mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 08:56:15 +09:00
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:
@@ -380,7 +380,7 @@ static unsigned base_bucket_hash(HashmapBase *h, const void *p) {
|
||||
|
||||
h->hash_ops->hash(p, &state);
|
||||
|
||||
siphash24_finalize((uint8_t*)&hash, &state);
|
||||
siphash24_finalize(&hash, &state);
|
||||
|
||||
return (unsigned) (hash % n_buckets(h));
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ void siphash24_compress(const void *_in, size_t inlen, struct siphash *state) {
|
||||
}
|
||||
}
|
||||
|
||||
void siphash24_finalize(uint8_t out[8], struct siphash *state) {
|
||||
void siphash24_finalize(uint64_t *out, struct siphash *state) {
|
||||
uint64_t b;
|
||||
|
||||
b = state->padding | (( ( uint64_t )state->inlen ) << 56);
|
||||
@@ -174,7 +174,7 @@ void siphash24_finalize(uint8_t out[8], struct siphash *state) {
|
||||
}
|
||||
|
||||
/* SipHash-2-4 */
|
||||
void siphash24(uint8_t out[8], const void *_in, size_t inlen, const uint8_t k[16]) {
|
||||
void siphash24(uint64_t *out, const void *_in, size_t inlen, const uint8_t k[16]) {
|
||||
struct siphash state;
|
||||
|
||||
siphash24_init(&state, k);
|
||||
|
||||
@@ -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(uint8_t out[8], struct siphash *state);
|
||||
void siphash24_finalize(uint64_t *out, struct siphash *state);
|
||||
|
||||
void siphash24(uint8_t out[8], const void *in, size_t inlen, const uint8_t k[16]);
|
||||
void siphash24(uint64_t *out, const void *in, size_t inlen, const uint8_t k[16]);
|
||||
|
||||
Reference in New Issue
Block a user