siphash24: change result argument to uint64_t
Change the "out" parameter from uint8_t[8] to uint64_t. On architectures which enforce pointer alignment this fixes crashes when we previously cast an unaligned array to uint64_t*, and on others this should at least improve performance as the compiler now aligns these properly. This also simplifies the code in most cases by getting rid of typecasts. The only place which we can't change is struct duid's en.id, as that is _packed_ and public API, so we can't enforce alignment of the "id" field and have to use memcpy instead.
This commit is contained in:
@@ -47,7 +47,7 @@ static int generate_mac(
|
||||
sd_id128_t hash_key,
|
||||
uint64_t idx) {
|
||||
|
||||
uint8_t result[8];
|
||||
uint64_t result;
|
||||
size_t l, sz;
|
||||
uint8_t *v, *i;
|
||||
int r;
|
||||
@@ -74,10 +74,10 @@ static int generate_mac(
|
||||
|
||||
/* Let's hash the host machine ID plus the container name. We
|
||||
* use a fixed, but originally randomly created hash key here. */
|
||||
siphash24(result, v, sz, hash_key.bytes);
|
||||
siphash24(&result, v, sz, hash_key.bytes);
|
||||
|
||||
assert_cc(ETH_ALEN <= sizeof(result));
|
||||
memcpy(mac->ether_addr_octet, result, ETH_ALEN);
|
||||
memcpy(mac->ether_addr_octet, &result, ETH_ALEN);
|
||||
|
||||
/* see eth_random_addr in the kernel */
|
||||
mac->ether_addr_octet[0] &= 0xfe; /* clear multicast bit */
|
||||
|
||||
Reference in New Issue
Block a user