aboutsummaryrefslogtreecommitdiff
path: root/hmac-main.c
blob: ad65d65e15d1f36500994b40750dd79ae9d4cb95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;
}