aboutsummaryrefslogtreecommitdiff
path: root/hmac-main.c
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2019-07-17 17:03:37 -0400
committerPaul Duncan <pabs@pablotron.org>2019-07-17 17:03:37 -0400
commit73100bf2aaa8a1bfc4b92f42a7461b99c587ef3d (patch)
tree4d1d988f6714e22e2b991e2f074a15e03667ac7f /hmac-main.c
parent2c9390c10b2f31c87830e0816ca207974ebfc590 (diff)
downloadsha2-73100bf2aaa8a1bfc4b92f42a7461b99c587ef3d.tar.bz2
sha2-73100bf2aaa8a1bfc4b92f42a7461b99c587ef3d.zip
add hmac-sha2 and update files
Diffstat (limited to 'hmac-main.c')
-rw-r--r--hmac-main.c31
1 files changed, 31 insertions, 0 deletions
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 <string.h> // strlen()
+#include <stdio.h> // 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;
+}