aboutsummaryrefslogtreecommitdiff
path: root/examples/01-shake128
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/01-shake128
parent7887a482dc7951a88fd0b2a4caa8988f0aef4340 (diff)
downloadsha3-4eebef1961a1c01890fe11dc5f1b9f3a1ea705e0.tar.bz2
sha3-4eebef1961a1c01890fe11dc5f1b9f3a1ea705e0.zip
add examples/
Diffstat (limited to 'examples/01-shake128')
-rw-r--r--examples/01-shake128/Makefile16
l---------examples/01-shake128/hex.h1
-rw-r--r--examples/01-shake128/main.c24
l---------examples/01-shake128/sha3.c1
l---------examples/01-shake128/sha3.h1
5 files changed, 43 insertions, 0 deletions
diff --git a/examples/01-shake128/Makefile b/examples/01-shake128/Makefile
new file mode 100644
index 0000000..f5080cd
--- /dev/null
+++ b/examples/01-shake128/Makefile
@@ -0,0 +1,16 @@
+CFLAGS=-W -Wall -Wextra -Werror -pedantic -std=c11 -O3 -march=native -mtune=native
+APP=./shake128-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/01-shake128/hex.h b/examples/01-shake128/hex.h
new file mode 120000
index 0000000..2adfa3e
--- /dev/null
+++ b/examples/01-shake128/hex.h
@@ -0,0 +1 @@
+../../hex.h \ No newline at end of file
diff --git a/examples/01-shake128/main.c b/examples/01-shake128/main.c
new file mode 100644
index 0000000..f2a2347
--- /dev/null
+++ b/examples/01-shake128/main.c
@@ -0,0 +1,24 @@
+//
+// shake128-example: hash contents of DATA with SHAKE128 and print first
+// 200 bytes of SHAKE128 hash of data 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";
+
+int main() {
+ // hash data
+ uint8_t buf[200] = { 0 };
+ shake128_xof_once(DATA, sizeof(DATA), buf, sizeof(buf));
+
+ // print result to stdout
+ printf("SHAKE128 (200 bytes): ");
+ hex_write(stdout, buf, sizeof(buf));
+ printf("\n");
+
+ return 0;
+}
diff --git a/examples/01-shake128/sha3.c b/examples/01-shake128/sha3.c
new file mode 120000
index 0000000..4748193
--- /dev/null
+++ b/examples/01-shake128/sha3.c
@@ -0,0 +1 @@
+../../sha3.c \ No newline at end of file
diff --git a/examples/01-shake128/sha3.h b/examples/01-shake128/sha3.h
new file mode 120000
index 0000000..b7c53d4
--- /dev/null
+++ b/examples/01-shake128/sha3.h
@@ -0,0 +1 @@
+../../sha3.h \ No newline at end of file