From 4c335d5b255752c6b9f18f16ce04abdc9612844f Mon Sep 17 00:00:00 2001 From: Apisit Ritreungroj Date: Mon, 12 Feb 2024 15:35:43 +0700 Subject: [PATCH] feat: hash --- wasm/event-stubs/hash.c | 86 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 wasm/event-stubs/hash.c diff --git a/wasm/event-stubs/hash.c b/wasm/event-stubs/hash.c new file mode 100644 index 000000000..a0cf3dbc9 --- /dev/null +++ b/wasm/event-stubs/hash.c @@ -0,0 +1,86 @@ +#include + +#include + +typedef struct { + uint8_t * data; + size_t length; +} +Bstr; + +typedef enum { + KeyTooBig, + HashTooBig, +} +Errno; + +const char * errno_name(Errno errno) { + switch (errno) { + case KeyTooBig: + return "key-too-big"; + case HashTooBig: + return "hash-too-big"; + default: + return "unknown-error"; + } +} + +const char * errno_message(Errno errno) { + switch (errno) { + case HashTooBig: + return "The key is larger than supported by the hash function."; + default: + return ""; + } +} + +typedef struct { + int code; + const char * name; + const char * message; +} +Errno_Debug; + +Errno_Debug errno_debug(Errno errno) { + return (Errno_Debug) { + errno, + errno_name(errno), + errno_message(errno) + }; +} + +typedef struct { + Bstr( * blake2s)(Bstr buf, uint8_t outlen, Bstr key); + Bstr( * blake2b)(Bstr buf, uint8_t outlen, Bstr key); + Bstr( * blake3)(Bstr buf, uint8_t outlen, Bstr key); +} +HashAPI; + +Bstr blake2s(Bstr buf, uint8_t outlen, Bstr key) { + Bstr result; + // Implement the BLAKE2s hashing function here + return result; +} + +Bstr blake2b(Bstr buf, uint8_t outlen, Bstr key) { + Bstr result; + // Implement the BLAKE2b hashing function here + return result; +} + +Bstr blake3(Bstr buf, uint8_t outlen, Bstr key) { + Bstr result; + // Implement the BLAKE3 hashing function here + return result; +} + +int main() { + HashAPI api = { + .blake2s = blake2s, + .blake2b = blake2b, + .blake3 = blake3, + }; + + // Use the API functions here + return 0; +}