From 3f3d350387058c77d8109189e8e8f0c1fb5f2c8c Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 5 Jun 2022 14:28:54 +0200 Subject: [PATCH] sodium_compare(): cast operands to unsigned int This matches the Zig implementation and fixes #1184 --- src/libsodium/sodium/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libsodium/sodium/utils.c b/src/libsodium/sodium/utils.c index e2886ada..82005cbf 100644 --- a/src/libsodium/sodium/utils.c +++ b/src/libsodium/sodium/utils.c @@ -242,8 +242,8 @@ sodium_compare(const unsigned char *b1_, const unsigned char *b2_, size_t len) i--; x1 = b1[i]; x2 = b2[i]; - gt |= ((x2 - x1) >> 8) & eq; - eq &= ((x2 ^ x1) - 1) >> 8; + gt |= (((unsigned int) x2 - (unsigned int) x1) >> 8) & eq; + eq &= (((unsigned int) (x2 ^ x1)) - 1) >> 8; } return (int) (gt + gt + eq) - 1; }