Skip to content

Commit a74a677

Browse files
committed
lib: Silently truncate rbytes after a maximum of 512 bits for yescrypt.
Likewise for gost-yescrypt and scrypt, as those hashing methods share the same codebase.
1 parent c50b731 commit a74a677

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

lib/crypt-gost-yescrypt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ gensalt_gost_yescrypt_rn (unsigned long count,
5858
const uint8_t *rbytes, size_t nrbytes,
5959
uint8_t *output, size_t o_size)
6060
{
61+
/* Up to 512 bits (64 bytes) of entropy for computing the salt portion
62+
of the MCF-setting are supported. */
63+
nrbytes = (nrbytes > 64 ? 64 : nrbytes);
64+
6165
if (o_size < 4 + 8 * 6 + BASE64_LEN (nrbytes) + 1 ||
6266
CRYPT_GENSALT_OUTPUT_SIZE < 4 + 8 * 6 + BASE64_LEN (nrbytes) + 1)
6367
{

lib/crypt-scrypt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ gensalt_scrypt_rn (unsigned long count,
165165
const uint8_t *rbytes, size_t nrbytes,
166166
uint8_t *output, size_t o_size)
167167
{
168+
/* Up to 512 bits (64 bytes) of entropy for computing the salt portion
169+
of the MCF-setting are supported. */
170+
nrbytes = (nrbytes > 64 ? 64 : nrbytes);
171+
168172
if (o_size < 3 + 1 + 5 * 2 + BASE64_LEN (nrbytes) + 1 ||
169173
CRYPT_GENSALT_OUTPUT_SIZE < 3 + 1 + 5 * 2 + BASE64_LEN (nrbytes) + 1)
170174
{

lib/crypt-yescrypt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ gensalt_yescrypt_rn (unsigned long count,
106106
const uint8_t *rbytes, size_t nrbytes,
107107
uint8_t *output, size_t o_size)
108108
{
109+
/* Up to 512 bits (64 bytes) of entropy for computing the salt portion
110+
of the MCF-setting are supported. */
111+
nrbytes = (nrbytes > 64 ? 64 : nrbytes);
112+
109113
if (o_size < 3 + 8 * 6 + 1 + BASE64_LEN (nrbytes) + 1 ||
110114
CRYPT_GENSALT_OUTPUT_SIZE < 3 + 8 * 6 + 1 + BASE64_LEN (nrbytes) + 1)
111115
{

0 commit comments

Comments
 (0)