chore: Re-add Argon2id test (non-interactive)

This commit is contained in:
Tommaso Gagliardoni 2025-10-21 18:21:36 +02:00
parent 05a7ecc557
commit de7b7ddffa
3 changed files with 31 additions and 8 deletions

View file

@ -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;
}

View file

@ -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 *

View file

@ -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;
}