From: Alan T. DeKok Date: Fri, 17 Mar 2023 13:15:00 +0000 (-0400) Subject: just use fr_hash(), instead of hand-rolled hash from 2002. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8aa26de57ffe4c1c48f873047ccb685873654d6;p=thirdparty%2Ffreeradius-server.git just use fr_hash(), instead of hand-rolled hash from 2002. --- diff --git a/src/lib/util/misc.c b/src/lib/util/misc.c index ce9344ab5bc..48db1bd21fd 100644 --- a/src/lib/util/misc.c +++ b/src/lib/util/misc.c @@ -396,32 +396,6 @@ size_t fr_snprint_uint128(char *out, size_t outlen, uint128_t const num) return strlcpy(out, p, outlen); } -/** Multiply with modulo wrap - * - * Avoids multiplication overflow. - * - * @param[in] lhs First operand. - * @param[in] rhs Second operand. - * @param[in] mod Modulo. - * @return - * - Result. - */ -uint64_t fr_multiply_mod(uint64_t lhs, uint64_t rhs, uint64_t mod) -{ - uint64_t res = 0; - - lhs %= mod; - - while (rhs > 0) { - if (rhs & 0x01) res = (res + lhs) % mod; - - lhs = (lhs * 2) % mod; - rhs /= 2; - } - - return res % mod; -} - /** Compares two pointers * * @param a first pointer to compare. diff --git a/src/lib/util/misc.h b/src/lib/util/misc.h index 97c3844c630..ccafef1880c 100644 --- a/src/lib/util/misc.h +++ b/src/lib/util/misc.h @@ -167,8 +167,6 @@ int fr_blocking(int fd); ssize_t fr_utf8_to_ucs2(uint8_t *out, size_t outlen, char const *in, size_t inlen); size_t fr_snprint_uint128(char *out, size_t outlen, uint128_t const num); -uint64_t fr_multiply_mod(uint64_t lhs, uint64_t rhs, uint64_t mod); - int8_t fr_pointer_cmp(void const *a, void const *b); void fr_quick_sort(void const *to_sort[], int min_idx, int max_idx, fr_cmp_t cmp); int fr_digest_cmp(uint8_t const *a, uint8_t const *b, size_t length) CC_HINT(nonnull); diff --git a/src/modules/rlm_passwd/rlm_passwd.c b/src/modules/rlm_passwd/rlm_passwd.c index df4d9839a20..bfd8f9096df 100644 --- a/src/modules/rlm_passwd/rlm_passwd.c +++ b/src/modules/rlm_passwd/rlm_passwd.c @@ -131,11 +131,9 @@ static void destroy_password (struct mypasswd * pass) static unsigned int hash(char const * username, unsigned int tablesize) { - uint64_t h = 1; + uint32_t h = fr_hash_string(username); - while (*username) h = fr_multiply_mod(h, (7907 + *username++), tablesize); - - return (unsigned int)h; + return h % tablesize; } static void release_hash_table(struct hashtable * ht){