Commit 42c667b3 authored by Ulrik Sverdrup's avatar Ulrik Sverdrup

siphash: Use uint64_t directly, remove typedef

parent dd000c9a
......@@ -6,8 +6,6 @@
#include "siphash.h"
typedef uint64_t u64;
enum sip_index { A=0, B=2, C=1, D=3, E=4 };
#define rol(x,l) (((x) << (l)) | ((x) >> (64-(l))))
......@@ -26,14 +24,14 @@ enum sip_index { A=0, B=2, C=1, D=3, E=4 };
} while(0)
static inline u64 W64(const unsigned char *p, size_t j)
static inline uint64_t W64(const unsigned char *p, size_t j)
{
uint64_t x;
memcpy(&x, p + j*sizeof(x), sizeof(x));
return le64_to_cpu(x);
}
static void siphash_init(u64 v[5], const unsigned char key[16])
static void siphash_init(uint64_t v[5], const unsigned char key[16])
{
v[A] = W64(key, 0) ^ UINT64_C(0x736f6d6570736575);
v[B] = W64(key, 1) ^ UINT64_C(0x646f72616e646f6d);
......@@ -43,25 +41,25 @@ static void siphash_init(u64 v[5], const unsigned char key[16])
}
/* Load the last 0-7 bytes of `in` and put in len & 255 */
static void siphash_epilogue(u64 *m, const unsigned char *in, size_t len)
static void siphash_epilogue(uint64_t *m, const unsigned char *in, size_t len)
{
in += len & ~(size_t)7;
*m = (u64)(len & 255) << 56;
*m = (uint64_t)(len & 255) << 56;
switch (len & 7) {
case 7: *m |= (u64) in[6] << 48;
case 6: *m |= (u64) in[5] << 40;
case 5: *m |= (u64) in[4] << 32;
case 4: *m |= (u64) in[3] << 24;
case 3: *m |= (u64) in[2] << 16;
case 2: *m |= (u64) in[1] << 8;
case 1: *m |= (u64) in[0];
case 7: *m |= (uint64_t) in[6] << 48;
case 6: *m |= (uint64_t) in[5] << 40;
case 5: *m |= (uint64_t) in[4] << 32;
case 4: *m |= (uint64_t) in[3] << 24;
case 3: *m |= (uint64_t) in[2] << 16;
case 2: *m |= (uint64_t) in[1] << 8;
case 1: *m |= (uint64_t) in[0];
case 0: ;
}
}
u64 siphash_2_4(const void *in, size_t len, const unsigned char key[16])
uint64_t siphash_2_4(const void *in, size_t len, const unsigned char key[16])
{
u64 v[5];
uint64_t v[5];
size_t j;
siphash_init(v, key);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment