summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2022-06-07 15:47:45 +0900
committerNIIBE Yutaka <gniibe@fsij.org>2022-06-07 15:47:45 +0900
commitf8c983cb14f8ba0921ce8fa52ea3519feae07861 (patch)
treeaae802b65f58f0c64d49241ddde74fb32bce82f8 /tests
parent8d8e80ad753645b5fcbe28bb3e768079415ef848 (diff)
downloadlibgcrypt-f8c983cb14f8ba0921ce8fa52ea3519feae07861.tar.gz
kdf: Add One-Step KDF with hash.
* src/gcrypt.h.in (GCRY_KDF_ONESTEP_KDF): New. * cipher/kdf.c (onestep_kdf_open, onestep_kdf_compute): New. (onestep_kdf_final): New. (_gcry_kdf_open, _gcry_kdf_compute, _gcry_kdf_final): Add GCRY_KDF_ONESTEP_KDF support. * tests/t-kdf.c (check_onestep_kdf): Add the test. (main): Call check_onestep_kdf. -- GnuPG-bug-id: 5964 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/t-kdf.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/t-kdf.c b/tests/t-kdf.c
index 234bbac6..49116d20 100644
--- a/tests/t-kdf.c
+++ b/tests/t-kdf.c
@@ -1603,6 +1603,84 @@ check_balloon (void)
}
+static void
+check_onestep_kdf (void)
+{
+ gcry_error_t err;
+ const unsigned long param[2] = { 38, 68 };
+ unsigned char out[68];
+ unsigned char input[2][16] = {
+ {
+ 0x3f, 0x89, 0x2b, 0xd8, 0xb8, 0x4d, 0xae, 0x64,
+ 0xa7, 0x82, 0xa3, 0x5f, 0x6e, 0xaa, 0x8f, 0x00
+ },
+ {
+ 0xe6, 0x5b, 0x19, 0x05, 0x87, 0x8b, 0x95, 0xf6,
+ 0x8b, 0x55, 0x35, 0xbd, 0x3b, 0x2b, 0x10, 0x13
+ }
+ };
+ unsigned char other[2][12] = {
+ {
+ 0xec, 0x3f, 0x1c, 0xd8, 0x73, 0xd2, 0x88, 0x58,
+ 0xa5, 0x8c, 0xc3, 0x9e
+ },
+ {
+ 0x83, 0x02, 0x21, 0xb1, 0x73, 0x0d, 0x91, 0x76,
+ 0xf8, 0x07, 0xd4, 0x07
+ }
+ };
+ unsigned char expected[2][68] = {
+ {
+ 0xa7, 0xc0, 0x66, 0x52, 0x98, 0x25, 0x25, 0x31,
+ 0xe0, 0xdb, 0x37, 0x73, 0x7a, 0x37, 0x46, 0x51,
+ 0xb3, 0x68, 0x27, 0x5f, 0x20, 0x48, 0x28, 0x4d,
+ 0x16, 0xa1, 0x66, 0xc6, 0xd8, 0xa9, 0x0a, 0x91,
+ 0xa4, 0x91, 0xc1, 0x6f, 0x49, 0x64
+ },
+ {
+ 0xb8, 0xc4, 0x4b, 0xdf, 0x0b, 0x85, 0xa6, 0x4b,
+ 0x6a, 0x51, 0xc1, 0x2a, 0x06, 0x71, 0x0e, 0x37,
+ 0x3d, 0x82, 0x9b, 0xb1, 0xfd, 0xa5, 0xb4, 0xe1,
+ 0xa2, 0x07, 0x95, 0xc6, 0x19, 0x95, 0x94, 0xf6,
+ 0xfa, 0x65, 0x19, 0x8a, 0x72, 0x12, 0x57, 0xf7,
+ 0xd5, 0x8c, 0xb2, 0xf6, 0xf6, 0xdb, 0x9b, 0xb5,
+ 0x69, 0x9f, 0x73, 0x86, 0x30, 0x45, 0x90, 0x90,
+ 0x54, 0xb2, 0x38, 0x9e, 0x06, 0xec, 0x00, 0xfe,
+ 0x31, 0x8c, 0xab, 0xd9
+ },
+ };
+ int i;
+ int hashalgo[2] = { GCRY_MD_SHA256, GCRY_MD_SHA512 };
+ int count = 0;
+
+ again:
+
+ if (verbose)
+ fprintf (stderr, "checking OneStepKDF test vector %d\n", count);
+
+ err = my_kdf_derive (0,
+ GCRY_KDF_ONESTEP_KDF, hashalgo[count], &param[count], 1,
+ input[count], 16, NULL, 0, NULL, 0,
+ other[count], 12,
+ param[count], out);
+ if (err)
+ fail ("OneStepKDF test %d failed: %s\n", count, gpg_strerror (err));
+ else if (memcmp (out, expected[count], param[count]))
+ {
+ fail ("OneStepKDF test %d failed: mismatch\n", count*2+0);
+ fputs ("got:", stderr);
+ for (i=0; i < param[count]; i++)
+ fprintf (stderr, " %02x", out[i]);
+ putc ('\n', stderr);
+ }
+
+ /* Next test vector */
+ count++;
+ if (count < 2)
+ goto again;
+}
+
+
int
main (int argc, char **argv)
{
@@ -1681,6 +1759,7 @@ main (int argc, char **argv)
check_scrypt ();
check_argon2 ();
check_balloon ();
+ check_onestep_kdf ();
}
return error_count ? 1 : 0;