]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
equix: Portability fixes for big endian platforms
authorMicah Elizabeth Scott <beth@torproject.org>
Wed, 15 Mar 2023 20:34:21 +0000 (13:34 -0700)
committerMicah Elizabeth Scott <beth@torproject.org>
Wed, 10 May 2023 14:38:28 +0000 (07:38 -0700)
Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
src/ext/equix/hashx/src/hashx.c
src/ext/equix/src/solver.h

index 1f5715dce8c42e6bd4a53a334d63013c813b6e75..5f17ccd5227569c262f72d0222e9410052e6821f 100644 (file)
@@ -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)) {
index ad69951929be7e5843a5608cf06620a259303219..4cf4105679274ee9f8225f09787c647c7ddc8d2e 100644 (file)
@@ -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]);