From a93cb141a03f447b91dcb9a865d1e616098aaae7 Mon Sep 17 00:00:00 2001 From: Anshu Chimala Date: Sat, 30 May 2026 00:32:58 -0700 Subject: [PATCH] Reject N less than two in reference scrypt crypto_scrypt() accepts powers of two for N, but N == 1 leaves smix() without a meaningful iteration count. Treat N values below 2 as invalid and keep the implementation comments in sync. --- lib/crypto/crypto_scrypt-ref.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/crypto/crypto_scrypt-ref.c b/lib/crypto/crypto_scrypt-ref.c index a249f90a..0d56c505 100644 --- a/lib/crypto/crypto_scrypt-ref.c +++ b/lib/crypto/crypto_scrypt-ref.c @@ -165,7 +165,8 @@ integerify(uint8_t * B, size_t r) * smix(B, r, N, V, XY): * Compute B = SMix_r(B, N). The input B must be 128r bytes in length; the * temporary storage V must be 128rN bytes in length; the temporary storage - * XY must be 256r bytes in length. The value N must be a power of 2. + * XY must be 256r bytes in length. The value N must be a power of 2 greater + * than 1. */ static void smix(uint8_t * B, size_t r, uint64_t N, uint8_t * V, uint8_t * XY) @@ -206,7 +207,7 @@ smix(uint8_t * B, size_t r, uint64_t N, uint8_t * V, uint8_t * XY) * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r, * p, buflen) and write the result into buf. The parameters r, p, and buflen * must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N - * must be a power of 2. + * must be a power of 2 greater than 1. * * Return 0 on success; or -1 on error. */ @@ -232,7 +233,7 @@ crypto_scrypt(const uint8_t * passwd, size_t passwdlen, errno = EFBIG; goto err0; } - if (((N & (N - 1)) != 0) || (N == 0)) { + if (((N & (N - 1)) != 0) || (N < 2)) { errno = EINVAL; goto err0; }