Old Compiler Warning Cleanup (GCC 4.0.2)

pwdbased.c: Simplified some arithmetic to fix a variable promotion
warning.
This commit is contained in:
John Safranek 2022-01-14 17:36:12 -08:00
parent 2cf21a3f69
commit 5ddf4392df
No known key found for this signature in database
GPG Key ID: 8CE817DE0D3CCB4A

View File

@ -568,8 +568,6 @@ int wc_PKCS12_PBKDF_ex(byte* output, const byte* passwd, int passLen,
/* (2^32 - 1) */
#define SCRYPT_WORD32_MAX 4294967295U
/* (2^32 - 1) * 32, used in a couple of scrypt max calculations. */
#define SCRYPT_MAX 137438953440UL
/* One round of Salsa20/8.
* Code taken from RFC 7914: scrypt PBKDF.
@ -760,7 +758,13 @@ int wc_scrypt(byte* output, const byte* passwd, int passLen,
if (cost < 1 || cost >= 128 * blockSize / 8 || parallel < 1 || dkLen < 1)
return BAD_FUNC_ARG;
if ((word32)parallel > (SCRYPT_MAX / (128 * blockSize)))
/* The following comparison used to be:
* ((word32)parallel > (SCRYPT_MAX / (128 * blockSize)))
* where SCRYPT_MAX is (2^32 - 1) * 32. For some compilers, the RHS of
* the comparison is greater than parallel's type. It wouldn't promote
* both sides to word64. What follows is just arithmetic simplification.
*/
if ((word32)parallel > (SCRYPT_WORD32_MAX / (4 * blockSize)))
return BAD_FUNC_ARG;
bSz = 128 * blockSize;