This is an automated email from the git hooks/post-receive script.
dgoulet pushed a commit to branch main in repository tor.
commit bfa2102c955e0dc81af0821760c45d787eac8e1e Author: Micah Elizabeth Scott beth@torproject.org AuthorDate: Thu Mar 9 15:28:56 2023 -0800
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 --- configure.ac | 3 --- src/app/include.am | 6 ++---- src/ext/.may_include | 4 +++- src/ext/compat_blake2.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/ext/include.am | 6 +++++- src/feature/hs/hs_pow.c | 4 +--- src/test/fuzz/include.am | 3 +-- src/test/include.am | 16 ++++++++-------- src/test/test_crypto.c | 4 +--- 9 files changed, 68 insertions(+), 25 deletions(-)
diff --git a/configure.ac b/configure.ac index eaef9d2703..2b20965d68 100644 --- a/configure.ac +++ b/configure.ac @@ -435,9 +435,6 @@ AC_DEFUN([ADD_MODULE], [ m4_foreach_w([module], MODULES, [ADD_MODULE([module])]) AC_SUBST(TOR_MODULES_ALL_ENABLED)
-dnl Blake2 check for Equi-X support. -PKG_CHECK_MODULES([LIBB2], [libb2]) - dnl check for the correct "ar" when cross-compiling. dnl (AM_PROG_AR was new in automake 1.11.2, which we do not yet require, dnl so kludge up a replacement for the case where it isn't there yet.) diff --git a/src/app/include.am b/src/app/include.am index 33365bfcac..5494d904a3 100644 --- a/src/app/include.am +++ b/src/app/include.am @@ -20,8 +20,7 @@ src_app_tor_LDADD = libtor.a \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ $(TOR_LIBS_CRYPTLIB) \ @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \ @CURVE25519_LIBS@ @TOR_SYSTEMD_LIBS@ \ - @TOR_LZMA_LIBS@ @TOR_ZSTD_LIBS@ @TOR_TRACE_LIBS@ \ - @LIBB2_LIBS@ + @TOR_LZMA_LIBS@ @TOR_ZSTD_LIBS@ @TOR_TRACE_LIBS@
if COVERAGE_ENABLED src_app_tor_cov_SOURCES = $(src_app_tor_SOURCES) @@ -33,6 +32,5 @@ src_app_tor_cov_LDADD = src/test/libtor-testing.a \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ $(TOR_LIBS_CRYPTLIB) \ @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ \ @CURVE25519_LIBS@ @TOR_SYSTEMD_LIBS@ \ - @TOR_LZMA_LIBS@ @TOR_ZSTD_LIBS@ @TOR_TRACE_LIBS@ \ - @LIBB2_LIBS@ + @TOR_LZMA_LIBS@ @TOR_ZSTD_LIBS@ @TOR_TRACE_LIBS@ endif 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 \ diff --git a/src/feature/hs/hs_pow.c b/src/feature/hs/hs_pow.c index 1cc8bcb6bd..c36870fd4a 100644 --- a/src/feature/hs/hs_pow.c +++ b/src/feature/hs/hs_pow.c @@ -9,12 +9,10 @@
typedef unsigned __int128 uint128_t;
-// TODO fixme -#include <blake2.h> - #include <stdio.h>
#include "ext/ht.h" +#include "ext/compat_blake2.h" #include "core/or/circuitlist.h" #include "core/or/origin_circuit_st.h" #include "feature/hs/hs_cache.h" diff --git a/src/test/fuzz/include.am b/src/test/fuzz/include.am index a97dca1489..9fece7d004 100644 --- a/src/test/fuzz/include.am +++ b/src/test/fuzz/include.am @@ -14,8 +14,7 @@ FUZZING_LIBS = \ @TOR_SYSTEMD_LIBS@ \ @TOR_LZMA_LIBS@ \ @TOR_ZSTD_LIBS@ \ - @TOR_TRACE_LIBS@ \ - @LIBB2_LIBS@ + @TOR_TRACE_LIBS@
oss-fuzz-prereqs: \ src/test/libtor-testing.a diff --git a/src/test/include.am b/src/test/include.am index 2ecea43333..deff450490 100644 --- a/src/test/include.am +++ b/src/test/include.am @@ -301,7 +301,7 @@ src_test_test_switch_id_LDADD = \ $(TOR_UTIL_TESTING_LIBS) \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ \ @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_USERENV@ \ - @TOR_LZMA_LIBS@ @TOR_ZSTD_LIBS@ @TOR_TRACE_LIBS@ @LIBB2_LIBS@ + @TOR_LZMA_LIBS@ @TOR_ZSTD_LIBS@ @TOR_TRACE_LIBS@ src_test_test_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) \ @TOR_LDFLAGS_libevent@ src_test_test_LDADD = \ @@ -309,7 +309,7 @@ src_test_test_LDADD = \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ \ $(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \ @CURVE25519_LIBS@ \ - @TOR_SYSTEMD_LIBS@ @TOR_LZMA_LIBS@ @TOR_ZSTD_LIBS@ @TOR_TRACE_LIBS@ @LIBB2_LIBS@ + @TOR_SYSTEMD_LIBS@ @TOR_LZMA_LIBS@ @TOR_ZSTD_LIBS@ @TOR_TRACE_LIBS@
src_test_test_slow_CPPFLAGS = $(src_test_test_CPPFLAGS) src_test_test_slow_CFLAGS = $(src_test_test_CFLAGS) @@ -337,7 +337,7 @@ src_test_bench_LDADD = \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ \ $(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \ @CURVE25519_LIBS@ \ - @TOR_SYSTEMD_LIBS@ @TOR_LZMA_LIBS@ @TOR_ZSTD_LIBS@ @TOR_TRACE_LIBS@ @LIBB2_LIBS@ + @TOR_SYSTEMD_LIBS@ @TOR_LZMA_LIBS@ @TOR_ZSTD_LIBS@ @TOR_TRACE_LIBS@
src_test_test_workqueue_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) \ @TOR_LDFLAGS_libevent@ @@ -346,7 +346,7 @@ src_test_test_workqueue_LDADD = \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ \ $(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \ @CURVE25519_LIBS@ \ - @TOR_LZMA_LIBS@ @TOR_ZSTD_LIBS@ @TOR_TRACE_LIBS@ @LIBB2_LIBS@ + @TOR_LZMA_LIBS@ @TOR_ZSTD_LIBS@ @TOR_TRACE_LIBS@
src_test_test_timers_CPPFLAGS = $(src_test_test_CPPFLAGS) src_test_test_timers_CFLAGS = $(src_test_test_CFLAGS) @@ -357,7 +357,7 @@ src_test_test_timers_LDADD = \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ \ $(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \ @CURVE25519_LIBS@ \ - @TOR_LZMA_LIBS@ @TOR_TRACE_LIBS@ @LIBB2_LIBS@ + @TOR_LZMA_LIBS@ @TOR_TRACE_LIBS@ src_test_test_timers_LDFLAGS = $(src_test_test_LDFLAGS)
# ADD_C_FILE: INSERT HEADERS HERE. @@ -391,7 +391,7 @@ src_test_test_ntor_cl_LDADD = \ libtor.a \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ \ $(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \ - @CURVE25519_LIBS@ @TOR_LZMA_LIBS@ @TOR_TRACE_LIBS@ @LIBB2_LIBS@ + @CURVE25519_LIBS@ @TOR_LZMA_LIBS@ @TOR_TRACE_LIBS@ src_test_test_ntor_cl_AM_CPPFLAGS = \ $(AM_CPPFLAGS)
@@ -401,7 +401,7 @@ src_test_test_hs_ntor_cl_LDADD = \ libtor.a \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ \ $(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ \ - @CURVE25519_LIBS@ @TOR_TRACE_LIBS@ @LIBB2_LIBS@ + @CURVE25519_LIBS@ @TOR_TRACE_LIBS@ src_test_test_hs_ntor_cl_AM_CPPFLAGS = \ $(AM_CPPFLAGS)
@@ -413,7 +413,7 @@ src_test_test_bt_cl_LDADD = \ $(TOR_UTIL_TESTING_LIBS) \ @TOR_LIB_MATH@ \ @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \ - @TOR_TRACE_LIBS@ @LIBB2_LIBS@ + @TOR_TRACE_LIBS@ src_test_test_bt_cl_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS) src_test_test_bt_cl_CPPFLAGS= $(src_test_AM_CPPFLAGS) $(TEST_CPPFLAGS) endif diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c index 1f66a6251a..82a9d5d642 100644 --- a/src/test/test_crypto.c +++ b/src/test/test_crypto.c @@ -10,6 +10,7 @@ #include "test/test.h" #include "lib/crypt_ops/aes.h" #include "siphash.h" +#include "ext/compat_blake2.h" #include "ext/equix/hashx/include/hashx.h" #include "lib/crypt_ops/crypto_curve25519.h" #include "lib/crypt_ops/crypto_dh.h" @@ -21,9 +22,6 @@ #include "ed25519_vectors.inc" #include "test/log_test_helpers.h"
-// TODO fixme -#include <blake2.h> - #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> #endif