From 73100bf2aaa8a1bfc4b92f42a7461b99c587ef3d Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 17 Jul 2019 17:03:37 -0400 Subject: add hmac-sha2 and update files --- hmac-main.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 hmac-main.c (limited to 'hmac-main.c') diff --git a/hmac-main.c b/hmac-main.c new file mode 100644 index 0000000..ad65d65 --- /dev/null +++ b/hmac-main.c @@ -0,0 +1,31 @@ +#include // strlen() +#include // printf() +#include "hmac-sha2.h" + +static void print_hash(const uint8_t * const hash) { + for (size_t i = 0; i < SHA256_HASH_SIZE; i++) { + printf("%02x", hash[i]); + } +} + +int main(int argc, char *argv[]) { + // check args + if (argc < 2) { + fprintf(stderr, "Usage: %s [key] [message]\n", argv[0]); + return -1; + } + + // calculate hmac + uint8_t hash[SHA256_HASH_SIZE]; + hmac_sha256( + (uint8_t *) argv[1], strlen(argv[1]), + (uint8_t *) argv[2], strlen(argv[2]), + hash + ); + + // print hash + print_hash(hash); + printf("\n"); + + return 0; +} -- cgit v1.2.3