diff options
author | Paul Duncan <pabs@pablotron.org> | 2023-09-06 23:23:31 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2023-09-06 23:23:31 -0400 |
commit | 4eebef1961a1c01890fe11dc5f1b9f3a1ea705e0 (patch) | |
tree | c48e3f15f1f26ce4456c549c2211545e8448cfac /examples/03-tuplehash128 | |
parent | 7887a482dc7951a88fd0b2a4caa8988f0aef4340 (diff) | |
download | sha3-4eebef1961a1c01890fe11dc5f1b9f3a1ea705e0.tar.bz2 sha3-4eebef1961a1c01890fe11dc5f1b9f3a1ea705e0.zip |
add examples/
Diffstat (limited to 'examples/03-tuplehash128')
-rw-r--r-- | examples/03-tuplehash128/Makefile | 16 | ||||
l--------- | examples/03-tuplehash128/hex.h | 1 | ||||
-rw-r--r-- | examples/03-tuplehash128/main.c | 75 | ||||
l--------- | examples/03-tuplehash128/sha3.c | 1 | ||||
l--------- | examples/03-tuplehash128/sha3.h | 1 |
5 files changed, 94 insertions, 0 deletions
diff --git a/examples/03-tuplehash128/Makefile b/examples/03-tuplehash128/Makefile new file mode 100644 index 0000000..cbbd3a9 --- /dev/null +++ b/examples/03-tuplehash128/Makefile @@ -0,0 +1,16 @@ +CFLAGS=-W -Wall -Wextra -Werror -pedantic -std=c11 -O3 -march=native -mtune=native +APP=./tuplehash128-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/03-tuplehash128/hex.h b/examples/03-tuplehash128/hex.h new file mode 120000 index 0000000..2adfa3e --- /dev/null +++ b/examples/03-tuplehash128/hex.h @@ -0,0 +1 @@ +../../hex.h
\ No newline at end of file diff --git a/examples/03-tuplehash128/main.c b/examples/03-tuplehash128/main.c new file mode 100644 index 0000000..c9e1952 --- /dev/null +++ b/examples/03-tuplehash128/main.c @@ -0,0 +1,75 @@ +// +// tuplehash128-example: Hash tuples with TupleHash128 and key +// and print first 20 bytes of result to standard output. +// +#include <stdint.h> +#include <stdio.h> +#include "hex.h" +#include "sha3.h" + +static const struct { + const char *name; + tuplehash_str_t strs[10]; + size_t num_strs; +} ROWS[] = {{ + .name = "TupleHash128: \"abc\"", + .strs = {{ + .ptr = (uint8_t*) "abc", + .len = 3, + }}, + .num_strs = 1, +}, { + .name = "TupleHash128: \"ab\", \"c\"", + .strs = {{ + .ptr = (uint8_t*) "ab", + .len = 2, + }, { + .ptr = (uint8_t*) "c", + .len = 1, + }}, + .num_strs = 2, +}, { + .name = "TupleHash128: \"a\", \"bc\"", + .strs = {{ + .ptr = (uint8_t*) "a", + .len = 1, + }, { + .ptr = (uint8_t*) "bc", + .len = 2, + }}, + .num_strs = 2, +}, { + .name = "TupleHash128: \"a\", \"b\", \"c\"", + .strs = {{ + .ptr = (uint8_t*) "a", + .len = 1, + }, { + .ptr = (uint8_t*) "b", + .len = 1, + }, { + .ptr = (uint8_t*) "c", + .len = 1, + }}, + .num_strs = 3, +}}; + +int main() { + for (size_t i = 0; i < sizeof(ROWS)/sizeof(ROWS[0]); i++) { + // build params + tuplehash_params_t params = { + .strs = ROWS[i].strs, + .num_strs = ROWS[i].num_strs, + }; + + // hash data + uint8_t buf[32]; + tuplehash128(params, 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/03-tuplehash128/sha3.c b/examples/03-tuplehash128/sha3.c new file mode 120000 index 0000000..4748193 --- /dev/null +++ b/examples/03-tuplehash128/sha3.c @@ -0,0 +1 @@ +../../sha3.c
\ No newline at end of file diff --git a/examples/03-tuplehash128/sha3.h b/examples/03-tuplehash128/sha3.h new file mode 120000 index 0000000..b7c53d4 --- /dev/null +++ b/examples/03-tuplehash128/sha3.h @@ -0,0 +1 @@ +../../sha3.h
\ No newline at end of file |