From 4f62600e21e55ef98d9b46c6e951a1cffe0b05bd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 3 Nov 2023 11:23:11 +0100 Subject: [PATCH] all: use NM_HASH_SEED_16() macro --- src/core/devices/wifi/nm-device-wifi.c | 35 ++++++------- src/core/nm-core-utils.c | 34 ++++++------- src/core/nm-l3-ipv4ll.c | 68 +++++++++++++------------- 3 files changed, 69 insertions(+), 68 deletions(-) diff --git a/src/core/devices/wifi/nm-device-wifi.c b/src/core/devices/wifi/nm-device-wifi.c index 437728345..2cd41b27f 100644 --- a/src/core/devices/wifi/nm-device-wifi.c +++ b/src/core/devices/wifi/nm-device-wifi.c @@ -3191,27 +3191,28 @@ ensure_hotspot_frequency(NMDeviceWifi *self, NMSettingWireless *s_wifi, NMWifiAP GBytes *ssid; gsize ssid_len; const guint8 *ssid_data; - const guint8 random_seed[16] = {0x9a, - 0xdc, - 0x86, - 0x9a, - 0xa8, - 0xa2, - 0x07, - 0x97, - 0xbe, - 0x6d, - 0xe6, - 0x99, - 0x9f, - 0xa8, - 0x09, - 0x2b}; /* Calculate a stable "random" number based on the SSID. */ ssid = nm_setting_wireless_get_ssid(s_wifi); ssid_data = g_bytes_get_data(ssid, &ssid_len); - rnd = c_siphash_hash(random_seed, ssid_data, ssid_len); + rnd = c_siphash_hash(NM_HASH_SEED_16(0x9a, + 0xdc, + 0x86, + 0x9a, + 0xa8, + 0xa2, + 0x07, + 0x97, + 0xbe, + 0x6d, + 0xe6, + 0x99, + 0x9f, + 0xa8, + 0x09, + 0x2b), + ssid_data, + ssid_len); } if (nm_streq0(band, "a")) { diff --git a/src/core/nm-core-utils.c b/src/core/nm-core-utils.c index b12ca1b5e..a6c20ad85 100644 --- a/src/core/nm-core-utils.c +++ b/src/core/nm-core-utils.c @@ -3819,23 +3819,23 @@ nm_utils_dhcp_client_id_mac(int arp_type, const guint8 *hwaddr, gsize hwaddr_len return g_bytes_new_take(client_id_buf, hwaddr_len + 1); } -#define HASH_KEY \ - ((const guint8[16]){0x80, \ - 0x11, \ - 0x8c, \ - 0xc2, \ - 0xfe, \ - 0x4a, \ - 0x03, \ - 0xee, \ - 0x3e, \ - 0xd6, \ - 0x0c, \ - 0x6f, \ - 0x36, \ - 0x39, \ - 0x14, \ - 0x09}) +#define HASH_KEY \ + NM_HASH_SEED_16(0x80, \ + 0x11, \ + 0x8c, \ + 0xc2, \ + 0xfe, \ + 0x4a, \ + 0x03, \ + 0xee, \ + 0x3e, \ + 0xd6, \ + 0x0c, \ + 0x6f, \ + 0x36, \ + 0x39, \ + 0x14, \ + 0x09) /** * nm_utils_create_dhcp_iaid: diff --git a/src/core/nm-l3-ipv4ll.c b/src/core/nm-l3-ipv4ll.c index ec871befc..551a90fe3 100644 --- a/src/core/nm-l3-ipv4ll.c +++ b/src/core/nm-l3-ipv4ll.c @@ -390,23 +390,23 @@ _ipv4ll_addrgen(NML3IPv4LL *self, gboolean generate_new_addr) _ASSERT(self); /* MAC_HASH_KEY is the same as used by systemd. */ -#define MAC_HASH_KEY \ - ((const guint8[16]){0xdf, \ - 0x04, \ - 0x22, \ - 0x98, \ - 0x3f, \ - 0xad, \ - 0x14, \ - 0x52, \ - 0xf9, \ - 0x87, \ - 0x2e, \ - 0xd1, \ - 0x9c, \ - 0x70, \ - 0xe2, \ - 0xf2}) +#define MAC_HASH_KEY \ + NM_HASH_SEED_16(0xdf, \ + 0x04, \ + 0x22, \ + 0x98, \ + 0x3f, \ + 0xad, \ + 0x14, \ + 0x52, \ + 0xf9, \ + 0x87, \ + 0x2e, \ + 0xd1, \ + 0x9c, \ + 0x70, \ + 0xe2, \ + 0xf2) if (self->mac_set && (!self->seed_set || !nm_ether_addr_equal(&self->mac, &self->seed_mac))) { /* systemd's ipv4ll library by default only hashes the MAC address (as we do here). @@ -465,23 +465,23 @@ _ipv4ll_addrgen(NML3IPv4LL *self, gboolean generate_new_addr) gen_addr: -#define PICK_HASH_KEY \ - ((const guint8[16]){0x15, \ - 0xac, \ - 0x82, \ - 0xa6, \ - 0xd6, \ - 0x3f, \ - 0x49, \ - 0x78, \ - 0x98, \ - 0x77, \ - 0x5d, \ - 0x0c, \ - 0x69, \ - 0x02, \ - 0x94, \ - 0x0b}) +#define PICK_HASH_KEY \ + NM_HASH_SEED_16(0x15, \ + 0xac, \ + 0x82, \ + 0xa6, \ + 0xd6, \ + 0x3f, \ + 0x49, \ + 0x78, \ + 0x98, \ + 0x77, \ + 0x5d, \ + 0x0c, \ + 0x69, \ + 0x02, \ + 0x94, \ + 0x0b) h = c_siphash_hash(PICK_HASH_KEY, (const guint8 *) &self->seed, sizeof(self->seed));