diff options
author | Micah Elizabeth Scott <beth@torproject.org> | 2023-05-28 19:45:41 -0700 |
---|---|---|
committer | Micah Elizabeth Scott <beth@torproject.org> | 2023-05-28 20:02:03 -0700 |
commit | 415c0354b2e495f236ddf8f67accb3cba4249e21 (patch) | |
tree | 9d23499ebbb127ea3bd6636c725dcf423c61b483 /src/feature/hs/hs_pow.c | |
parent | a397a92be2032e781479fa4d53a04f9b369ea1ac (diff) | |
download | tor-415c0354b2e495f236ddf8f67accb3cba4249e21.tar.gz tor-415c0354b2e495f236ddf8f67accb3cba4249e21.zip |
hs_pow: Add CompiledProofOfWorkHash torrc option
This exposes the new fallback behavior in hashx via a new AUTOBOOL
configuration option, available to both clients and services. The
default should be fine for nearly everyone, but it might be necessary
to enable or disable the compiler manually for diagnostic purposes.
Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
Diffstat (limited to 'src/feature/hs/hs_pow.c')
-rw-r--r-- | src/feature/hs/hs_pow.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/feature/hs/hs_pow.c b/src/feature/hs/hs_pow.c index 27d09cb0b4..5cee3b00d7 100644 --- a/src/feature/hs/hs_pow.c +++ b/src/feature/hs/hs_pow.c @@ -175,9 +175,24 @@ unpack_equix_solution(const uint8_t *bytes_in, } } +/** Helper: Map the CompiledProofOfWorkHash configuration option to its + * corresponding equix_ctx_flags bit. */ +static equix_ctx_flags +hs_pow_equix_option_flags(int CompiledProofOfWorkHash) +{ + if (CompiledProofOfWorkHash == 0) { + return 0; + } else if (CompiledProofOfWorkHash == 1) { + return EQUIX_CTX_MUST_COMPILE; + } else { + tor_assert_nonfatal(CompiledProofOfWorkHash == -1); + return EQUIX_CTX_TRY_COMPILE; + } +} + /** Solve the EquiX/blake2b PoW scheme using the parameters in pow_params, and * store the solution in pow_solution_out. Returns 0 on success and -1 - * otherwise. Called by a client. */ + * otherwise. Called by a client, from a cpuworker thread. */ int hs_pow_solve(const hs_pow_solver_inputs_t *pow_inputs, hs_pow_solution_t *pow_solution_out) @@ -198,7 +213,10 @@ hs_pow_solve(const hs_pow_solver_inputs_t *pow_inputs, challenge = build_equix_challenge(&pow_inputs->service_blinded_id, pow_inputs->seed, nonce, effort); - ctx = equix_alloc(EQUIX_CTX_SOLVE | EQUIX_CTX_TRY_COMPILE); + /* This runs on a cpuworker, let's not access global get_options(). + * Instead, the particular options we need are captured in pow_inputs. */ + ctx = equix_alloc(EQUIX_CTX_SOLVE | + hs_pow_equix_option_flags(pow_inputs->CompiledProofOfWorkHash)); if (!ctx) { goto end; } @@ -339,7 +357,8 @@ hs_pow_verify(const ed25519_public_key_t *service_blinded_id, goto done; } - ctx = equix_alloc(EQUIX_CTX_VERIFY | EQUIX_CTX_TRY_COMPILE); + ctx = equix_alloc(EQUIX_CTX_VERIFY | + hs_pow_equix_option_flags(get_options()->CompiledProofOfWorkHash)); if (!ctx) { goto done; } @@ -428,7 +447,6 @@ pow_worker_threadfn(void *state_, void *work_) job->pow_solution_out = tor_malloc_zero(sizeof(hs_pow_solution_t)); if (hs_pow_solve(&job->pow_inputs, job->pow_solution_out)) { - log_warn(LD_REND, "Failed to run the proof of work solver"); tor_free(job->pow_solution_out); job->pow_solution_out = NULL; /* how we signal that we came up empty */ } |