diff options
author | Micah Elizabeth Scott <beth@torproject.org> | 2023-03-14 15:25:12 -0700 |
---|---|---|
committer | Micah Elizabeth Scott <beth@torproject.org> | 2023-05-10 07:38:28 -0700 |
commit | 1a3afeb387461680bcf97f5cf8574ee0e0cad893 (patch) | |
tree | 271cebad707b17853cc47d7cc3a75bf65fa751c0 /src/feature/hs/hs_pow.c | |
parent | 037dea2252e5122059bd189c57ad606f05c7b0b7 (diff) | |
download | tor-1a3afeb387461680bcf97f5cf8574ee0e0cad893.tar.gz tor-1a3afeb387461680bcf97f5cf8574ee0e0cad893.zip |
hs_pow: unswap byte order of seed_head field
In proposal 327, "POW_SEED is the first 4 bytes of the seed used".
The proposal doesn't specifically mention the data type of this field,
and the code in hs_pow so far treats it as an integer but semantically
it's more like the first four bytes of an already-encoded little endian
blob. This leads to a byte swap, since the type confusion takes place
in a little-endian subsystem but the wire encoding of seed_head uses
tor's default of big endian.
This patch does not address the underlying type confusion, it's a
minimal change that only swaps the byte order and updates unit tests
accordingly. Further changes will clean up the data types.
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 | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/feature/hs/hs_pow.c b/src/feature/hs/hs_pow.c index 0c138273e8..1fc9de1268 100644 --- a/src/feature/hs/hs_pow.c +++ b/src/feature/hs/hs_pow.c @@ -182,7 +182,7 @@ hs_pow_solve(const hs_pow_desc_params_t *pow_params, /* Store the effort E. */ pow_solution_out->effort = effort; /* We only store the first 4 bytes of the seed C. */ - pow_solution_out->seed_head = get_uint32(pow_params->seed); + pow_solution_out->seed_head = tor_ntohl(get_uint32(pow_params->seed)); /* Store the solution S */ memcpy(&pow_solution_out->equix_solution, sol, sizeof(pow_solution_out->equix_solution)); @@ -231,9 +231,11 @@ hs_pow_verify(const hs_pow_service_state_t *pow_state, /* Find a valid seed C that starts with the seed head. Fail if no such seed * exists. */ - if (get_uint32(pow_state->seed_current) == pow_solution->seed_head) { + if (tor_ntohl(get_uint32(pow_state->seed_current)) + == pow_solution->seed_head) { seed = pow_state->seed_current; - } else if (get_uint32(pow_state->seed_previous) == pow_solution->seed_head) { + } else if (tor_ntohl(get_uint32(pow_state->seed_previous)) + == pow_solution->seed_head) { seed = pow_state->seed_previous; } else { log_warn(LD_REND, "Seed head didn't match either seed."); |