summaryrefslogtreecommitdiff
path: root/examples/02-kmac128/main.c
blob: d1965a90aeb55ddbf283e166387d309f2be29c2d (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// kmac128-example: Hash contents of DATA with KMAC128 and key and print first
// 32 bytes of result to standard output.
//
#include <stdint.h>
#include <stdio.h>
#include "hex.h"
#include "sha3.h"

// test data
static const uint8_t DATA[] = "this is some test data";

static const struct {
  const char *name;
  kmac_params_t params;
} ROWS[] = {{
  .name = "KMAC128 (key = \"\", custom = \"\")",
}, {
  .name = "KMAC128 (key = \"foo\", custom = \"\")",
  .params = {
    .key = (uint8_t*) "foo",
    .key_len = 3,
  },
}, {
  .name = "KMAC128 (key = \"bar\", custom = \"\")",
  .params = {
    .key = (uint8_t*) "bar",
    .key_len = 3,
  },
}, {
  .name = "KMAC128 (key = \"bar\", custom = \"blum\")",
  .params = {
    .key = (uint8_t*) "bar",
    .key_len = 3,
    .custom = (uint8_t*) "blum",
    .custom_len = 4,
  },
}};

int main() {
  for (size_t i = 0; i < sizeof(ROWS)/sizeof(ROWS[0]); i++) {
    // hash data
    uint8_t buf[32] = { 0 };
    kmac128_xof_once(ROWS[i].params, DATA, sizeof(DATA), buf, sizeof(buf));

    // print to stdout
    printf("%s:\n", ROWS[i].name);
    hex_write(stdout, buf, sizeof(buf));
    printf("\n");
  }

  return 0;
}