mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Use a guard page instead of NULL for opt arguments in tests
This commit is contained in:
@@ -3179,7 +3179,7 @@ tv(void)
|
||||
printf("Message length should have been set to zero after a failure\n");
|
||||
}
|
||||
if (crypto_aead_aes256gcm_decrypt(decrypted, &found_message_len,
|
||||
NULL, NULL,
|
||||
NULL, guard_page,
|
||||
randombytes_uniform(crypto_aead_aes256gcm_ABYTES),
|
||||
ad, ad_len, nonce, key) != -1) {
|
||||
printf("Verification of test vector #%u with a truncated tag failed\n",
|
||||
|
||||
@@ -115,7 +115,7 @@ tv(void)
|
||||
}
|
||||
m2len = 1;
|
||||
if (crypto_aead_chacha20poly1305_decrypt(
|
||||
m2, &m2len, NULL, NULL,
|
||||
m2, &m2len, NULL, guard_page,
|
||||
randombytes_uniform(crypto_aead_chacha20poly1305_ABYTES),
|
||||
NULL, 0U, nonce, firstkey) != -1) {
|
||||
printf("crypto_aead_chacha20poly1305_decrypt() worked with a short "
|
||||
@@ -296,7 +296,7 @@ tv_ietf(void)
|
||||
}
|
||||
m2len = 1;
|
||||
if (crypto_aead_chacha20poly1305_ietf_decrypt(
|
||||
m2, &m2len, NULL, NULL,
|
||||
m2, &m2len, NULL, guard_page,
|
||||
randombytes_uniform(crypto_aead_chacha20poly1305_ietf_ABYTES),
|
||||
NULL, 0U, nonce, firstkey) != -1) {
|
||||
printf("crypto_aead_chacha20poly1305_ietf_decrypt() worked with a short "
|
||||
|
||||
@@ -118,7 +118,7 @@ tv(void)
|
||||
}
|
||||
m2len = 1;
|
||||
if (crypto_aead_xchacha20poly1305_ietf_decrypt(
|
||||
m2, &m2len, NULL, NULL,
|
||||
m2, &m2len, NULL, guard_page,
|
||||
randombytes_uniform(crypto_aead_xchacha20poly1305_ietf_ABYTES),
|
||||
NULL, 0U, nonce, firstkey) != -1) {
|
||||
printf("crypto_aead_xchacha20poly1305_ietf_decrypt() worked with a short "
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ main(void)
|
||||
|
||||
memset(a2, 0, sizeof a2);
|
||||
crypto_auth_hmacsha256_init(&st256, key2, sizeof key2);
|
||||
crypto_auth_hmacsha256_update(&st256, NULL, 0U);
|
||||
crypto_auth_hmacsha256_update(&st256, guard_page, 0U);
|
||||
crypto_auth_hmacsha256_update(&st256, c, 1U);
|
||||
crypto_auth_hmacsha256_update(&st256, c, sizeof c - 2U);
|
||||
crypto_auth_hmacsha256_final(&st256, a2);
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
|
||||
int xmain(void);
|
||||
|
||||
static void *guard_page;
|
||||
|
||||
#ifdef BENCHMARKS
|
||||
|
||||
# include <sys/time.h>
|
||||
@@ -166,6 +168,7 @@ static FILE *fp_res;
|
||||
int main(void)
|
||||
{
|
||||
FILE *fp_out;
|
||||
void *_guard_page;
|
||||
int c;
|
||||
|
||||
if ((fp_res = fopen(TEST_NAME_RES, "w+")) == NULL) {
|
||||
@@ -175,6 +178,11 @@ int main(void)
|
||||
if (sodium_init() != 0) {
|
||||
return 99;
|
||||
}
|
||||
if ((_guard_page = sodium_malloc(0)) == NULL) {
|
||||
perror("sodium_malloc()");
|
||||
return 99;
|
||||
}
|
||||
guard_page = (void *) (((unsigned char *) _guard_page) + 1);
|
||||
if (xmain() != 0) {
|
||||
return 99;
|
||||
}
|
||||
@@ -188,6 +196,7 @@ int main(void)
|
||||
return 99;
|
||||
}
|
||||
} while (c != EOF);
|
||||
sodium_free(_guard_page);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+10
-10
@@ -93,7 +93,7 @@ main(void)
|
||||
sodium_bin2base64(buf3, 33U, (const unsigned char *) "\xfb\xf0\xf1" "0123456789ABCDEFabc",
|
||||
22U, sodium_base64_VARIANT_URLSAFE_NO_PADDING));
|
||||
printf("%s\n",
|
||||
sodium_bin2base64(buf3, 1U, NULL,
|
||||
sodium_bin2base64(buf3, 1U, guard_page,
|
||||
0U, sodium_base64_VARIANT_ORIGINAL));
|
||||
printf("%s\n",
|
||||
sodium_bin2base64(buf3, 5U, (const unsigned char *) "a",
|
||||
@@ -105,7 +105,7 @@ main(void)
|
||||
sodium_bin2base64(buf3, 5U, (const unsigned char *) "abc",
|
||||
3U, sodium_base64_VARIANT_ORIGINAL));
|
||||
printf("%s\n",
|
||||
sodium_bin2base64(buf3, 1U, NULL,
|
||||
sodium_bin2base64(buf3, 1U, guard_page,
|
||||
0U, sodium_base64_VARIANT_ORIGINAL_NO_PADDING));
|
||||
printf("%s\n",
|
||||
sodium_bin2base64(buf3, 3U, (const unsigned char *) "a",
|
||||
@@ -161,21 +161,21 @@ main(void)
|
||||
assert(sodium_base642bin(buf1, sizeof buf1, b64, strlen(b64), " \r\n", NULL,
|
||||
NULL, sodium_base64_VARIANT_URLSAFE_NO_PADDING) == -1);
|
||||
|
||||
assert(sodium_base642bin(NULL, (size_t) 10U, "a=", (size_t) 2U, NULL, NULL, NULL,
|
||||
assert(sodium_base642bin(guard_page, (size_t) 10U, "a=", (size_t) 2U, NULL, NULL, NULL,
|
||||
sodium_base64_VARIANT_URLSAFE) == -1);
|
||||
assert(sodium_base642bin(NULL, (size_t) 10U, "a*", (size_t) 2U, NULL, NULL, NULL,
|
||||
assert(sodium_base642bin(guard_page, (size_t) 10U, "a*", (size_t) 2U, NULL, NULL, NULL,
|
||||
sodium_base64_VARIANT_URLSAFE) == -1);
|
||||
assert(sodium_base642bin(NULL, (size_t) 10U, "a*", (size_t) 2U, "~", NULL, NULL,
|
||||
assert(sodium_base642bin(guard_page, (size_t) 10U, "a*", (size_t) 2U, "~", NULL, NULL,
|
||||
sodium_base64_VARIANT_URLSAFE) == -1);
|
||||
assert(sodium_base642bin(NULL, (size_t) 10U, "a*", (size_t) 2U, "*", NULL, NULL,
|
||||
assert(sodium_base642bin(guard_page, (size_t) 10U, "a*", (size_t) 2U, "*", NULL, NULL,
|
||||
sodium_base64_VARIANT_URLSAFE) == -1);
|
||||
assert(sodium_base642bin(NULL, (size_t) 10U, "a==", (size_t) 3U, NULL, NULL, NULL,
|
||||
assert(sodium_base642bin(guard_page, (size_t) 10U, "a==", (size_t) 3U, NULL, NULL, NULL,
|
||||
sodium_base64_VARIANT_URLSAFE) == -1);
|
||||
assert(sodium_base642bin(NULL, (size_t) 10U, "a=*", (size_t) 3U, NULL, NULL, NULL,
|
||||
assert(sodium_base642bin(guard_page, (size_t) 10U, "a=*", (size_t) 3U, NULL, NULL, NULL,
|
||||
sodium_base64_VARIANT_URLSAFE) == -1);
|
||||
assert(sodium_base642bin(NULL, (size_t) 10U, "a=*", (size_t) 3U, "~", NULL, NULL,
|
||||
assert(sodium_base642bin(guard_page, (size_t) 10U, "a=*", (size_t) 3U, "~", NULL, NULL,
|
||||
sodium_base64_VARIANT_URLSAFE) == -1);
|
||||
assert(sodium_base642bin(NULL, (size_t) 10U, "a=*", (size_t) 3U, "*", NULL, NULL,
|
||||
assert(sodium_base642bin(guard_page, (size_t) 10U, "a=*", (size_t) 3U, "*", NULL, NULL,
|
||||
sodium_base64_VARIANT_URLSAFE) == -1);
|
||||
|
||||
assert(sodium_base642bin(buf1, sizeof buf1, "O1R", (size_t) 3U, NULL, NULL, NULL,
|
||||
|
||||
@@ -1367,13 +1367,13 @@ main(void)
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
assert(crypto_generichash(NULL, 0,
|
||||
assert(crypto_generichash(guard_page, 0,
|
||||
in, (unsigned long long) sizeof in,
|
||||
k, sizeof k) == -1);
|
||||
assert(crypto_generichash(NULL, crypto_generichash_BYTES_MAX + 1,
|
||||
assert(crypto_generichash(guard_page, crypto_generichash_BYTES_MAX + 1,
|
||||
in, (unsigned long long) sizeof in,
|
||||
k, sizeof k) == -1);
|
||||
assert(crypto_generichash(NULL, (unsigned long long) sizeof in,
|
||||
assert(crypto_generichash(guard_page, (unsigned long long) sizeof in,
|
||||
in, (unsigned long long) sizeof in,
|
||||
k, crypto_generichash_KEYBYTES_MAX + 1) == -1);
|
||||
|
||||
|
||||
@@ -131,15 +131,15 @@ main(void)
|
||||
printf("\n");
|
||||
|
||||
assert(crypto_generichash_blake2b_salt_personal
|
||||
(NULL, 0,
|
||||
(guard_page, 0,
|
||||
in, (unsigned long long) sizeof in,
|
||||
k, sizeof k, NULL, NULL) == -1);
|
||||
assert(crypto_generichash_blake2b_salt_personal
|
||||
(NULL, crypto_generichash_BYTES_MAX + 1,
|
||||
(guard_page, crypto_generichash_BYTES_MAX + 1,
|
||||
in, (unsigned long long) sizeof in,
|
||||
k, sizeof k, NULL, NULL) == -1);
|
||||
assert(crypto_generichash_blake2b_salt_personal
|
||||
(NULL, (unsigned long long) sizeof in,
|
||||
(guard_page, (unsigned long long) sizeof in,
|
||||
in, (unsigned long long) sizeof in,
|
||||
k, crypto_generichash_KEYBYTES_MAX + 1, NULL, NULL) == -1);
|
||||
|
||||
|
||||
+22
-22
@@ -19,8 +19,8 @@ sigabrt_handler_14(int sig)
|
||||
(void) sig;
|
||||
signal(SIGABRT, sigabrt_handler_15);
|
||||
assert(crypto_box_curve25519xchacha20poly1305_easy
|
||||
(NULL, NULL, crypto_stream_xchacha20_MESSAGEBYTES_MAX - 1,
|
||||
NULL, NULL, NULL) == -1);
|
||||
(guard_page, guard_page, crypto_stream_xchacha20_MESSAGEBYTES_MAX - 1,
|
||||
guard_page, guard_page, guard_page) == -1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ sigabrt_handler_13(int sig)
|
||||
(void) sig;
|
||||
signal(SIGABRT, sigabrt_handler_14);
|
||||
assert(crypto_box_curve25519xchacha20poly1305_easy_afternm
|
||||
(NULL, NULL, crypto_stream_xchacha20_MESSAGEBYTES_MAX - 1,
|
||||
NULL, NULL) == -1);
|
||||
(guard_page, guard_page, crypto_stream_xchacha20_MESSAGEBYTES_MAX - 1,
|
||||
guard_page, guard_page) == -1);
|
||||
exit(1);
|
||||
}
|
||||
# endif
|
||||
@@ -45,7 +45,7 @@ sigabrt_handler_12(int sig)
|
||||
# else
|
||||
signal(SIGABRT, sigabrt_handler_13);
|
||||
# endif
|
||||
assert(crypto_pwhash_str_alg(NULL, "", 0U, 1U, 1U, -1) == -1);
|
||||
assert(crypto_pwhash_str_alg(guard_page, "", 0U, 1U, 1U, -1) == -1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ sigabrt_handler_11(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
signal(SIGABRT, sigabrt_handler_12);
|
||||
assert(crypto_box_easy(NULL, NULL, crypto_stream_xsalsa20_MESSAGEBYTES_MAX,
|
||||
NULL, NULL, NULL) == -1);
|
||||
assert(crypto_box_easy(guard_page, guard_page, crypto_stream_xsalsa20_MESSAGEBYTES_MAX,
|
||||
guard_page, guard_page, guard_page) == -1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -64,8 +64,8 @@ sigabrt_handler_10(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
signal(SIGABRT, sigabrt_handler_11);
|
||||
assert(crypto_box_easy_afternm(NULL, NULL, crypto_stream_xsalsa20_MESSAGEBYTES_MAX,
|
||||
NULL, NULL) == -1);
|
||||
assert(crypto_box_easy_afternm(guard_page, guard_page, crypto_stream_xsalsa20_MESSAGEBYTES_MAX,
|
||||
guard_page, guard_page) == -1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ sigabrt_handler_9(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
signal(SIGABRT, sigabrt_handler_10);
|
||||
assert(sodium_base642bin(NULL, 1, NULL, 1, NULL, NULL, NULL, -1) == -1);
|
||||
assert(sodium_base642bin(guard_page, 1, guard_page, 1, NULL, NULL, NULL, -1) == -1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ sigabrt_handler_8(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
signal(SIGABRT, sigabrt_handler_9);
|
||||
assert(sodium_bin2base64(NULL, 1, NULL, 1, sodium_base64_VARIANT_ORIGINAL) == NULL);
|
||||
assert(sodium_bin2base64(guard_page, 1, guard_page, 1, sodium_base64_VARIANT_ORIGINAL) == NULL);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ sigabrt_handler_7(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
signal(SIGABRT, sigabrt_handler_8);
|
||||
assert(sodium_bin2base64(NULL, 1, NULL, 1, -1) == NULL);
|
||||
assert(sodium_bin2base64(guard_page, 1, guard_page, 1, -1) == NULL);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ sigabrt_handler_6(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
signal(SIGABRT, sigabrt_handler_7);
|
||||
assert(sodium_pad(NULL, NULL, SIZE_MAX, 16, 1) == -1);
|
||||
assert(sodium_pad(NULL, guard_page, SIZE_MAX, 16, 1) == -1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -110,8 +110,8 @@ sigabrt_handler_5(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
signal(SIGABRT, sigabrt_handler_6);
|
||||
assert(crypto_aead_xchacha20poly1305_ietf_encrypt(NULL, NULL, NULL, UINT64_MAX,
|
||||
NULL, 0, NULL, NULL, NULL) == -1);
|
||||
assert(crypto_aead_xchacha20poly1305_ietf_encrypt(guard_page, NULL, NULL, UINT64_MAX,
|
||||
NULL, 0, NULL, guard_page, NULL) == -1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -120,8 +120,8 @@ sigabrt_handler_4(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
signal(SIGABRT, sigabrt_handler_5);
|
||||
assert(crypto_aead_chacha20poly1305_ietf_encrypt(NULL, NULL, NULL, UINT64_MAX,
|
||||
NULL, 0, NULL, NULL, NULL) == -1);
|
||||
assert(crypto_aead_chacha20poly1305_ietf_encrypt(guard_page, NULL, NULL, UINT64_MAX,
|
||||
NULL, 0, NULL, guard_page, NULL) == -1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -130,8 +130,8 @@ sigabrt_handler_3(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
signal(SIGABRT, sigabrt_handler_4);
|
||||
assert(crypto_aead_chacha20poly1305_encrypt(NULL, NULL, NULL, UINT64_MAX,
|
||||
NULL, 0, NULL, NULL, NULL) == -1);
|
||||
assert(crypto_aead_chacha20poly1305_encrypt(guard_page, NULL, NULL, UINT64_MAX,
|
||||
NULL, 0, NULL, guard_page, NULL) == -1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ sigabrt_handler_2(int sig)
|
||||
(void) sig;
|
||||
signal(SIGABRT, sigabrt_handler_3);
|
||||
#if SIZE_MAX > 0x4000000000ULL
|
||||
randombytes_buf_deterministic(NULL, 0x4000000001ULL, NULL);
|
||||
randombytes_buf_deterministic(guard_page, 0x4000000001ULL, guard_page);
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
@@ -153,7 +153,7 @@ sigabrt_handler_1(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
signal(SIGABRT, sigabrt_handler_2);
|
||||
assert(crypto_kx_server_session_keys(NULL, NULL, NULL, NULL, NULL) == -1);
|
||||
assert(crypto_kx_server_session_keys(NULL, NULL, guard_page, guard_page, guard_page) == -1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ int
|
||||
main(void)
|
||||
{
|
||||
signal(SIGABRT, sigabrt_handler_1);
|
||||
assert(crypto_kx_client_session_keys(NULL, NULL, NULL, NULL, NULL) == -1);
|
||||
assert(crypto_kx_client_session_keys(NULL, NULL, guard_page, guard_page, guard_page) == -1);
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -480,19 +480,19 @@ main(void)
|
||||
assert(crypto_pwhash_alg_argon2id13() != crypto_pwhash_alg_argon2i13());
|
||||
assert(crypto_pwhash_alg_argon2id13() == crypto_pwhash_alg_default());
|
||||
|
||||
assert(crypto_pwhash_argon2id(NULL, 0, NULL, 0, NULL,
|
||||
assert(crypto_pwhash_argon2id(guard_page, 0, guard_page, 0, guard_page,
|
||||
crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE,
|
||||
crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE,
|
||||
0) == -1);
|
||||
assert(crypto_pwhash_argon2id(NULL, 0, NULL, 0, NULL,
|
||||
assert(crypto_pwhash_argon2id(guard_page, 0, guard_page, 0, guard_page,
|
||||
crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE,
|
||||
crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE,
|
||||
crypto_pwhash_ALG_ARGON2I13) == -1);
|
||||
assert(crypto_pwhash_argon2i(NULL, 0, NULL, 0, NULL,
|
||||
assert(crypto_pwhash_argon2i(guard_page, 0, guard_page, 0, guard_page,
|
||||
crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE,
|
||||
crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE,
|
||||
0) == -1);
|
||||
assert(crypto_pwhash_argon2i(NULL, 0, NULL, 0, NULL,
|
||||
assert(crypto_pwhash_argon2i(guard_page, 0, guard_page, 0, guard_page,
|
||||
crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE,
|
||||
crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE,
|
||||
crypto_pwhash_ALG_ARGON2ID13) == -1);
|
||||
|
||||
Reference in New Issue
Block a user