summaryrefslogtreecommitdiff
path: root/examples/02-kmac128/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/02-kmac128/main.c')
-rw-r--r--examples/02-kmac128/main.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/examples/02-kmac128/main.c b/examples/02-kmac128/main.c
new file mode 100644
index 0000000..d1965a9
--- /dev/null
+++ b/examples/02-kmac128/main.c
@@ -0,0 +1,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;
+}