From 3785fc5cd505a040e411326cf939eb236faffada Mon Sep 17 00:00:00 2001 From: Jan Varho Date: Thu, 8 May 2014 12:48:56 +0300 Subject: [PATCH] Check r and p against zero before dividing --- .../nosse/pwhash_scryptxsalsa208sha256.c | 4 ++++ .../scryptxsalsa208sha256/sse/pwhash_scryptxsalsa208sha256.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/nosse/pwhash_scryptxsalsa208sha256.c b/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/nosse/pwhash_scryptxsalsa208sha256.c index a79f9a78..a9ab966e 100644 --- a/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/nosse/pwhash_scryptxsalsa208sha256.c +++ b/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/nosse/pwhash_scryptxsalsa208sha256.c @@ -248,6 +248,10 @@ escrypt_kdf_nosse(escrypt_local_t * local, errno = EINVAL; return -1; } + if (r == 0 || p == 0) { + errno = EINVAL; + return -1; + } if ((r > SIZE_MAX / 128 / p) || #if SIZE_MAX / 256 <= UINT32_MAX (r > SIZE_MAX / 256) || diff --git a/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/sse/pwhash_scryptxsalsa208sha256.c b/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/sse/pwhash_scryptxsalsa208sha256.c index 3b9d9462..b734acf1 100644 --- a/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/sse/pwhash_scryptxsalsa208sha256.c +++ b/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/sse/pwhash_scryptxsalsa208sha256.c @@ -334,6 +334,10 @@ escrypt_kdf_sse(escrypt_local_t * local, errno = EINVAL; return -1; } + if (r == 0 || p == 0) { + errno = EINVAL; + return -1; + } if ((r > SIZE_MAX / 128 / p) || #if SIZE_MAX / 256 <= UINT32_MAX (r > SIZE_MAX / 256) ||