From de7b7ddffa99aebdc482175f833ea982b4631bad Mon Sep 17 00:00:00 2001 From: Tommaso Gagliardoni Date: Tue, 21 Oct 2025 18:21:36 +0200 Subject: [PATCH] chore: Re-add Argon2id test (non-interactive) --- .../test/crypto/test_argon2id.c | 27 ++++++++++++++----- .../test/crypto/test_argon2id.h | 10 +++++++ shufflecake-userland/test/main.c | 2 +- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/shufflecake-userland/test/crypto/test_argon2id.c b/shufflecake-userland/test/crypto/test_argon2id.c index 7e1180d..a9cf27f 100644 --- a/shufflecake-userland/test/crypto/test_argon2id.c +++ b/shufflecake-userland/test/crypto/test_argon2id.c @@ -39,7 +39,7 @@ * CONSTANT VARIABLES * *****************************************************/ -char SALT[SFLC_ARGON_SALTLEN+1] = "Poor Petrol Pump"; +char SALT[SFLC_ARGON_SALTLEN+1] = ARGON2ID_SALT; /***************************************************** @@ -48,29 +48,39 @@ char SALT[SFLC_ARGON_SALTLEN+1] = "Poor Petrol Pump"; char *test_argon2id() { - char pwd[SFLC_BIGBUFSIZE]; + char pwd[] = ARGON2ID_PWD; char key[SFLC_STANDARD_KEYLEN]; + char keytest[] = ARGON2ID_KEY; int err; - sflc_log_blue("Testing Argon2id interactively with a fixed salt"); + sflc_log_blue("Testing Argon2id"); + // Hash + err = sflc_argon2id_derive(pwd, strlen(pwd), SALT, key); + mu_assert("Could not hash password", !err); + + // Verify match + mu_assert("Key derivation mismatch", memcmp(key, keytest, SFLC_STANDARD_KEYLEN) == 0); + + +/* // Loop until user breaks out while (true) { - /* Collect password */ + // Collect password printf("Choose password to hash (empty to skip): "); err = sflc_safeReadLine(pwd, SFLC_BIGBUFSIZE); mu_assert("Could not read password", !err); - /* Check if empty */ + // Check if empty if (strlen(pwd) == 0) { break; } - /* Hash it */ + // Hash it err = sflc_argon2id_derive(pwd, strlen(pwd), SALT, key); mu_assert("Could not hash password", !err); - /* Print it */ + // Print it printf("Salt used ASCII: \"%s\". Hex:\n", SALT); sflc_log_hex(SALT, SFLC_ARGON_SALTLEN); printf("Argon2id hash (m = %d, t = %d, p = %d):\n", @@ -78,6 +88,9 @@ char *test_argon2id() sflc_log_hex(key, SFLC_STANDARD_KEYLEN); printf("Go check the result online\n\n"); } +*/ + sflc_log_green("OK"); return NULL; + } diff --git a/shufflecake-userland/test/crypto/test_argon2id.h b/shufflecake-userland/test/crypto/test_argon2id.h index 12bd2c0..aba9a07 100644 --- a/shufflecake-userland/test/crypto/test_argon2id.h +++ b/shufflecake-userland/test/crypto/test_argon2id.h @@ -30,6 +30,16 @@ * CONSTANTS * *****************************************************/ +#define ARGON2ID_PWD "password" +#define ARGON2ID_SALT "Poor Petrol Pump" +#define ARGON2ID_KEY \ +{ \ + 0x58, 0x25, 0x37, 0x46, 0xe2, 0x11, 0x06, 0x47, \ + 0x4e, 0xf0, 0x31, 0xdc, 0x90, 0xb3, 0x63, 0xe4, \ + 0x21, 0x10, 0x0b, 0x36, 0xfa, 0xb9, 0x7b, 0x1b, \ + 0x87, 0x0a, 0xcb, 0x18, 0x61, 0x44, 0xe9, 0xe3 \ +} + /***************************************************** * PUBLIC FUNCTIONS DECLARATIONS * diff --git a/shufflecake-userland/test/main.c b/shufflecake-userland/test/main.c index b696c75..a8eb16b 100644 --- a/shufflecake-userland/test/main.c +++ b/shufflecake-userland/test/main.c @@ -73,7 +73,7 @@ static char *all_tests() mu_run_test(test_aes256gcm_encrypt); mu_run_test(test_aes256gcm_decrypt_good); mu_run_test(test_aes256gcm_decrypt_fail); - //mu_run_test(test_argon2id); // TODO: change it to static, rather than interactive test + mu_run_test(test_argon2id); return 0; }