diff --git a/AK/IPv4Address.h b/AK/IPv4Address.h index 3d0330604c5..2365b5c95d0 100644 --- a/AK/IPv4Address.h +++ b/AK/IPv4Address.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -162,7 +163,7 @@ static_assert(sizeof(IPv4Address) == 4); template<> struct Traits : public GenericTraits { - static constexpr unsigned hash(IPv4Address const& address) { return int_hash(address.to_u32()); } + static unsigned hash(IPv4Address const& address) { return secure_sip_hash(static_cast(address.to_u32())); } }; #ifdef KERNEL diff --git a/AK/IPv6Address.h b/AK/IPv6Address.h index 6bfd811a0e7..e9f36535094 100644 --- a/AK/IPv6Address.h +++ b/AK/IPv6Address.h @@ -270,18 +270,8 @@ static_assert(sizeof(IPv6Address) == 16); template<> struct Traits : public GenericTraits { - static constexpr unsigned hash(IPv6Address const& address) - { - unsigned h = 0; - for (int group = 0; group < 8; group += 2) { - u32 two_groups = ((u32)address[group] << 16) | (u32)address[group + 1]; - if (group == 0) - h = int_hash(two_groups); - else - h = pair_int_hash(h, two_groups); - } - return h; - } + // SipHash-4-8 is considered conservatively secure, even if not cryptographically secure. + static unsigned hash(IPv6Address const& address) { return sip_hash_bytes<4, 8>({ &address.to_in6_addr_t(), sizeof(address.to_in6_addr_t()) }); } }; #ifdef KERNEL