diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2022-01-26 20:25:10 +0900 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2022-01-26 20:25:10 +0900 |
commit | 026d798e8b41f6f3c955212641612a79f3347492 (patch) | |
tree | 802451e85d4e8ff1fc26ace3e172f3f22476b12e | |
parent | bb08ae763d249213b1f3a4a687c24aab9b7ec3c8 (diff) | |
download | libgcrypt-026d798e8b41f6f3c955212641612a79f3347492.tar.gz |
kdf: Change the test vector for the one of version 1.3.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
-rw-r--r-- | cipher/kdf.c | 30 | ||||
-rw-r--r-- | tests/t-kdf.c | 10 |
2 files changed, 26 insertions, 14 deletions
diff --git a/cipher/kdf.c b/cipher/kdf.c index 6852efe7..df043071 100644 --- a/cipher/kdf.c +++ b/cipher/kdf.c @@ -359,7 +359,7 @@ struct argon2_context { unsigned int t; gcry_md_hd_t hd; - unsigned char *block; + u64 *block; struct argon2_thread_data *thread_data; unsigned char out[1]; /* In future, we may use flexible array member. */ @@ -375,6 +375,17 @@ enum argon2_iterator_step { #define ARGON2_VERSION 0x13 +#define ARGON2_WORDS_IN_BLOCK (1024/8) + +static void +xor_block (u64 *dst, const u64 *src) +{ + int i; + + for (i = 0; i < ARGON2_WORDS_IN_BLOCK; i++) + dst[i] ^= src[i]; +} + static gpg_err_code_t hash (gcry_md_hd_t hd, const unsigned char *input, unsigned int inputlen, unsigned char *output, unsigned int outputlen) @@ -518,12 +529,13 @@ argon2_genh0_first_blocks (argon2_ctx_t a) /*FIXME*/ memset (h0_01_i+64, 0, 4); buf_put_le32 (h0_01_i+64+4, i); - ec = hash (a->hd, h0_01_i, 72, a->block+1024*i, 1024); + ec = hash (a->hd, h0_01_i, 72, (unsigned char *)a->block+1024*i, 1024); if (ec) break; buf_put_le32 (h0_01_i+64, 1); - ec = hash (a->hd, h0_01_i, 72, a->block+1024*(i+a->lanes), 1024); + ec = hash (a->hd, h0_01_i, 72, (unsigned char *)a->block+1024*(i+a->lanes), + 1024); if (ec) break; } @@ -741,17 +753,17 @@ argon2_final (argon2_ctx_t a, size_t resultlen, void *result) memset (a->block, 0, 1024); for (i = 0; i < a->lanes; i++) { - unsigned char *p0; - unsigned char *p1; /*FIXME*/ + u64 *p0; + u64 *p1; /*FIXME*/ p0 = a->block; - p1 = p0 + a->lane_length * i + (a->segment_length - 1)*1024; + p1 = p0 + (a->lane_length * i + (a->segment_length - 1)*1024)/8; - for (j = 0; j < 1024; j++) - p0[j] ^= p1[j]; + xor_block (p0, p1); } - ec = hash (a->hd, a->block, 1024, result, a->outlen); + ec = hash (a->hd, (unsigned char *)a->block, + 1024, result, a->outlen); return ec; } diff --git a/tests/t-kdf.c b/tests/t-kdf.c index 88205c26..3af9c621 100644 --- a/tests/t-kdf.c +++ b/tests/t-kdf.c @@ -1364,7 +1364,7 @@ static void check_argon2 (void) { gcry_error_t err; - const unsigned long param[5] = { 32, 3, 16, 4, 4 }; + const unsigned long param[5] = { 32, 3, 32, 4, 4 }; const unsigned char pass[32] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 @@ -1376,10 +1376,10 @@ check_argon2 (void) const unsigned char ad[12] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }; unsigned char out[32]; unsigned char expected[32] = { - 0xf8, 0x7c, 0x95, 0x96, 0xbd, 0xbf, 0x75, 0x0b, - 0xfb, 0x35, 0x3a, 0x89, 0x70, 0xe5, 0x44, 0x1a, - 0x70, 0x24, 0x3e, 0xb4, 0x90, 0x30, 0xdf, 0xe2, - 0x74, 0xd9, 0xad, 0x4e, 0x37, 0x0e, 0x38, 0x9b + 0x0d, 0x64, 0x0d, 0xf5, 0x8d, 0x78, 0x76, 0x6c, + 0x08, 0xc0, 0x37, 0xa3, 0x4a, 0x8b, 0x53, 0xc9, + 0xd0, 0x1e, 0xf0, 0x45, 0x2d, 0x75, 0xb6, 0x5e, + 0xb5, 0x25, 0x20, 0xe9, 0x6b, 0x01, 0xe6, 0x59 }; int i; |