Argon2 incorrect result and division by zero
Guido Vranken
guidovranken at gmail.com
Mon Mar 28 22:47:20 CEST 2022
Fuzzer debug output for the reproducer (included at end of this message):
Module libgcrypt result:
{0x0f, 0xb5, 0x95, 0x20, 0xf8, 0x1a, 0x3f, 0xec, 0xac, 0xc0, 0xa4, 0x68,
0x78, 0x33, 0xf7, 0xce,
0xb0, 0xbd, 0x42, 0x95, 0xc2, 0x63, 0x45, 0x38, 0xc2, 0x06, 0x6e, 0x8c,
0x39, 0x2a, 0xb4, 0xd5,
0x84, 0x6b, 0x19, 0xf2, 0x5f, 0x00, 0x7b, 0xbf, 0x66, 0xfe, 0xc8, 0xd2,
0xe7, 0x98, 0x2d, 0xa7,
0x00, 0xdb, 0xf9, 0x43, 0x13, 0xd5, 0x5d, 0x19, 0xec, 0x0e, 0x5c, 0x69,
0x06, 0xd2, 0xb6, 0xd7,
0xcf, 0x72, 0xbb, 0x3b, 0xa7, 0x29} (70 bytes)
Module Botan result:
{0x0f, 0xb5, 0x95, 0x20, 0xf8, 0x1a, 0x3f, 0xec, 0xac, 0xc0, 0xa4, 0x68,
0x78, 0x33, 0xf7, 0xce,
0xb0, 0xbd, 0x42, 0x95, 0xc2, 0x63, 0x45, 0x38, 0xc2, 0x06, 0x6e, 0x8c,
0x39, 0x2a, 0xb4, 0xd5,
0xc1, 0x16, 0x48, 0x32, 0x7c, 0xed, 0xe1, 0x56, 0x90, 0xab, 0x49, 0x32,
0xd0, 0x51, 0x48, 0x55,
0x6d, 0x96, 0xcc, 0xd1, 0x33, 0xe2, 0xb2, 0x2b, 0x88, 0xf8, 0x35, 0x74,
0xf8, 0x90, 0x78, 0x27,
0x45, 0xa4, 0x37, 0x99, 0xc6, 0x86} (70 bytes)
It seems that the 64 bytes are always correct but with output sizes larger
than that, discrepancies occur.
Additionally there is a division by zero on this line in argon2_init() if
parallelism is set to 0:
segment_length = memory_blocks / (parallelism * 4);
it would be better to return an error in this case.
Reproducer:
#include <gcrypt.h>
#define CF_CHECK_EQ(expr, res) if ( (expr) != (res) ) { goto end; }
int main(void)
{
const unsigned char password[32] = {
0xa3, 0x18, 0xc3, 0x65, 0x45, 0xbb, 0x67, 0xb8, 0x26, 0xab, 0x1d,
0x8c, 0xa7, 0x0f, 0xc7, 0x8c,
0x33, 0x0d, 0x4c, 0x57, 0x2b, 0xcf, 0x95, 0x94, 0xfd, 0x75, 0x85,
0xf0, 0x08, 0x2a, 0x04, 0x05};
const unsigned char salt[32] = {
0xb4, 0x0f, 0xf9, 0x84, 0x68, 0x4e, 0x44, 0x0c, 0x86, 0x0b, 0xd1,
0x4b, 0x7c, 0x71, 0x85, 0xdb,
0xa7, 0x9b, 0x47, 0x6e, 0x76, 0xba, 0xf9, 0xa3, 0x47, 0xf0, 0x82,
0x20, 0x84, 0x60, 0xca, 0x8e};
gcry_kdf_hd_t hd;
unsigned char out[70];
const unsigned long params[4] = {sizeof(out), 1, 27701, 1};
CF_CHECK_EQ(gcry_kdf_open(&hd, GCRY_KDF_ARGON2, GCRY_KDF_ARGON2ID,
params, 4,
password, sizeof(password),
salt, sizeof(salt),
NULL, 0,
NULL, 0), GPG_ERR_NO_ERROR);
CF_CHECK_EQ(gcry_kdf_compute(hd, NULL), GPG_ERR_NO_ERROR);
CF_CHECK_EQ(gcry_kdf_final(hd, sizeof(out), out), GPG_ERR_NO_ERROR);
for (size_t i = 0; i < sizeof(out); i++) {
if ( !(i % 16) ) printf("\n");
printf("0x%02x, ", out[i]);
}
printf("\n");
end:
gcry_kdf_close(hd);
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gnupg.org/pipermail/gcrypt-devel/attachments/20220328/b66e6500/attachment.html>
More information about the Gcrypt-devel
mailing list