This reverts commit
cc9c56894606fdf324933cd8090d9a54d967bf5b for the file
pbe_scrypt.c instead of scrypt.c
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4357)
unsigned char *B;
uint32_t *X, *V, *T;
uint64_t i, Blen, Vlen;
unsigned char *B;
uint32_t *X, *V, *T;
uint64_t i, Blen, Vlen;
/* Sanity check parameters */
/* initial check, r,p must be non zero, N >= 2 and a power of 2 */
/* Sanity check parameters */
/* initial check, r,p must be non zero, N >= 2 and a power of 2 */
- * Check 32 * r * (N + 2) * sizeof(uint32_t) fits in
- * uint64_t and also size_t (their sizes are unrelated).
+ * Check 32 * r * (N + 2) * sizeof(uint32_t) fits in uint64_t
* This is combined size V, X and T (section 4)
*/
i = UINT64_MAX / (32 * sizeof(uint32_t));
* This is combined size V, X and T (section 4)
*/
i = UINT64_MAX / (32 * sizeof(uint32_t));
/* check total allocated size fits in uint64_t */
if (Blen > UINT64_MAX - Vlen)
return 0;
/* check total allocated size fits in uint64_t */
if (Blen > UINT64_MAX - Vlen)
return 0;
- /* check total allocated size fits in size_t */
- if (Blen > SIZE_MAX - Vlen)
- return 0;
-
- allocsize = (size_t)(Blen + Vlen);
if (maxmem == 0)
maxmem = SCRYPT_MAX_MEM;
if (maxmem == 0)
maxmem = SCRYPT_MAX_MEM;
- if (allocsize > maxmem) {
+ if (Blen + Vlen > maxmem) {
EVPerr(EVP_F_EVP_PBE_SCRYPT, EVP_R_MEMORY_LIMIT_EXCEEDED);
return 0;
}
EVPerr(EVP_F_EVP_PBE_SCRYPT, EVP_R_MEMORY_LIMIT_EXCEEDED);
return 0;
}
if (key == NULL)
return 1;
if (key == NULL)
return 1;
- B = OPENSSL_malloc(allocsize);
+ B = OPENSSL_malloc(Blen + Vlen);
if (B == NULL)
return 0;
X = (uint32_t *)(B + Blen);
if (B == NULL)
return 0;
X = (uint32_t *)(B + Blen);
- OPENSSL_clear_free(B, allocsize);
+ OPENSSL_clear_free(B, Blen + Vlen);