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

[tor-commits] [tor] 51/77: equix: Portability fixes for big endian platforms



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

dgoulet pushed a commit to branch main
in repository tor.

commit ae86d98815ad61c447cd81c0060d403641e3071a
Author: Micah Elizabeth Scott <beth@xxxxxxxxxxxxxx>
AuthorDate: Wed Mar 15 13:34:21 2023 -0700

    equix: Portability fixes for big endian platforms
    
    Signed-off-by: Micah Elizabeth Scott <beth@xxxxxxxxxxxxxx>
---
 src/ext/equix/hashx/src/hashx.c | 18 +++++++++++++++---
 src/ext/equix/src/solver.h      | 18 ++++++++++++++++--
 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]);

-- 
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