Welcome to little lamb

Code » limb » commit 0ad440d

Add hashers for SHA3 224, 256, 384 & 512

author Olivier Brunel
2023-03-26 13:08:36 UTC
committer Olivier Brunel
2023-03-26 14:03:03 UTC
parent 4a3a229680d54e50271f2720c3822d5d64f3fb6b

Add hashers for SHA3 224, 256, 384 & 512

include/limb/hasher_sha3_224.h +12 -0
include/limb/hasher_sha3_256.h +12 -0
include/limb/hasher_sha3_384.h +12 -0
include/limb/hasher_sha3_512.h +12 -0
meta/libs/limb +5 -0
src/hasher_sha3_224.c +16 -0
src/hasher_sha3_256.c +16 -0
src/hasher_sha3_384.c +16 -0
src/hasher_sha3_512.c +16 -0

diff --git a/include/limb/hasher_sha3_224.h b/include/limb/hasher_sha3_224.h
new file mode 100644
index 0000000..ca760b0
--- /dev/null
+++ b/include/limb/hasher_sha3_224.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_SHA3_224_H
+#define LIMB_HASHER_SHA3_224_H
+
+#include "limb/hasher.h"
+
+extern struct hsha3_224 hasher_sha3_224;
+#define sha3_224 ((hasher *) (&hasher_sha3_224))
+
+#endif /* LIMB_HASHER_SHA3_224_H */
diff --git a/include/limb/hasher_sha3_256.h b/include/limb/hasher_sha3_256.h
new file mode 100644
index 0000000..42ff58a
--- /dev/null
+++ b/include/limb/hasher_sha3_256.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_SHA3_256_H
+#define LIMB_HASHER_SHA3_256_H
+
+#include "limb/hasher.h"
+
+extern struct hsha3_256 hasher_sha3_256;
+#define sha3_256 ((hasher *) (&hasher_sha3_256))
+
+#endif /* LIMB_HASHER_SHA3_256_H */
diff --git a/include/limb/hasher_sha3_384.h b/include/limb/hasher_sha3_384.h
new file mode 100644
index 0000000..67604ac
--- /dev/null
+++ b/include/limb/hasher_sha3_384.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_SHA3_384_H
+#define LIMB_HASHER_SHA3_384_H
+
+#include "limb/hasher.h"
+
+extern struct hsha3_384 hasher_sha3_384;
+#define sha3_384 ((hasher *) (&hasher_sha3_384))
+
+#endif /* LIMB_HASHER_SHA3_384_H */
diff --git a/include/limb/hasher_sha3_512.h b/include/limb/hasher_sha3_512.h
new file mode 100644
index 0000000..b55d762
--- /dev/null
+++ b/include/limb/hasher_sha3_512.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_SHA3_512_H
+#define LIMB_HASHER_SHA3_512_H
+
+#include "limb/hasher.h"
+
+extern struct hsha3_512 hasher_sha3_512;
+#define sha3_512 ((hasher *) (&hasher_sha3_512))
+
+#endif /* LIMB_HASHER_SHA3_512_H */
diff --git a/meta/libs/limb b/meta/libs/limb
index a0508a9..1adf17e 100644
--- a/meta/libs/limb
+++ b/meta/libs/limb
@@ -97,6 +97,11 @@ obj/sha3/sha3_384_init.o
 obj/sha3/sha3_512_init.o
 obj/sha3/sha3_update.o
 obj/sha3/sha3_final.o
+# hasher SHA3
+obj/hasher_sha3_224.o
+obj/hasher_sha3_256.o
+obj/hasher_sha3_384.o
+obj/hasher_sha3_512.o
 # BLAKE3
 obj/blake3/blake3_impl.o
 obj/blake3/blake3_dispatch.o
diff --git a/src/hasher_sha3_224.c b/src/hasher_sha3_224.c
new file mode 100644
index 0000000..eece4aa
--- /dev/null
+++ b/src/hasher_sha3_224.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_sha3_224.h"
+#include "limb/sha3.h"
+
+struct hsha3_224 {
+    hasher h;
+    sha3_ctx ctx;
+} hasher_sha3_224 = {
+    .h.hlen = 28,
+    .h.blen = 144,
+    .h.init = sha3_224_init,
+    .h.update = sha3_update,
+    .h.final = sha3_final,
+};
diff --git a/src/hasher_sha3_256.c b/src/hasher_sha3_256.c
new file mode 100644
index 0000000..540f7a8
--- /dev/null
+++ b/src/hasher_sha3_256.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_sha3_256.h"
+#include "limb/sha3.h"
+
+struct hsha3_256 {
+    hasher h;
+    sha3_ctx ctx;
+} hasher_sha3_256 = {
+    .h.hlen = 32,
+    .h.blen = 136,
+    .h.init = sha3_256_init,
+    .h.update = sha3_update,
+    .h.final = sha3_final,
+};
diff --git a/src/hasher_sha3_384.c b/src/hasher_sha3_384.c
new file mode 100644
index 0000000..7668911
--- /dev/null
+++ b/src/hasher_sha3_384.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_sha3_384.h"
+#include "limb/sha3.h"
+
+struct hsha3_384 {
+    hasher h;
+    sha3_ctx ctx;
+} hasher_sha3_384 = {
+    .h.hlen = 48,
+    .h.blen = 104,
+    .h.init = sha3_384_init,
+    .h.update = sha3_update,
+    .h.final = sha3_final,
+};
diff --git a/src/hasher_sha3_512.c b/src/hasher_sha3_512.c
new file mode 100644
index 0000000..aa30938
--- /dev/null
+++ b/src/hasher_sha3_512.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_sha3_512.h"
+#include "limb/sha3.h"
+
+struct hsha3_512 {
+    hasher h;
+    sha3_ctx ctx;
+} hasher_sha3_512 = {
+    .h.hlen = 64,
+    .h.blen = 72,
+    .h.init = sha3_512_init,
+    .h.update = sha3_update,
+    .h.final = sha3_final,
+};