siphash24: let siphash24_finalize() and siphash24() return the result directly

Rather than passing a pointer to return the result, return it directly
from the function calls.

Also, return the result in native endianess, and let the callers care
about the conversion. For hash tables and bloom filters, we don't care,
but in order to keep MAC addresses and DHCP client IDs stable, we
explicitly convert to LE.
This commit is contained in:
Daniel Mack
2015-11-16 23:17:52 +01:00
parent 5cd6491b71
commit 933f9caeeb
14 changed files with 27 additions and 27 deletions
+1 -1
View File
@@ -380,7 +380,7 @@ static unsigned base_bucket_hash(HashmapBase *h, const void *p) {
h->hash_ops->hash(p, &state);
siphash24_finalize(&hash, &state);
hash = siphash24_finalize(&state);
return (unsigned) (hash % n_buckets(h));
}
+5 -4
View File
@@ -141,7 +141,7 @@ void siphash24_compress(const void *_in, size_t inlen, struct siphash *state) {
}
}
void siphash24_finalize(uint64_t *out, struct siphash *state) {
uint64_t siphash24_finalize(struct siphash *state) {
uint64_t b;
b = state->padding | (( ( uint64_t )state->inlen ) << 56);
@@ -170,14 +170,15 @@ void siphash24_finalize(uint64_t *out, struct siphash *state) {
sipround(state);
sipround(state);
*(le64_t*)out = htole64(state->v0 ^ state->v1 ^ state->v2 ^ state->v3);
return state->v0 ^ state->v1 ^ state->v2 ^ state->v3;
}
/* SipHash-2-4 */
void siphash24(uint64_t *out, const void *_in, size_t inlen, const uint8_t k[16]) {
uint64_t siphash24(const void *_in, size_t inlen, const uint8_t k[16]) {
struct siphash state;
siphash24_init(&state, k);
siphash24_compress(_in, inlen, &state);
siphash24_finalize(out, &state);
return siphash24_finalize(&state);
}
+2 -2
View File
@@ -14,6 +14,6 @@ struct siphash {
void siphash24_init(struct siphash *state, const uint8_t k[16]);
void siphash24_compress(const void *in, size_t inlen, struct siphash *state);
void siphash24_finalize(uint64_t *out, struct siphash *state);
uint64_t siphash24_finalize(struct siphash *state);
void siphash24(uint64_t *out, const void *in, size_t inlen, const uint8_t k[16]);
uint64_t siphash24(const void *in, size_t inlen, const uint8_t k[16]);