From 51407f1797c77c742815d3135632666f4d940cb7 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sat, 18 Nov 2017 13:43:28 +1300 Subject: Switch to in-house byte-order switching --- Makefile | 2 ++ endian.h | 13 +++++++++++++ sand-leek.c | 4 ++-- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 endian.h diff --git a/Makefile b/Makefile index 144a423..adf947e 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ LDFLAGS += -lssl -lcrypto -lpthread all: sand-leek +sand-leek.o: endian.h onion_base32.h key_update.h + sand-leek: sand-leek.o onion_base32.o key_update.o $(CC) -o $@ $^ $(LDFLAGS) diff --git a/endian.h b/endian.h new file mode 100644 index 0000000..6ebda83 --- /dev/null +++ b/endian.h @@ -0,0 +1,13 @@ +#ifndef SAND_LEEK_ENDIAN_H +#define SAND_LEEK_ENDIAN_H + +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define sl_htobe32(x) (x) +#else +# define sl_htobe32(x) (((x & 0x000000FF) << 24) | \ + ((x & 0xFF000000) >> 24)) | \ + ((x & 0x0000FF00) << 8) | \ + ((x & 0x00FF0000) >> 8) +#endif + +#endif /* ifndef SAND_LEEK_ENDIAN_H */ diff --git a/sand-leek.c b/sand-leek.c index 7c5ea29..97b9b1d 100644 --- a/sand-leek.c +++ b/sand-leek.c @@ -6,12 +6,12 @@ #include #include #include -#include #include #include #include #include +#include "endian.h" #include "onion_base32.h" #include "key_update.h" @@ -91,7 +91,7 @@ work(void *arg) { while (e < EXPONENT_MAX) { memcpy(&working_sha_c, &sha_c, sizeof(SHA_CTX)); - e_big_endian = htobe32(e); + e_big_endian = sl_htobe32(e); SHA1_Update(&working_sha_c, &e_big_endian, EXPONENT_SIZE_BYTES); SHA1_Final((unsigned char*)&sha, &working_sha_c); -- cgit v1.1