tests: Integrate Argon2 tests into functional_test
Refactor the Argon2 tests to enable the module build and integrate the tests into function_test. Signed-off-by: Gary Lin <glin@suse.com> Tested-By: Waldemar Brodkorb <wbx@openadk.org> Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
parent
6a525ee64f
commit
c1bd9fc829
@ -2265,6 +2265,11 @@ module = {
|
|||||||
common = tests/pbkdf2_test.c;
|
common = tests/pbkdf2_test.c;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module = {
|
||||||
|
name = argon2_test;
|
||||||
|
common = tests/argon2_test.c;
|
||||||
|
};
|
||||||
|
|
||||||
module = {
|
module = {
|
||||||
name = legacy_password_test;
|
name = legacy_password_test;
|
||||||
common = tests/legacy_password_test.c;
|
common = tests/legacy_password_test.c;
|
||||||
|
|||||||
@ -1,23 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* GRUB -- GRand Unified Bootloader
|
||||||
|
* Copyright (C) 2025 Free Software Foundation, Inc.
|
||||||
|
*
|
||||||
|
* GRUB is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* GRUB is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <grub/test.h>
|
||||||
|
#include <grub/dl.h>
|
||||||
|
#include <grub/misc.h>
|
||||||
|
#include <grub/crypto.h>
|
||||||
|
|
||||||
|
GRUB_MOD_LICENSE ("GPLv3+");
|
||||||
|
|
||||||
|
#define DIM(v) (sizeof(v)/sizeof((v)[0]))
|
||||||
|
|
||||||
static void
|
static void
|
||||||
check_argon2 (void)
|
argon2_test (void)
|
||||||
{
|
{
|
||||||
gcry_error_t err;
|
gcry_error_t err;
|
||||||
static struct {
|
static struct {
|
||||||
int subalgo;
|
int subalgo;
|
||||||
unsigned long param[4];
|
unsigned long param[4];
|
||||||
size_t passlen;
|
grub_size_t passlen;
|
||||||
const char *pass;
|
const char *pass;
|
||||||
size_t saltlen;
|
grub_size_t saltlen;
|
||||||
const char *salt;
|
const char *salt;
|
||||||
size_t keylen;
|
grub_size_t keylen;
|
||||||
const char *key;
|
const char *key;
|
||||||
size_t adlen;
|
grub_size_t adlen;
|
||||||
const char *ad;
|
const char *ad;
|
||||||
size_t dklen;
|
grub_size_t dklen;
|
||||||
const char *dk;
|
const char *dk;
|
||||||
} tv[] = {
|
} tv[] = {
|
||||||
{
|
{
|
||||||
GCRY_KDF_ARGON2D,
|
GRUB_GCRY_KDF_ARGON2D,
|
||||||
{ 32, 3, 32, 4 },
|
{ 32, 3, 32, 4 },
|
||||||
32,
|
32,
|
||||||
"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
|
"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
|
||||||
@ -33,7 +60,7 @@ check_argon2 (void)
|
|||||||
"\xf8\x68\xe3\xbe\x39\x84\xf3\xc1\xa1\x3a\x4d\xb9\xfa\xbe\x4a\xcb"
|
"\xf8\x68\xe3\xbe\x39\x84\xf3\xc1\xa1\x3a\x4d\xb9\xfa\xbe\x4a\xcb"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
GCRY_KDF_ARGON2I,
|
GRUB_GCRY_KDF_ARGON2I,
|
||||||
{ 32, 3, 32, 4 },
|
{ 32, 3, 32, 4 },
|
||||||
32,
|
32,
|
||||||
"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
|
"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
|
||||||
@ -49,7 +76,7 @@ check_argon2 (void)
|
|||||||
"\xc8\xde\x6b\x01\x6d\xd3\x88\xd2\x99\x52\xa4\xc4\x67\x2b\x6c\xe8"
|
"\xc8\xde\x6b\x01\x6d\xd3\x88\xd2\x99\x52\xa4\xc4\x67\x2b\x6c\xe8"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
GCRY_KDF_ARGON2ID,
|
GRUB_GCRY_KDF_ARGON2ID,
|
||||||
{ 32, 3, 32, 4 },
|
{ 32, 3, 32, 4 },
|
||||||
32,
|
32,
|
||||||
"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
|
"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
|
||||||
@ -66,7 +93,7 @@ check_argon2 (void)
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
/* empty password */
|
/* empty password */
|
||||||
GCRY_KDF_ARGON2I,
|
GRUB_GCRY_KDF_ARGON2I,
|
||||||
{ 32, 3, 128, 1 },
|
{ 32, 3, 128, 1 },
|
||||||
0, NULL,
|
0, NULL,
|
||||||
16,
|
16,
|
||||||
@ -79,7 +106,7 @@ check_argon2 (void)
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
/* empty password */
|
/* empty password */
|
||||||
GCRY_KDF_ARGON2ID,
|
GRUB_GCRY_KDF_ARGON2ID,
|
||||||
{ 32, 3, 128, 1 },
|
{ 32, 3, 128, 1 },
|
||||||
0, NULL,
|
0, NULL,
|
||||||
16,
|
16,
|
||||||
@ -92,50 +119,21 @@ check_argon2 (void)
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
unsigned char out[32];
|
unsigned char out[32];
|
||||||
int i;
|
unsigned int count;
|
||||||
int count;
|
|
||||||
|
|
||||||
for (count = 0; count < DIM(tv); count++)
|
for (count = 0; count < DIM(tv); count++)
|
||||||
{
|
{
|
||||||
if (verbose)
|
err = grub_crypto_argon2 (tv[count].subalgo,
|
||||||
fprintf (stderr, "checking ARGON2 test vector %d\n", count);
|
tv[count].param, 4,
|
||||||
|
tv[count].pass, tv[count].passlen,
|
||||||
err = my_kdf_derive (0, GCRY_KDF_ARGON2,
|
tv[count].salt, tv[count].saltlen,
|
||||||
tv[count].subalgo, tv[count].param, 4,
|
tv[count].key, tv[count].keylen,
|
||||||
tv[count].pass, tv[count].passlen,
|
tv[count].ad, tv[count].adlen,
|
||||||
tv[count].salt, tv[count].saltlen,
|
tv[count].dklen, out);
|
||||||
tv[count].key, tv[count].keylen,
|
grub_test_assert (err == 0, "argon2 test %d failed: %d", count, err);
|
||||||
tv[count].ad, tv[count].adlen,
|
grub_test_assert (grub_memcmp (out, tv[count].dk, tv[count].dklen) == 0,
|
||||||
tv[count].dklen, out);
|
"argon2 test %d failed: mismatch", count);
|
||||||
if (err)
|
|
||||||
fail ("argon2 test %d failed: %s\n", count*2+0, gpg_strerror (err));
|
|
||||||
else if (memcmp (out, tv[count].dk, tv[count].dklen))
|
|
||||||
{
|
|
||||||
fail ("argon2 test %d failed: mismatch\n", count*2+0);
|
|
||||||
fputs ("got:", stderr);
|
|
||||||
for (i=0; i < tv[count].dklen; i++)
|
|
||||||
fprintf (stderr, " %02x", out[i]);
|
|
||||||
putc ('\n', stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_PTHREAD
|
|
||||||
err = my_kdf_derive (1, GCRY_KDF_ARGON2,
|
|
||||||
tv[count].subalgo, tv[count].param, 4,
|
|
||||||
tv[count].pass, tv[count].passlen,
|
|
||||||
tv[count].salt, tv[count].saltlen,
|
|
||||||
tv[count].key, tv[count].keylen,
|
|
||||||
tv[count].ad, tv[count].adlen,
|
|
||||||
tv[count].dklen, out);
|
|
||||||
if (err)
|
|
||||||
fail ("argon2 test %d failed: %s\n", count*2+1, gpg_strerror (err));
|
|
||||||
else if (memcmp (out, tv[count].dk, tv[count].dklen))
|
|
||||||
{
|
|
||||||
fail ("argon2 test %d failed: mismatch\n", count*2+1);
|
|
||||||
fputs ("got:", stderr);
|
|
||||||
for (i=0; i < tv[count].dklen; i++)
|
|
||||||
fprintf (stderr, " %02x", out[i]);
|
|
||||||
putc ('\n', stderr);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GRUB_FUNCTIONAL_TEST (argon2_test, argon2_test);
|
||||||
|
|||||||
@ -81,6 +81,7 @@ grub_functional_all_tests (grub_extcmd_context_t ctxt __attribute__ ((unused)),
|
|||||||
grub_dl_load ("mul_test");
|
grub_dl_load ("mul_test");
|
||||||
grub_dl_load ("shift_test");
|
grub_dl_load ("shift_test");
|
||||||
grub_dl_load ("asn1_test");
|
grub_dl_load ("asn1_test");
|
||||||
|
grub_dl_load ("argon2_test");
|
||||||
|
|
||||||
FOR_LIST_ELEMENTS (test, grub_test_list)
|
FOR_LIST_ELEMENTS (test, grub_test_list)
|
||||||
ok = !grub_test_run (test) && ok;
|
ok = !grub_test_run (test) && ok;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user