aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-11-18 13:43:28 +1300
committerDavid Phillips <david@sighup.nz>2017-11-18 13:43:28 +1300
commit51407f1797c77c742815d3135632666f4d940cb7 (patch)
tree9eae513f96a9fdcb9a6a9b17d804a3a63b949308
parent8816f394206b7642c159caf0d2db9b3ab55b7d10 (diff)
downloadsand-leek-51407f1797c77c742815d3135632666f4d940cb7.tar.xz
Switch to in-house byte-order switching
-rw-r--r--Makefile2
-rw-r--r--endian.h13
-rw-r--r--sand-leek.c4
3 files changed, 17 insertions, 2 deletions
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 <semaphore.h>
#include <errno.h>
#include <string.h>
-#include <endian.h>
#include <openssl/rsa.h>
#include <openssl/sha.h>
#include <openssl/pem.h>
#include <openssl/err.h>
+#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);