[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor] 56/77: hs_pow: unswap byte order of seed_head field



This is an automated email from the git hooks/post-receive script.

dgoulet pushed a commit to branch main
in repository tor.

commit 1a3afeb387461680bcf97f5cf8574ee0e0cad893
Author: Micah Elizabeth Scott <beth@xxxxxxxxxxxxxx>
AuthorDate: Tue Mar 14 15:25:12 2023 -0700

    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@xxxxxxxxxxxxxx>
---
 src/feature/hs/hs_pow.c     | 8 +++++---
 src/test/test_hs_pow.c      | 9 ++++-----
 src/test/test_hs_pow_slow.c | 5 ++---
 3 files changed, 11 insertions(+), 11 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.");
diff --git a/src/test/test_hs_pow.c b/src/test/test_hs_pow.c
index 706ad2db05..e2111478fc 100644
--- a/src/test/test_hs_pow.c
+++ b/src/test/test_hs_pow.c
@@ -315,7 +315,7 @@ test_hs_pow_vectors(void *arg)
       "cdd49fdbc34326d9d2f18ed277469c63", "7f153437c58620d3ea4717746093dde6",
       "01"
       "cdd49fdbc34326d9d2f18ed277469c63"
-      "0001869f" "cf0afb86"
+      "0001869f" "86fb0acf"
       "7f153437c58620d3ea4717746093dde6"
     },
     {
@@ -325,7 +325,7 @@ test_hs_pow_vectors(void *arg)
       "cdd49fdbc34326d9d2f18ed270469c63", "7f153437c58620d3ea4717746093dde6",
       "01"
       "cdd49fdbc34326d9d2f18ed270469c63"
-      "000186a0" "cf0afb86"
+      "000186a0" "86fb0acf"
       "7f153437c58620d3ea4717746093dde6"
     },
     {
@@ -335,7 +335,7 @@ test_hs_pow_vectors(void *arg)
       "cdd49fdbc34326d9d2f18ed277469c63", "7f153437c58620d3ea4717746093dde6",
       "01"
       "cdd49fdbc34326d9d2f18ed277469c63"
-      "000186a0" "cf0afb86"
+      "000186a0" "86fb0acf"
       "7f153437c58620d3ea4717746093dde6"
     }
   };
@@ -382,8 +382,7 @@ test_hs_pow_vectors(void *arg)
                             sol_hex, 2 * sizeof solution.equix_solution),
                             OP_EQ, HS_POW_EQX_SOL_LEN);
 
-    memcpy(&solution.seed_head, pow_state->seed_previous,
-           sizeof solution.seed_head);
+    solution.seed_head = tor_ntohl(get_uint32(pow_state->seed_previous));
 
     /* Try to encode 'solution' into a relay cell */
 
diff --git a/src/test/test_hs_pow_slow.c b/src/test/test_hs_pow_slow.c
index 4d28765ba9..8ccbf8025c 100644
--- a/src/test/test_hs_pow_slow.c
+++ b/src/test/test_hs_pow_slow.c
@@ -211,15 +211,14 @@ test_hs_pow_vectors(void *arg)
                             sizeof solution.equix_solution,
                             sol_hex, 2 * sizeof solution.equix_solution),
                             OP_EQ, HS_POW_EQX_SOL_LEN);
-    memcpy(&solution.seed_head, params.seed, sizeof solution.seed_head);
+    solution.seed_head = tor_ntohl(get_uint32(params.seed));
 
     memset(&output, 0xaa, sizeof output);
     testing_enable_prefilled_rng(rng_bytes, HS_POW_NONCE_LEN);
     tt_int_op(0, OP_EQ, hs_pow_solve(&params, &output));
     testing_disable_prefilled_rng();
 
-    tt_mem_op(params.seed, OP_EQ, &output.seed_head,
-              sizeof output.seed_head);
+    tt_int_op(solution.seed_head, OP_EQ, output.seed_head);
     tt_mem_op(&solution.nonce, OP_EQ, &output.nonce,
               sizeof output.nonce);
     tt_mem_op(&solution.equix_solution, OP_EQ, &output.equix_solution,

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits