Skip to content

Commit

Permalink
lib: Silently truncate rbytes after a maximum of 512 bits for yescrypt.
Browse files Browse the repository at this point in the history
Likewise for gost-yescrypt and scrypt, as those hashing methods share
the same codebase.
  • Loading branch information
besser82 committed Nov 30, 2021
1 parent c50b731 commit a74a677
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/crypt-gost-yescrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ gensalt_gost_yescrypt_rn (unsigned long count,
const uint8_t *rbytes, size_t nrbytes,
uint8_t *output, size_t o_size)
{
/* Up to 512 bits (64 bytes) of entropy for computing the salt portion
of the MCF-setting are supported. */
nrbytes = (nrbytes > 64 ? 64 : nrbytes);

if (o_size < 4 + 8 * 6 + BASE64_LEN (nrbytes) + 1 ||
CRYPT_GENSALT_OUTPUT_SIZE < 4 + 8 * 6 + BASE64_LEN (nrbytes) + 1)
{
Expand Down
4 changes: 4 additions & 0 deletions lib/crypt-scrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ gensalt_scrypt_rn (unsigned long count,
const uint8_t *rbytes, size_t nrbytes,
uint8_t *output, size_t o_size)
{
/* Up to 512 bits (64 bytes) of entropy for computing the salt portion
of the MCF-setting are supported. */
nrbytes = (nrbytes > 64 ? 64 : nrbytes);

if (o_size < 3 + 1 + 5 * 2 + BASE64_LEN (nrbytes) + 1 ||
CRYPT_GENSALT_OUTPUT_SIZE < 3 + 1 + 5 * 2 + BASE64_LEN (nrbytes) + 1)
{
Expand Down
4 changes: 4 additions & 0 deletions lib/crypt-yescrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ gensalt_yescrypt_rn (unsigned long count,
const uint8_t *rbytes, size_t nrbytes,
uint8_t *output, size_t o_size)
{
/* Up to 512 bits (64 bytes) of entropy for computing the salt portion
of the MCF-setting are supported. */
nrbytes = (nrbytes > 64 ? 64 : nrbytes);

if (o_size < 3 + 8 * 6 + 1 + BASE64_LEN (nrbytes) + 1 ||
CRYPT_GENSALT_OUTPUT_SIZE < 3 + 8 * 6 + 1 + BASE64_LEN (nrbytes) + 1)
{
Expand Down

0 comments on commit a74a677

Please sign in to comment.