siphash24: introduce siphash24_compress_typesafe() macro
To prevent copy-and-paste mistake. This also introduce in_addr_hash_func(). No functional change, just refactoring.
This commit is contained in:
@@ -59,8 +59,8 @@ void hw_addr_hash_func(const struct hw_addr_data *p, struct siphash *state) {
|
||||
assert(p);
|
||||
assert(state);
|
||||
|
||||
siphash24_compress(&p->length, sizeof(p->length), state);
|
||||
siphash24_compress(p->bytes, p->length, state);
|
||||
siphash24_compress_typesafe(p->length, state);
|
||||
siphash24_compress_safe(p->bytes, p->length, state);
|
||||
}
|
||||
|
||||
DEFINE_HASH_OPS(hw_addr_hash_ops, struct hw_addr_data, hw_addr_hash_func, hw_addr_compare);
|
||||
@@ -106,7 +106,7 @@ int ether_addr_compare(const struct ether_addr *a, const struct ether_addr *b) {
|
||||
}
|
||||
|
||||
static void ether_addr_hash_func(const struct ether_addr *p, struct siphash *state) {
|
||||
siphash24_compress(p, sizeof(struct ether_addr), state);
|
||||
siphash24_compress_typesafe(*p, state);
|
||||
}
|
||||
|
||||
DEFINE_HASH_OPS(ether_addr_hash_ops, struct ether_addr, ether_addr_hash_func, ether_addr_compare);
|
||||
|
||||
@@ -33,7 +33,7 @@ void path_hash_func(const char *q, struct siphash *state) {
|
||||
|
||||
/* if path is absolute, add one "/" to the hash. */
|
||||
if (path_is_absolute(q))
|
||||
siphash24_compress("/", 1, state);
|
||||
siphash24_compress_byte('/', state);
|
||||
|
||||
for (;;) {
|
||||
const char *e;
|
||||
@@ -67,7 +67,7 @@ DEFINE_HASH_OPS_FULL(path_hash_ops_free_free,
|
||||
void, free);
|
||||
|
||||
void trivial_hash_func(const void *p, struct siphash *state) {
|
||||
siphash24_compress(&p, sizeof(p), state);
|
||||
siphash24_compress_typesafe(p, state);
|
||||
}
|
||||
|
||||
int trivial_compare_func(const void *a, const void *b) {
|
||||
@@ -93,7 +93,7 @@ const struct hash_ops trivial_hash_ops_free_free = {
|
||||
};
|
||||
|
||||
void uint64_hash_func(const uint64_t *p, struct siphash *state) {
|
||||
siphash24_compress(p, sizeof(uint64_t), state);
|
||||
siphash24_compress_typesafe(*p, state);
|
||||
}
|
||||
|
||||
int uint64_compare_func(const uint64_t *a, const uint64_t *b) {
|
||||
@@ -104,7 +104,7 @@ DEFINE_HASH_OPS(uint64_hash_ops, uint64_t, uint64_hash_func, uint64_compare_func
|
||||
|
||||
#if SIZEOF_DEV_T != 8
|
||||
void devt_hash_func(const dev_t *p, struct siphash *state) {
|
||||
siphash24_compress(p, sizeof(dev_t), state);
|
||||
siphash24_compress_typesafe(*p, state);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -922,12 +922,19 @@ int in_addr_prefix_from_string_auto_internal(
|
||||
|
||||
}
|
||||
|
||||
void in_addr_hash_func(const union in_addr_union *u, int family, struct siphash *state) {
|
||||
assert(u);
|
||||
assert(state);
|
||||
|
||||
siphash24_compress(u->bytes, FAMILY_ADDRESS_SIZE(family), state);
|
||||
}
|
||||
|
||||
void in_addr_data_hash_func(const struct in_addr_data *a, struct siphash *state) {
|
||||
assert(a);
|
||||
assert(state);
|
||||
|
||||
siphash24_compress(&a->family, sizeof(a->family), state);
|
||||
siphash24_compress(&a->address, FAMILY_ADDRESS_SIZE(a->family), state);
|
||||
siphash24_compress_typesafe(a->family, state);
|
||||
in_addr_hash_func(&a->address, a->family, state);
|
||||
}
|
||||
|
||||
int in_addr_data_compare_func(const struct in_addr_data *x, const struct in_addr_data *y) {
|
||||
@@ -960,7 +967,7 @@ void in6_addr_hash_func(const struct in6_addr *addr, struct siphash *state) {
|
||||
assert(addr);
|
||||
assert(state);
|
||||
|
||||
siphash24_compress(addr, sizeof(*addr), state);
|
||||
siphash24_compress_typesafe(*addr, state);
|
||||
}
|
||||
|
||||
int in6_addr_compare_func(const struct in6_addr *a, const struct in6_addr *b) {
|
||||
|
||||
@@ -185,6 +185,7 @@ static inline size_t FAMILY_ADDRESS_SIZE(int family) {
|
||||
* See also oss-fuzz#11344. */
|
||||
#define IN_ADDR_NULL ((union in_addr_union) { .in6 = {} })
|
||||
|
||||
void in_addr_hash_func(const union in_addr_union *u, int family, struct siphash *state);
|
||||
void in_addr_data_hash_func(const struct in_addr_data *a, struct siphash *state);
|
||||
int in_addr_data_compare_func(const struct in_addr_data *x, const struct in_addr_data *y);
|
||||
void in6_addr_hash_func(const struct in6_addr *addr, struct siphash *state);
|
||||
|
||||
+1
-1
@@ -303,7 +303,7 @@ bool pidref_is_self(const PidRef *pidref) {
|
||||
}
|
||||
|
||||
static void pidref_hash_func(const PidRef *pidref, struct siphash *state) {
|
||||
siphash24_compress(&pidref->pid, sizeof(pidref->pid), state);
|
||||
siphash24_compress_typesafe(pidref->pid, state);
|
||||
}
|
||||
|
||||
static int pidref_compare_func(const PidRef *a, const PidRef *b) {
|
||||
|
||||
@@ -22,15 +22,16 @@ struct siphash {
|
||||
void siphash24_init(struct siphash *state, const uint8_t k[static 16]);
|
||||
void siphash24_compress(const void *in, size_t inlen, struct siphash *state);
|
||||
#define siphash24_compress_byte(byte, state) siphash24_compress((const uint8_t[]) { (byte) }, 1, (state))
|
||||
#define siphash24_compress_typesafe(in, state) \
|
||||
siphash24_compress(&(in), sizeof(typeof(in)), (state))
|
||||
|
||||
static inline void siphash24_compress_boolean(bool in, struct siphash *state) {
|
||||
uint8_t i = in;
|
||||
siphash24_compress(&i, sizeof i, state);
|
||||
siphash24_compress_byte(in, state);
|
||||
}
|
||||
|
||||
static inline void siphash24_compress_usec_t(usec_t in, struct siphash *state) {
|
||||
uint64_t u = htole64(in);
|
||||
siphash24_compress(&u, sizeof u, state);
|
||||
siphash24_compress_typesafe(u, state);
|
||||
}
|
||||
|
||||
static inline void siphash24_compress_safe(const void *in, size_t inlen, struct siphash *state) {
|
||||
|
||||
@@ -476,8 +476,8 @@ int xstatfsat(int dir_fd, const char *path, struct statfs *ret) {
|
||||
}
|
||||
|
||||
void inode_hash_func(const struct stat *q, struct siphash *state) {
|
||||
siphash24_compress(&q->st_dev, sizeof(q->st_dev), state);
|
||||
siphash24_compress(&q->st_ino, sizeof(q->st_ino), state);
|
||||
siphash24_compress_typesafe(q->st_dev, state);
|
||||
siphash24_compress_typesafe(q->st_ino, state);
|
||||
}
|
||||
|
||||
int inode_compare_func(const struct stat *a, const struct stat *b) {
|
||||
|
||||
Reference in New Issue
Block a user