summaryrefslogtreecommitdiff
path: root/examples/02-kmac128
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2023-09-06 23:23:31 -0400
committerPaul Duncan <pabs@pablotron.org>2023-09-06 23:23:31 -0400
commit4eebef1961a1c01890fe11dc5f1b9f3a1ea705e0 (patch)
treec48e3f15f1f26ce4456c549c2211545e8448cfac /examples/02-kmac128
parent7887a482dc7951a88fd0b2a4caa8988f0aef4340 (diff)
downloadsha3-4eebef1961a1c01890fe11dc5f1b9f3a1ea705e0.tar.bz2
sha3-4eebef1961a1c01890fe11dc5f1b9f3a1ea705e0.zip
add examples/
Diffstat (limited to 'examples/02-kmac128')
-rw-r--r--examples/02-kmac128/Makefile16
l---------examples/02-kmac128/hex.h1
-rw-r--r--examples/02-kmac128/main.c53
l---------examples/02-kmac128/sha3.c1
l---------examples/02-kmac128/sha3.h1
5 files changed, 72 insertions, 0 deletions
diff --git a/examples/02-kmac128/Makefile b/examples/02-kmac128/Makefile
new file mode 100644
index 0000000..ae267f9
--- /dev/null
+++ b/examples/02-kmac128/Makefile
@@ -0,0 +1,16 @@
+CFLAGS=-W -Wall -Wextra -Werror -pedantic -std=c11 -O3 -march=native -mtune=native
+APP=./kmac128-example
+OBJS=sha3.o main.o
+
+.PHONY=all
+
+all: $(APP)
+
+$(APP): $(OBJS)
+ $(CC) -o $(APP) $(CFLAGS) $(OBJS)
+
+%.o: %.c
+ $(CC) -c $(CFLAGS) $<
+
+clean:
+ $(RM) -f $(APP) $(OBJS)
diff --git a/examples/02-kmac128/hex.h b/examples/02-kmac128/hex.h
new file mode 120000
index 0000000..2adfa3e
--- /dev/null
+++ b/examples/02-kmac128/hex.h
@@ -0,0 +1 @@
+../../hex.h \ No newline at end of file
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;
+}
diff --git a/examples/02-kmac128/sha3.c b/examples/02-kmac128/sha3.c
new file mode 120000
index 0000000..4748193
--- /dev/null
+++ b/examples/02-kmac128/sha3.c
@@ -0,0 +1 @@
+../../sha3.c \ No newline at end of file
diff --git a/examples/02-kmac128/sha3.h b/examples/02-kmac128/sha3.h
new file mode 120000
index 0000000..b7c53d4
--- /dev/null
+++ b/examples/02-kmac128/sha3.h
@@ -0,0 +1 @@
+../../sha3.h \ No newline at end of file