]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
hs_pow: Replace libb2 dependency with hashx's internal blake2
authorMicah Elizabeth Scott <beth@torproject.org>
Thu, 9 Mar 2023 23:28:56 +0000 (15:28 -0800)
committerMicah Elizabeth Scott <beth@torproject.org>
Wed, 10 May 2023 14:38:28 +0000 (07:38 -0700)
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
src/app/include.am
src/ext/.may_include
src/ext/compat_blake2.h [new file with mode: 0644]
src/ext/include.am
src/feature/hs/hs_pow.c
src/test/fuzz/include.am
src/test/include.am
src/test/test_crypto.c

index eaef9d270331497f37c5c5c9f91290f2cb5ae6f9..2b20965d68fe67b3e32dc7f82b86075ce7f7d5ff 100644 (file)
@@ -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.)
index 33365bfcac1492be609215e3b975887116ccfe4d..5494d904a357ab0361b91ddc22020c26fd172a39 100644 (file)
@@ -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
index 1eafff2eeb598eaa03212bb733a14eea8ca0bdfb..f55772f7312a6857e94c1e502430c66d1a214cf6 100644 (file)
@@ -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 (file)
index 0000000..01adb2c
--- /dev/null
@@ -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) */
index f7dc9fe59aafaabcebbe3ee4b36fd114c1dd4706..dea8e4419b026bd95aeb1289b65796c937899b50 100644 (file)
@@ -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 \
index 1cc8bcb6bdeb39836e48cda0503bdaf9b0151ce3..c36870fd4a5c9f5696c84be02b11f2a023faf798 100644 (file)
@@ -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"
index a97dca148903b5ea18b1efae49d6ac92fe5ff0f9..9fece7d0041272fb2c36607ccb203c0e71a54e65 100644 (file)
@@ -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
index 2ecea43333b93ccaac6931fb6ae6ca3a6ebd32fd..deff450490f67ef9a53779748efdb69d41b7fe76 100644 (file)
@@ -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
index 1f66a6251adfcb711458b0d32483fe291c438758..82a9d5d6426bdaf2d452222cb517b619389c44e2 100644 (file)
@@ -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