summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-10-06 15:04:42 +0200
committerTom Gundersen <teg@jklm.no>2015-10-06 17:47:00 +0200
commit0cb3c286883b694fc52a18a3b559ff98931641f3 (patch)
treef8c3cf9104b3ea8fc180bd1de1e72119dfe4524e /src/basic
parent8c60d978bd3453659bfa7f4d90a17ba5fa3e0774 (diff)
siphash24: unify API
Make the API of the new helpers more similar to the old wrapper. In particular we now return the hash as a byte string to avoid any endianness problems.
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/hashmap.c7
-rw-r--r--src/basic/siphash24.c15
-rw-r--r--src/basic/siphash24.h4
3 files changed, 14 insertions, 12 deletions
diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c
index 3e17ed30df..20e7e51d9e 100644
--- a/src/basic/hashmap.c
+++ b/src/basic/hashmap.c
@@ -372,12 +372,15 @@ static uint8_t *hash_key(HashmapBase *h) {
static unsigned base_bucket_hash(HashmapBase *h, const void *p) {
struct siphash state;
+ uint64_t hash;
- siphash_init(&state, hash_key(h));
+ siphash24_init(&state, hash_key(h));
h->hash_ops->hash(p, &state);
- return (unsigned) (siphash24_finalize(&state) % n_buckets(h));
+ siphash24_finalize((uint8_t*)&hash, &state);
+
+ return (unsigned) (hash % n_buckets(h));
}
#define bucket_hash(h, p) base_bucket_hash(HASHMAP_BASE(h), p)
diff --git a/src/basic/siphash24.c b/src/basic/siphash24.c
index 308e4230c5..9c56b5e9ea 100644
--- a/src/basic/siphash24.c
+++ b/src/basic/siphash24.c
@@ -52,7 +52,7 @@ typedef uint8_t u8;
(state)->v2 += (state)->v1; (state)->v1=ROTL((state)->v1,17); (state)->v1 ^= (state)->v2; (state)->v2=ROTL((state)->v2,32); \
} while(0)
-void siphash_init(struct siphash *state, const uint8_t k[16]) {
+void siphash24_init(struct siphash *state, const uint8_t k[16]) {
u64 k0, k1;
k0 = U8TO64_LE( k );
@@ -140,7 +140,7 @@ void siphash24_compress(const void *_in, size_t inlen, struct siphash *state) {
}
}
-uint64_t siphash24_finalize(struct siphash *state) {
+void siphash24_finalize(uint8_t out[8], struct siphash *state) {
u64 b;
b = state->padding | (( ( u64 )state->inlen ) << 56);
@@ -168,20 +168,19 @@ uint64_t siphash24_finalize(struct siphash *state) {
SIPROUND(state);
SIPROUND(state);
- return state->v0 ^ state->v1 ^ state->v2 ^ state->v3;
+ b = state->v0 ^ state->v1 ^ state->v2 ^ state->v3;
+
+ U64TO8_LE( out, b );
}
/* SipHash-2-4 */
void siphash24(uint8_t out[8], const void *_in, size_t inlen, const uint8_t k[16])
{
struct siphash state;
- u64 b;
- siphash_init(&state, k);
+ siphash24_init(&state, k);
siphash24_compress(_in, inlen, &state);
- b = siphash24_finalize(&state);
-
- U64TO8_LE( out, b );
+ siphash24_finalize(out, &state);
}
diff --git a/src/basic/siphash24.h b/src/basic/siphash24.h
index c107bdd213..6c5cd98ee8 100644
--- a/src/basic/siphash24.h
+++ b/src/basic/siphash24.h
@@ -12,8 +12,8 @@ struct siphash {
size_t inlen;
};
-void siphash_init(struct siphash *state, const uint8_t k[16]);
+void siphash24_init(struct siphash *state, const uint8_t k[16]);
void siphash24_compress(const void *in, size_t inlen, struct siphash *state);
-uint64_t siphash24_finalize(struct siphash *state);
+void siphash24_finalize(uint8_t out[8], struct siphash *state);
void siphash24(uint8_t out[8], const void *in, size_t inlen, const uint8_t k[16]);