diff options
author | Micah Elizabeth Scott <beth@torproject.org> | 2023-03-09 15:28:56 -0800 |
---|---|---|
committer | Micah Elizabeth Scott <beth@torproject.org> | 2023-05-10 07:38:28 -0700 |
commit | bfa2102c955e0dc81af0821760c45d787eac8e1e (patch) | |
tree | 819b955529412abe212cfc25dec692ce8db5f77b /src/ext | |
parent | ffa8531fe0f495e45ade4910b7a1c0d7e56d78ba (diff) | |
download | tor-bfa2102c955e0dc81af0821760c45d787eac8e1e.tar.gz tor-bfa2102c955e0dc81af0821760c45d787eac8e1e.zip |
hs_pow: Replace libb2 dependency with hashx's internal blake2
This forgoes another external library dependency, and instead
introduces a compatibility header so that interested parties
(who already depend on equix, like hs_pow and unit tests) can
use the implementation of blake2b included in hashx.
Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
Diffstat (limited to 'src/ext')
-rw-r--r-- | src/ext/.may_include | 4 | ||||
-rw-r--r-- | src/ext/compat_blake2.h | 47 | ||||
-rw-r--r-- | src/ext/include.am | 6 |
3 files changed, 55 insertions, 2 deletions
diff --git a/src/ext/.may_include b/src/ext/.may_include index 1eafff2eeb..f55772f731 100644 --- a/src/ext/.may_include +++ b/src/ext/.may_include @@ -7,4 +7,6 @@ lib/cc/*.h tinytest*.h ext/siphash.h ext/byteorder.h -ext/tor_readpassphrase.h
\ No newline at end of file +ext/tor_readpassphrase.h + +ext/equix/hashx/src/blake2.h
\ No newline at end of file diff --git a/src/ext/compat_blake2.h b/src/ext/compat_blake2.h new file mode 100644 index 0000000000..01adb2c34a --- /dev/null +++ b/src/ext/compat_blake2.h @@ -0,0 +1,47 @@ +/* Copyright (c) 2023, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file compat_blake2.h + * + * \brief Compatibility adapter providing blake2b using ext/equix/hashx + **/ + +#ifndef TOR_COMPAT_BLAKE2_H +#define TOR_COMPAT_BLAKE2_H + +#include <stddef.h> +#include <string.h> +#include "lib/cc/compat_compiler.h" +#include "ext/equix/hashx/src/blake2.h" + +static inline int +blake2b_init_param(blake2b_state *S, const blake2b_param *P) +{ + return hashx_blake2b_init_param(S, P); +} + +static inline int +blake2b_init(blake2b_state *S, const uint8_t digest_length) +{ + blake2b_param P; + memset(&P, 0, sizeof P); + P.digest_length = digest_length; + P.fanout = 1; + P.depth = 1; + return blake2b_init_param(S, &P); +} + +static inline int +blake2b_update(blake2b_state *S, const uint8_t *in, uint64_t inlen) +{ + return hashx_blake2b_update(S, in, inlen); +} + +static inline int +blake2b_final(blake2b_state *S, uint8_t *out, uint8_t outlen) +{ + return hashx_blake2b_final(S, out, outlen); +} + +#endif /* !defined(TOR_COMPAT_BLAKE2_H) */ diff --git a/src/ext/include.am b/src/ext/include.am index f7dc9fe59a..dea8e4419b 100644 --- a/src/ext/include.am +++ b/src/ext/include.am @@ -1,5 +1,8 @@ -AM_CPPFLAGS += -I$(srcdir)/src/ext -Isrc/ext +AM_CPPFLAGS += \ + -I$(srcdir)/src/ext/ \ + -I$(srcdir)/src/ext/equix/include/ \ + -I$(srcdir)/src/ext/equix/hashx/include/ # TODO: put this with other equix/hashx ext defs when those happen, # and also add it to the autoconf config header. For now this is here @@ -19,6 +22,7 @@ EXTHEADERS = \ src/ext/tinytest_macros.h \ src/ext/tor_queue.h \ src/ext/siphash.h \ + src/ext/compat_blake2.h \ src/ext/timeouts/timeout.h \ src/ext/timeouts/timeout-debug.h \ src/ext/timeouts/timeout-bitops.c \ |