Browse Source

Get csiphash better integrated with our build system

Nick Mathewson 10 years ago
parent
commit
9605978eb6
3 changed files with 12 additions and 8 deletions
  1. 1 0
      src/common/include.am
  2. 9 7
      src/ext/csiphash.c
  3. 2 1
      src/ext/include.am

+ 1 - 0
src/common/include.am

@@ -61,6 +61,7 @@ LIBOR_A_SOURCES = \
   src/common/util.c					\
   src/common/util_codedigest.c				\
   src/common/sandbox.c					\
+  src/ext/csiphash.c					\
   $(libor_extra_source)
 
 LIBOR_CRYPTO_A_SOURCES = \

+ 9 - 7
src/ext/csiphash.c

@@ -29,7 +29,8 @@
     Jean-Philippe Aumasson (https://131002.net/siphash/siphash24.c)
 */
 
-#include <stdint.h>
+#include "torint.h"
+#include "siphash.h"
 
 #if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
 	__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
@@ -58,7 +59,6 @@
 
 #endif
 
-
 #define ROTATE(x, b) (uint64_t)( ((x) << (b)) | ( (x) >> (64 - (b))) )
 
 #define HALF_ROUND(a,b,c,d,s,t)			\
@@ -74,13 +74,15 @@
 	HALF_ROUND(v2,v1,v0,v3,17,21);
 
 
-uint64_t siphash24(const void *src, unsigned long src_sz, const char key[16]) {
-	const uint64_t *_key = (uint64_t *)key;
-	uint64_t k0 = _le64toh(_key[0]);
-	uint64_t k1 = _le64toh(_key[1]);
+uint64_t siphash24(const void *src, unsigned long src_sz, const struct sipkey *key) {
+	uint64_t k0 = key->k0;
+	uint64_t k1 = key->k1;
 	uint64_t b = (uint64_t)src_sz << 56;
 	const uint64_t *in = (uint64_t*)src;
 
+        uint64_t t;
+        uint8_t *pt, *m;
+
 	uint64_t v0 = k0 ^ 0x736f6d6570736575ULL;
 	uint64_t v1 = k1 ^ 0x646f72616e646f6dULL;
 	uint64_t v2 = k0 ^ 0x6c7967656e657261ULL;
@@ -94,7 +96,7 @@ uint64_t siphash24(const void *src, unsigned long src_sz, const char key[16]) {
 		v0 ^= mi;
 	}
 
-	uint64_t t = 0; uint8_t *pt = (uint8_t *)&t; uint8_t *m = (uint8_t *)in;
+	t = 0; pt = (uint8_t*)&t; m = (uint8_t*)in;
 	switch (src_sz) {
 	case 7: pt[6] = m[6];
 	case 6: pt[5] = m[5];

+ 2 - 1
src/ext/include.am

@@ -10,7 +10,8 @@ EXTHEADERS = \
   src/ext/strlcat.c	\
   src/ext/strlcpy.c	\
   src/ext/tinytest_macros.h \
-  src/ext/tor_queue.h
+  src/ext/tor_queue.h	\
+  src/ext/siphash.h
 
 noinst_HEADERS+= $(EXTHEADERS)