mirror of
https://codeberg.org/shufflecake/shufflecake-c.git
synced 2026-01-09 20:41:04 -05:00
Merge pull request 'fix: Fix make test not compiling' (#106) from fix/tests into dev
Reviewed-on: https://codeberg.org/shufflecake/shufflecake-c/pulls/106
This commit is contained in:
commit
6bbfb82814
4 changed files with 35 additions and 35 deletions
|
|
@ -56,10 +56,10 @@ char *test_aes256ctr_encrypt_inplace()
|
|||
char iv[] = AES256CTR_TEST_IV;
|
||||
int err;
|
||||
|
||||
sflite_log_blue("Testing AES256-CTR encryption in-place");
|
||||
sflc_log_blue("Testing AES256-CTR encryption in-place");
|
||||
|
||||
// Encrypt in-place
|
||||
err = sflite_aes256ctr_encrypt(key, msg, msg_len, iv, NULL);
|
||||
err = sflc_aes256ctr_encrypt(key, msg, msg_len, iv, NULL);
|
||||
|
||||
// Check error
|
||||
mu_assert("Error while encrypting", !err);
|
||||
|
|
@ -73,7 +73,7 @@ char *test_aes256ctr_encrypt_inplace()
|
|||
// Check IV untouched
|
||||
mu_assert("IV changed", memcmp(iv, IV, sizeof(iv)) == 0);
|
||||
|
||||
sflite_log_green("OK");
|
||||
sflc_log_green("OK");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -87,10 +87,10 @@ char *test_aes256ctr_encrypt_outofplace()
|
|||
char iv[] = AES256CTR_TEST_IV;
|
||||
int err;
|
||||
|
||||
sflite_log_blue("Testing AES256-CTR encryption out-of-place");
|
||||
sflc_log_blue("Testing AES256-CTR encryption out-of-place");
|
||||
|
||||
// Encrypt out-of-place
|
||||
err = sflite_aes256ctr_encrypt(key, msg, msg_len, iv, ct);
|
||||
err = sflc_aes256ctr_encrypt(key, msg, msg_len, iv, ct);
|
||||
|
||||
// Check error
|
||||
mu_assert("Error while encrypting", !err);
|
||||
|
|
@ -107,7 +107,7 @@ char *test_aes256ctr_encrypt_outofplace()
|
|||
// Check IV untouched
|
||||
mu_assert("IV changed", memcmp(iv, IV, sizeof(iv)) == 0);
|
||||
|
||||
sflite_log_green("OK");
|
||||
sflc_log_green("OK");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -120,10 +120,10 @@ char *test_aes256ctr_decrypt_inplace()
|
|||
char iv[] = AES256CTR_TEST_IV;
|
||||
int err;
|
||||
|
||||
sflite_log_blue("Testing AES256-CTR decryption in-place");
|
||||
sflc_log_blue("Testing AES256-CTR decryption in-place");
|
||||
|
||||
// Decrypt in-place
|
||||
err = sflite_aes256ctr_decrypt(key, msg, msg_len, iv, NULL);
|
||||
err = sflc_aes256ctr_decrypt(key, msg, msg_len, iv, NULL);
|
||||
|
||||
// Check error
|
||||
mu_assert("Error while decrypting", !err);
|
||||
|
|
@ -137,7 +137,7 @@ char *test_aes256ctr_decrypt_inplace()
|
|||
// Check IV untouched
|
||||
mu_assert("IV changed", memcmp(iv, IV, sizeof(iv)) == 0);
|
||||
|
||||
sflite_log_green("OK");
|
||||
sflc_log_green("OK");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -151,10 +151,10 @@ char *test_aes256ctr_decrypt_outofplace()
|
|||
char iv[] = AES256CTR_TEST_IV;
|
||||
int err;
|
||||
|
||||
sflite_log_blue("Testing AES256-CTR decryption out-of-place");
|
||||
sflc_log_blue("Testing AES256-CTR decryption out-of-place");
|
||||
|
||||
// Decrypt out-of-place
|
||||
err = sflite_aes256ctr_decrypt(key, msg, msg_len, iv, pt);
|
||||
err = sflc_aes256ctr_decrypt(key, msg, msg_len, iv, pt);
|
||||
|
||||
// Check error
|
||||
mu_assert("Error while decrypting", !err);
|
||||
|
|
@ -171,7 +171,7 @@ char *test_aes256ctr_decrypt_outofplace()
|
|||
// Check IV untouched
|
||||
mu_assert("IV changed", memcmp(iv, IV, sizeof(iv)) == 0);
|
||||
|
||||
sflite_log_green("OK");
|
||||
sflc_log_green("OK");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,20 +56,20 @@ char *test_aes256gcm_encrypt()
|
|||
char key[] = AES256GCM_TEST_KEY;
|
||||
char iv[] = AES256GCM_TEST_IV;
|
||||
char ct[sizeof(pt)];
|
||||
char tag[SFLITE_AESGCM_TAGLEN];
|
||||
char tag[SFLC_AESGCM_TAGLEN];
|
||||
int err;
|
||||
|
||||
sflite_log_blue("Testing AES256-GCM encryption");
|
||||
sflc_log_blue("Testing AES256-GCM encryption");
|
||||
|
||||
// Encrypt
|
||||
err = sflite_aes256gcm_encrypt(key, pt, pt_len, iv, ct, tag);
|
||||
err = sflc_aes256gcm_encrypt(key, pt, pt_len, iv, ct, tag);
|
||||
|
||||
// Check error
|
||||
mu_assert("Error while encrypting", !err);
|
||||
|
||||
// Check outcome
|
||||
mu_assert("Ciphertext mismatch", memcmp(ct, CT, pt_len) == 0);
|
||||
mu_assert("MAC mismatch", memcmp(tag, TAG, SFLITE_AESGCM_TAGLEN) == 0);
|
||||
mu_assert("MAC mismatch", memcmp(tag, TAG, SFLC_AESGCM_TAGLEN) == 0);
|
||||
|
||||
// Check key untouched
|
||||
mu_assert("Key changed", memcmp(key, KEY, sizeof(key)) == 0);
|
||||
|
|
@ -77,7 +77,7 @@ char *test_aes256gcm_encrypt()
|
|||
// Check IV untouched
|
||||
mu_assert("IV changed", memcmp(iv, IV, sizeof(iv)) == 0);
|
||||
|
||||
sflite_log_green("OK");
|
||||
sflc_log_green("OK");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -93,10 +93,10 @@ char *test_aes256gcm_decrypt_good()
|
|||
char pt[sizeof(ct)];
|
||||
int err;
|
||||
|
||||
sflite_log_blue("Testing AES256-GCM decryption with the proper MAC");
|
||||
sflc_log_blue("Testing AES256-GCM decryption with the proper MAC");
|
||||
|
||||
// Decrypt
|
||||
err = sflite_aes256gcm_decrypt(key, ct, ct_len, tag, iv, pt, &match);
|
||||
err = sflc_aes256gcm_decrypt(key, ct, ct_len, tag, iv, pt, &match);
|
||||
|
||||
// Check error
|
||||
mu_assert("Error while decrypting", !err);
|
||||
|
|
@ -114,7 +114,7 @@ char *test_aes256gcm_decrypt_good()
|
|||
// Check MAC untouched
|
||||
mu_assert("MAC changed", memcmp(tag, TAG, sizeof(tag)) == 0);
|
||||
|
||||
sflite_log_green("OK");
|
||||
sflc_log_green("OK");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -130,13 +130,13 @@ char *test_aes256gcm_decrypt_fail()
|
|||
char pt[sizeof(ct)];
|
||||
int err;
|
||||
|
||||
sflite_log_blue("Testing AES256-GCM decryption without the proper MAC");
|
||||
sflc_log_blue("Testing AES256-GCM decryption without the proper MAC");
|
||||
|
||||
// Corrupt the MAC
|
||||
tag[0] += 1;
|
||||
|
||||
// Decrypt
|
||||
err = sflite_aes256gcm_decrypt(key, ct, ct_len, tag, iv, pt, &match);
|
||||
err = sflc_aes256gcm_decrypt(key, ct, ct_len, tag, iv, pt, &match);
|
||||
|
||||
// Check error
|
||||
mu_assert("Error while decrypting", !err);
|
||||
|
|
@ -154,7 +154,7 @@ char *test_aes256gcm_decrypt_fail()
|
|||
mu_assert("Tail of MAC changed", memcmp(tag+1, TAG+1, sizeof(tag)-1) == 0);
|
||||
mu_assert("Head of MAC changed", tag[0] == TAG[0]+1);
|
||||
|
||||
sflite_log_green("OK");
|
||||
sflc_log_green("OK");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
* CONSTANT VARIABLES *
|
||||
*****************************************************/
|
||||
|
||||
char SALT[SFLITE_ARGON_SALTLEN+1] = "Poor Petrol Pump";
|
||||
char SALT[SFLC_ARGON_SALTLEN+1] = "Poor Petrol Pump";
|
||||
|
||||
|
||||
/*****************************************************
|
||||
|
|
@ -48,17 +48,17 @@ char SALT[SFLITE_ARGON_SALTLEN+1] = "Poor Petrol Pump";
|
|||
|
||||
char *test_argon2id()
|
||||
{
|
||||
char pwd[SFLITE_BIGBUFSIZE];
|
||||
char key[SFLITE_STANDARD_KEYLEN];
|
||||
char pwd[SFLC_BIGBUFSIZE];
|
||||
char key[SFLC_STANDARD_KEYLEN];
|
||||
int err;
|
||||
|
||||
sflite_log_blue("Testing Argon2id interactively with a fixed salt");
|
||||
sflc_log_blue("Testing Argon2id interactively with a fixed salt");
|
||||
|
||||
// Loop until user breaks out
|
||||
while (true) {
|
||||
/* Collect password */
|
||||
printf("Choose password to hash (empty to skip): ");
|
||||
err = sflite_safeReadLine(pwd, SFLITE_BIGBUFSIZE);
|
||||
err = sflc_safeReadLine(pwd, SFLC_BIGBUFSIZE);
|
||||
mu_assert("Could not read password", !err);
|
||||
|
||||
/* Check if empty */
|
||||
|
|
@ -67,15 +67,15 @@ char *test_argon2id()
|
|||
}
|
||||
|
||||
/* Hash it */
|
||||
err = sflite_argon2id_derive(pwd, strlen(pwd), SALT, key);
|
||||
err = sflc_argon2id_derive(pwd, strlen(pwd), SALT, key);
|
||||
mu_assert("Could not hash password", !err);
|
||||
|
||||
/* Print it */
|
||||
printf("Salt used ASCII: \"%s\". Hex:\n", SALT);
|
||||
sflite_log_hex(SALT, SFLITE_ARGON_SALTLEN);
|
||||
sflc_log_hex(SALT, SFLC_ARGON_SALTLEN);
|
||||
printf("Argon2id hash (m = %d, t = %d, p = %d):\n",
|
||||
SFLITE_ARGON_M, SFLITE_ARGON_T, SFLITE_ARGON_P);
|
||||
sflite_log_hex(key, SFLITE_STANDARD_KEYLEN);
|
||||
SFLC_ARGON_M, SFLC_ARGON_T, SFLC_ARGON_P);
|
||||
sflc_log_hex(key, SFLC_STANDARD_KEYLEN);
|
||||
printf("Go check the result online\n\n");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,10 +49,10 @@ int main()
|
|||
char *result = all_tests();
|
||||
|
||||
if (result != NULL) {
|
||||
sflite_log_red("\nTEST FAILED: %s", result);
|
||||
sflc_log_red("\nTEST FAILED: %s", result);
|
||||
}
|
||||
else {
|
||||
sflite_log_green("\nALL TESTS PASSED");
|
||||
sflc_log_green("\nALL TESTS PASSED");
|
||||
}
|
||||
|
||||
return result != NULL;
|
||||
|
|
@ -65,7 +65,7 @@ int main()
|
|||
|
||||
static char *all_tests()
|
||||
{
|
||||
sflite_log_yellow("Running crypto tests");
|
||||
sflc_log_yellow("Running crypto tests");
|
||||
mu_run_test(test_aes256ctr_encrypt_inplace);
|
||||
mu_run_test(test_aes256ctr_encrypt_outofplace);
|
||||
mu_run_test(test_aes256ctr_decrypt_inplace);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue