diff options
author | Tomas Mraz <tomas@openssl.org> | 2022-01-25 17:14:52 +0100 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2022-01-27 10:36:57 +0100 |
commit | 2ce0a3d19005271e7e3c351b562d9da93e2d4c80 (patch) | |
tree | 2727324e0278a111d02561924e54500eeac08ea8 | |
parent | Fix IV length of DES EDE ECB implementations (diff) | |
download | openssl-2ce0a3d19005271e7e3c351b562d9da93e2d4c80.tar.xz openssl-2ce0a3d19005271e7e3c351b562d9da93e2d4c80.zip |
lhash: Avoid 32 bit right shift of a 32 bit value
Fixes #17583
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17589)
-rw-r--r-- | crypto/lhash/lhash.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/crypto/lhash/lhash.c b/crypto/lhash/lhash.c index 62e2be4c18..b99b63fd6a 100644 --- a/crypto/lhash/lhash.c +++ b/crypto/lhash/lhash.c @@ -383,7 +383,8 @@ unsigned long OPENSSL_LH_strhash(const char *c) v = n | (*c); n += 0x100; r = (int)((v >> 2) ^ v) & 0x0f; - ret = (ret << r) | (ret >> (32 - r)); + /* cast to uint64_t to avoid 32 bit shift of 32 bit value */ + ret = (ret << r) | (unsigned long)((uint64_t)ret >> (32 - r)); ret &= 0xFFFFFFFFL; ret ^= v * v; c++; @@ -404,7 +405,8 @@ unsigned long ossl_lh_strcasehash(const char *c) for (n = 0x100; *c != '\0'; n += 0x100) { v = n | ossl_tolower(*c); r = (int)((v >> 2) ^ v) & 0x0f; - ret = (ret << r) | (ret >> (32 - r)); + /* cast to uint64_t to avoid 32 bit shift of 32 bit value */ + ret = (ret << r) | (unsigned long)((uint64_t)ret >> (32 - r)); ret &= 0xFFFFFFFFL; ret ^= v * v; c++; |