aboutsummaryrefslogtreecommitdiffstats
path: root/argon2
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2026-05-16 02:11:29 +0200
committerMattias Andrée <m@maandree.se>2026-05-16 02:11:29 +0200
commit8e7bfadb3eb9f43eb0b670b908b479325722fee5 (patch)
treee7f26f67cc4da2846e0ac3f8201e1e82de3c6112 /argon2
parentm (diff)
downloadlibrecrypt-8e7bfadb3eb9f43eb0b670b908b479325722fee5.tar.gz
librecrypt-8e7bfadb3eb9f43eb0b670b908b479325722fee5.tar.bz2
librecrypt-8e7bfadb3eb9f43eb0b670b908b479325722fee5.tar.xz
Add WITH_LIBAR2SIMPLIFIED=false + work on fuzzing code
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'argon2')
-rw-r--r--argon2/hash.c80
-rw-r--r--argon2/suffix.mk22
2 files changed, 95 insertions, 7 deletions
diff --git a/argon2/hash.c b/argon2/hash.c
index a40e54c..d06ec1e 100644
--- a/argon2/hash.c
+++ b/argon2/hash.c
@@ -3,7 +3,11 @@
#ifndef TEST
#include <libar2.h>
-#include <libar2simplified.h>
+#ifndef NO_LIBAR2SIMPLIFIED
+# include <libar2simplified.h>
+#else
+# define libar2simplified_init_context init_context
+#endif
#define RANGE(MIN, MAX) (uintmax_t)(MIN), (uintmax_t)(MAX)
@@ -11,6 +15,80 @@
#define REMOVE_CONST(X) (*(void **)(void *)&(X))
+#ifdef NO_LIBAR2SIMPLIFIED
+
+static void *
+allocate(size_t num, size_t size, size_t alignment, struct libar2_context *ctx)
+{
+ size_t extra, pad;
+ void *ptr;
+ unsigned char *p;
+ int err;
+
+ (void) ctx;
+
+ alignment = MAX(alignment, sizeof(void *));
+ extra = 2u * sizeof(size_t);
+ pad = -extra & (alignment - 1u);
+
+ err = ENOMEM;
+ if (num > (SIZE_MAX - extra - pad) / size ||
+ (err = posix_memalign(&ptr, alignment, pad + extra + (size *= num)))) {
+ errno = err;
+ return NULL;
+ }
+
+ p = ptr;
+ p += pad;
+ memcpy(p, &pad, sizeof(size_t));
+ p += sizeof(size_t);
+ memcpy(p, &size, sizeof(size_t));
+ p += sizeof(size_t);
+ return p;
+}
+
+
+static void
+deallocate(void *ptr, struct libar2_context *ctx)
+{
+ size_t size, pad;
+ char *p = ptr;
+
+ (void) ctx;
+
+ p -= sizeof(size_t);
+ memcpy(&size, p, sizeof(size_t));
+ p -= sizeof(size_t);
+ memcpy(&pad, p, sizeof(size_t));
+ p -= pad;
+
+ librecrypt_wipe(p, size + pad + 2u * sizeof(size_t));
+ free(p);
+}
+
+
+static int
+init_thread_pool(size_t desired, size_t *createdp, struct libar2_context *ctx)
+{
+ (void) desired;
+ (void) ctx;
+ *createdp = 0u;
+ return 0;
+}
+
+
+static void
+init_context(struct libar2_context *ctxp)
+{
+ memset(ctxp, 0, sizeof(*ctxp));
+ ctxp->allocate = &allocate;
+ ctxp->deallocate = &deallocate;
+ ctxp->init_thread_pool = &init_thread_pool;
+}
+
+#endif
+
+
int
librecrypt__argon2__hash(char *restrict out_buffer, size_t size, const char *phrase, size_t len,
const char *settings, size_t prefix, void *reserved)
diff --git a/argon2/suffix.mk b/argon2/suffix.mk
index 65617b1..5ca2ceb 100644
--- a/argon2/suffix.mk
+++ b/argon2/suffix.mk
@@ -1,5 +1,7 @@
SUPPORT_ANY_ARGON2 = ($(SUPPORT_ARGON2I) || $(SUPPORT_ARGON2D) || $(SUPPORT_ARGON2ID) || $(SUPPORT_ARGON2DS))
+WITH_LIBAR2SIMPLIFIED = true
+
HDR += argon2/argon2.h
OBJ_ARGON2 !=\
@@ -29,19 +31,27 @@ CPPFLAGS_ARGON2 !=\
;fi;\
if $(SUPPORT_ARGON2DS); then echo\
-DSUPPORT_ARGON2DS\
+ ;fi;\
+ if ! $(WITH_LIBAR2SIMPLIFIED); then echo\
+ -DNO_LIBAR2SIMPLIFIED\
;fi
CFLAGS_ARGON2 !=\
- if $(SUPPORT_ANY_ARGON2); then echo\
+ if $(SUPPORT_ANY_ARGON2) && $(WITH_LIBAR2SIMPLIFIED); then echo\
-pthread\
;fi
LDFLAGS_ARGON2 !=\
- if $(SUPPORT_ANY_ARGON2); then echo\
- -lar2simplified\
- -lar2\
- -lblake\
- -pthread\
+ if $(SUPPORT_ANY_ARGON2); then\
+ if $(WITH_LIBAR2SIMPLIFIED); then echo\
+ -lar2simplified\
+ -lar2\
+ -lblake\
+ -pthread\
+ ;else echo\
+ -lar2\
+ -lblake\
+ ;fi\
;fi
CPPFLAGS_MODULES += $(CPPFLAGS_ARGON2)