From 0cb3c286883b694fc52a18a3b559ff98931641f3 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Tue, 6 Oct 2015 15:04:42 +0200 Subject: 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. --- src/libsystemd-network/sd-dhcp-server.c | 6 ++++-- src/libsystemd-network/test-dhcp-server.c | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src/libsystemd-network') diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index d941e6c0de..d27bb561ca 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -741,15 +741,17 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message, address = existing_lease->address; else { struct siphash state; + uint64_t hash; uint32_t next_offer; /* even with no persistence of leases, we try to offer the same client the same IP address. we do this by using the hash of the client id as the offset into the pool of leases when finding the next free one */ - siphash_init(&state, HASH_KEY.bytes); + siphash24_init(&state, HASH_KEY.bytes); client_id_hash_func(&req->client_id, &state); - next_offer = siphash24_finalize(&state) % server->pool_size; + siphash24_finalize((uint8_t*)&hash, &state); + next_offer = hash % server->pool_size; for (i = 0; i < server->pool_size; i++) { if (!server->bound_leases[next_offer]) { diff --git a/src/libsystemd-network/test-dhcp-server.c b/src/libsystemd-network/test-dhcp-server.c index 01205efc18..c3bcb9cb4b 100644 --- a/src/libsystemd-network/test-dhcp-server.c +++ b/src/libsystemd-network/test-dhcp-server.c @@ -200,10 +200,13 @@ static void test_message_handler(void) { static uint64_t client_id_hash_helper(DHCPClientId *id, uint8_t key[HASH_KEY_SIZE]) { struct siphash state; + uint64_t hash; - siphash_init(&state, key); + siphash24_init(&state, key); client_id_hash_func(id, &state); - return siphash24_finalize(&state); + siphash24_finalize((uint8_t*)&hash, &state); + + return hash; } static void test_client_id_hash(void) { -- cgit v1.2.3-54-g00ecf