aboutsummaryrefslogtreecommitdiff
path: root/src/ext
diff options
context:
space:
mode:
authorMicah Elizabeth Scott <beth@torproject.org>2023-03-15 13:34:21 -0700
committerMicah Elizabeth Scott <beth@torproject.org>2023-05-10 07:38:28 -0700
commitae86d98815ad61c447cd81c0060d403641e3071a (patch)
treee4e540c5f64c3374a3fdf3148aa37db60aa40524 /src/ext
parentdaa08557ad81f71313604d8a3ec29d22319ecc58 (diff)
downloadtor-ae86d98815ad61c447cd81c0060d403641e3071a.tar.gz
tor-ae86d98815ad61c447cd81c0060d403641e3071a.zip
equix: Portability fixes for big endian platforms
Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
Diffstat (limited to 'src/ext')
-rw-r--r--src/ext/equix/hashx/src/hashx.c18
-rw-r--r--src/ext/equix/src/solver.h18
2 files changed, 31 insertions, 5 deletions
diff --git a/src/ext/equix/hashx/src/hashx.c b/src/ext/equix/hashx/src/hashx.c
index 1f5715dce8..5f17ccd522 100644
--- a/src/ext/equix/hashx/src/hashx.c
+++ b/src/ext/equix/hashx/src/hashx.c
@@ -41,12 +41,24 @@ static int initialize_program(hashx_ctx* ctx, hashx_program* program,
int hashx_make(hashx_ctx* ctx, const void* seed, size_t size) {
assert(ctx != NULL && ctx != HASHX_NOTSUPP);
- assert(seed != NULL || size == 0);
- siphash_state keys[2];
+ assert(seed != NULL || size == 0);
+
+ uint8_t keys_bytes[2 * sizeof(siphash_state)];
blake2b_state hash_state;
hashx_blake2b_init_param(&hash_state, &hashx_blake2_params);
hashx_blake2b_update(&hash_state, seed, size);
- hashx_blake2b_final(&hash_state, &keys, sizeof(keys));
+ hashx_blake2b_final(&hash_state, keys_bytes, sizeof(keys_bytes));
+
+ siphash_state keys[2];
+ keys[0].v0 = load64(keys_bytes + 0 * sizeof(uint64_t));
+ keys[0].v1 = load64(keys_bytes + 1 * sizeof(uint64_t));
+ keys[0].v2 = load64(keys_bytes + 2 * sizeof(uint64_t));
+ keys[0].v3 = load64(keys_bytes + 3 * sizeof(uint64_t));
+ keys[1].v0 = load64(keys_bytes + 4 * sizeof(uint64_t));
+ keys[1].v1 = load64(keys_bytes + 5 * sizeof(uint64_t));
+ keys[1].v2 = load64(keys_bytes + 6 * sizeof(uint64_t));
+ keys[1].v3 = load64(keys_bytes + 7 * sizeof(uint64_t));
+
if (ctx->type & HASHX_COMPILED) {
hashx_program program;
if (!initialize_program(ctx, &program, keys)) {
diff --git a/src/ext/equix/src/solver.h b/src/ext/equix/src/solver.h
index ad69951929..4cf4105679 100644
--- a/src/ext/equix/src/solver.h
+++ b/src/ext/equix/src/solver.h
@@ -17,12 +17,26 @@ static inline bool tree_cmp1(const equix_idx* left, const equix_idx* right) {
return *left <= *right;
}
+static inline uint32_t tree_idx2(const equix_idx* idx) {
+ return
+ (uint32_t)idx[1] << 1*16 |
+ (uint32_t)idx[0] << 0*16;
+}
+
static inline bool tree_cmp2(const equix_idx* left, const equix_idx* right) {
- return load32(left) <= load32(right);
+ return tree_idx2(left) <= tree_idx2(right);
+}
+
+static inline uint64_t tree_idx4(const equix_idx* idx) {
+ return
+ (uint64_t)idx[3] << 3*16 |
+ (uint64_t)idx[2] << 2*16 |
+ (uint64_t)idx[1] << 1*16 |
+ (uint64_t)idx[0] << 0*16;
}
static inline bool tree_cmp4(const equix_idx* left, const equix_idx* right) {
- return load64(left) <= load64(right);
+ return tree_idx4(left) <= tree_idx4(right);
}
EQUIX_PRIVATE int equix_solver_solve(hashx_ctx* hash_func, solver_heap* heap, equix_solution output[EQUIX_MAX_SOLS]);