Welcome to little lamb

Code » limb » commit 96e372e

Add hasher for BLAKE3

author Olivier Brunel
2023-03-26 14:00:59 UTC
committer Olivier Brunel
2023-03-26 14:31:10 UTC
parent 3f2cefe8d9092e3b56f836b605305662b55a3afb

Add hasher for BLAKE3

doc/blake3_init.3.md +4 -0
doc/hasher_blake3.h.0.md +25 -0
doc/hasher_hash.3.md +11 -0
include/limb/hasher_blake3.h +12 -0
meta/libs/limb +2 -0
src/hasher_blake3.c +16 -0

diff --git a/doc/blake3_init.3.md b/doc/blake3_init.3.md
index 2ab24e8..ee5547e 100644
--- a/doc/blake3_init.3.md
+++ b/doc/blake3_init.3.md
@@ -29,3 +29,7 @@ function repeatedly as many times as needed.
 
 The `blake3_final`() function stores the calculated hash from `ctx` in binary
 form into `md`, which must be able to store 32 bytes.
+
+# SEE ALSO
+
+[hasher_blake3.h](0), [hasher_hash](3), [sha3_224_init](3)
diff --git a/doc/hasher_blake3.h.0.md b/doc/hasher_blake3.h.0.md
new file mode 100644
index 0000000..14f9471
--- /dev/null
+++ b/doc/hasher_blake3.h.0.md
@@ -0,0 +1,25 @@
+% limb manual
+% hasher_blake3.h(0)
+
+# NAME
+
+hasher_blake3.h - hasher for BLAKE3
+
+# SYNOPSIS
+
+    #include <limb/hasher_blake3.h>
+
+# DESCRIPTION
+
+This header defines the hasher to compute the BLAKE3 of a given message.
+
+## Hashers
+
+The following hashers are defined :
+
+: *blake3*
+:: A hasher for BLAKE3. See [hasher_hash](3) for more.
+
+# SEE ALSO
+
+[blake3_init](3)
diff --git a/doc/hasher_hash.3.md b/doc/hasher_hash.3.md
index 457c1fd..7f569ba 100644
--- a/doc/hasher_hash.3.md
+++ b/doc/hasher_hash.3.md
@@ -74,6 +74,17 @@ compute into `digest` the message digest for message `msg` of length `mlen`
 using `hasher` all in a single call, when the entire message is available in
 a single continuous memory area.
 
+# AVAILABLE HASHERS
+
+A few hashers are available, each define in their own header. In order to use a
+hasher, all you need is to include its header, which includes [hasher.h](0), and
+you can any of the functions described above.
+
+The following hashers are available :
+
+: *blake3*
+:: Requires [hasher_blake3.h](0).
+
 # EXAMPLE
 
 To compute the SHA1 of a given message, and show it on *stdout*, one could do :
diff --git a/include/limb/hasher_blake3.h b/include/limb/hasher_blake3.h
new file mode 100644
index 0000000..8294afb
--- /dev/null
+++ b/include/limb/hasher_blake3.h
@@ -0,0 +1,12 @@
+/* This file is part of limb                           https://lila.oss/limb
+ * Copyright (C) 2023 Olivier Brunel                          jjk@jjacky.com */
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef LIMB_HASHER_BLAKE3_H
+#define LIMB_HASHER_BLAKE3_H
+
+#include "limb/hasher.h"
+
+extern struct hblake3 hasher_blake3;
+#define blake3 ((hasher *) (&hasher_blake3))
+
+#endif /* LIMB_HASHER_BLAKE3_H */
diff --git a/meta/libs/limb b/meta/libs/limb
index 53d195c..b5ac2e3 100644
--- a/meta/libs/limb
+++ b/meta/libs/limb
@@ -107,5 +107,7 @@ obj/blake3/blake3_impl.o
 obj/blake3/blake3_dispatch.o
 obj/blake3/blake3_portable.o
 $$(BLAKE3_OPTIMIZ)
+# hasher blake3
+obj/hasher_blake3.o
 # skalibs dependency
 skalibs
diff --git a/src/hasher_blake3.c b/src/hasher_blake3.c
new file mode 100644
index 0000000..90da431
--- /dev/null
+++ b/src/hasher_blake3.c
@@ -0,0 +1,16 @@
+/* This file is part of limb                           https://lila.oss/limb
+ * Copyright (C) 2023 Olivier Brunel                          jjk@jjacky.com */
+/* SPDX-License-Identifier: GPL-2.0-only */
+#include "limb/hasher_blake3.h"
+#include "limb/blake3.h"
+
+struct hblake3 {
+    hasher h;
+    blake3_ctx ctx;
+} hasher_blake3 = {
+    .h.hlen = 32,
+    .h.blen = 64,
+    .h.init = blake3_init,
+    .h.update = blake3_update,
+    .h.final = blake3_final,
+};