diff options
author | Micah Elizabeth Scott <beth@torproject.org> | 2023-03-10 17:23:06 -0800 |
---|---|---|
committer | Micah Elizabeth Scott <beth@torproject.org> | 2023-05-10 07:38:28 -0700 |
commit | 3129910b11b576ae32ac84fa3fd9feb3e5648dce (patch) | |
tree | f1960ea932e3b23c04aa17ab26b10673ba3bceb9 /src/feature/hs | |
parent | c6b168e141e9b2a80c80254a9cf3f2a5583fac8c (diff) | |
download | tor-3129910b11b576ae32ac84fa3fd9feb3e5648dce.tar.gz tor-3129910b11b576ae32ac84fa3fd9feb3e5648dce.zip |
hs_pow: use the compiled HashX implementation
Much faster per-hash, affects both verify and solve.
Only implemented on x86_64 and aarch64, other platforms
always use the interpreted version of hashx.
Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
Diffstat (limited to 'src/feature/hs')
-rw-r--r-- | src/feature/hs/hs_pow.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/feature/hs/hs_pow.c b/src/feature/hs/hs_pow.c index c36870fd4a..0c138273e8 100644 --- a/src/feature/hs/hs_pow.c +++ b/src/feature/hs/hs_pow.c @@ -75,6 +75,23 @@ increment_and_set_nonce(uint128_t *nonce, uint8_t *challenge) memcpy(challenge + HS_POW_SEED_LEN, nonce, HS_POW_NONCE_LEN); } +/* Helper: Allocate an EquiX context, using the much faster compiled + * implementation of hashx if it's available on this architecture. */ +static equix_ctx * +build_equix_ctx(equix_ctx_flags flags) +{ + equix_ctx *ctx = equix_alloc(flags | EQUIX_CTX_COMPILE); + if (ctx == EQUIX_NOTSUPP) { + ctx = equix_alloc(flags); + } + tor_assert_nonfatal(ctx != EQUIX_NOTSUPP); + tor_assert_nonfatal(ctx != NULL); + if (ctx == EQUIX_NOTSUPP) { + ctx = NULL; + } + return ctx; +} + /* Helper: Build EquiX challenge (C || N || INT_32(E)) and return a newly * allocated buffer containing it. */ static uint8_t * @@ -145,7 +162,10 @@ hs_pow_solve(const hs_pow_desc_params_t *pow_params, /* Build EquiX challenge (C || N || INT_32(E)). */ challenge = build_equix_challenge(pow_params->seed, nonce, effort); - ctx = equix_alloc(EQUIX_CTX_SOLVE); + ctx = build_equix_ctx(EQUIX_CTX_SOLVE); + if (!ctx) { + goto end; + } equix_solution solutions[EQUIX_MAX_SOLS]; log_notice(LD_REND, "Solving proof of work (effort %u)", effort); @@ -239,9 +259,12 @@ hs_pow_verify(const hs_pow_service_state_t *pow_state, goto done; } - /* Fail if equix_verify(C || N || E, S) != EQUIX_OK */ - ctx = equix_alloc(EQUIX_CTX_SOLVE); + ctx = build_equix_ctx(EQUIX_CTX_VERIFY); + if (!ctx) { + goto done; + } + /* Fail if equix_verify(C || N || E, S) != EQUIX_OK */ equix_result result = equix_verify(ctx, challenge, HS_POW_CHALLENGE_LEN, &pow_solution->equix_solution); if (result != EQUIX_OK) { |