diff --git a/test/default/auth.c b/test/default/auth.c index 1f4553ca..23ac9277 100644 --- a/test/default/auth.c +++ b/test/default/auth.c @@ -67,7 +67,7 @@ main(void) printf("\n"); } - // Empty message tests: HMAC-SHA512 + /* Empty message tests: HMAC-SHA512 */ memset(a2, 0, sizeof a2); crypto_auth_hmacsha512_init(&st, key, sizeof key); crypto_auth_hmacsha512_final(&st, a2); @@ -80,11 +80,11 @@ main(void) memset(a3, 0, sizeof a3); crypto_auth_hmacsha512_init(&st, key, sizeof key); - crypto_auth_hmacsha512_update(&st, NULL, 0U); + crypto_auth_hmacsha512_update(&st, guard_page, 0U); crypto_auth_hmacsha512_final(&st, a3); assert(sodium_memcmp(a2, a3, sizeof a2) == 0); - // Empty message tests: HMAC-SHA512-256 + /* Empty message tests: HMAC-SHA512-256 */ memset(a2, 0, sizeof a2); crypto_auth_hmacsha512256_init(&st512_256, key, sizeof key); crypto_auth_hmacsha512256_final(&st512_256, a2); @@ -97,12 +97,12 @@ main(void) memset(a3, 0, sizeof a3); crypto_auth_hmacsha512256_init(&st512_256, key, sizeof key); - crypto_auth_hmacsha512256_update(&st512_256, NULL, 0U); + crypto_auth_hmacsha512256_update(&st512_256, guard_page, 0U); crypto_auth_hmacsha512256_final(&st512_256, a3); assert(sodium_memcmp(a2, a3, sizeof a2) == 0); + /* Empty message tests: HMAC-SHA256 */ - // Empty message tests: HMAC-SHA256 memset(a2, 0, sizeof a2); crypto_auth_hmacsha256_init(&st256, key, sizeof key); crypto_auth_hmacsha256_final(&st256, a2); @@ -115,10 +115,12 @@ main(void) memset(a3, 0, sizeof a3); crypto_auth_hmacsha256_init(&st256, key, sizeof key); - crypto_auth_hmacsha256_update(&st256, NULL, 0U); + crypto_auth_hmacsha256_update(&st256, guard_page, 0U); crypto_auth_hmacsha256_final(&st256, a3); assert(sodium_memcmp(a2, a3, sizeof a2) == 0); + /* --- */ + assert(crypto_auth_bytes() > 0U); assert(crypto_auth_keybytes() > 0U); assert(strcmp(crypto_auth_primitive(), "hmacsha512256") == 0); diff --git a/test/default/auth3.c b/test/default/auth3.c index 786f6f2e..ca90aa7b 100644 --- a/test/default/auth3.c +++ b/test/default/auth3.c @@ -29,9 +29,8 @@ main(void) printf("%d\n", crypto_auth_hmacsha256_verify(a, c, sizeof c, key)); - // Test empty message with NULL pointer - crypto_auth_hmacsha256(a2, NULL, 0U, key); - assert(crypto_auth_hmacsha256_verify(a2, NULL, 0U, key) == 0); + crypto_auth_hmacsha256(a2, guard_page, 0U, key); + assert(crypto_auth_hmacsha256_verify(a2, guard_page, 0U, key) == 0); return 0; } diff --git a/test/default/auth5.c b/test/default/auth5.c index 5559ac51..955c9cfb 100644 --- a/test/default/auth5.c +++ b/test/default/auth5.c @@ -33,10 +33,9 @@ main(void) } } - // Test empty message with NULL pointer crypto_auth_keygen(key); - crypto_auth(a, NULL, 0U, key); - assert(crypto_auth_verify(a, NULL, 0U, key) == 0); + crypto_auth(a, guard_page, 0U, key); + assert(crypto_auth_verify(a, guard_page, 0U, key) == 0); return 0; } diff --git a/test/default/auth7.c b/test/default/auth7.c index 71f97dff..3d087f8e 100644 --- a/test/default/auth7.c +++ b/test/default/auth7.c @@ -33,10 +33,9 @@ main(void) } } - // Test empty message with NULL pointer crypto_auth_keygen(key); - crypto_auth_hmacsha512(a, NULL, 0U, key); - assert(crypto_auth_hmacsha512_verify(a, NULL, 0U, key) == 0); + crypto_auth_hmacsha512(a, guard_page, 0U, key); + assert(crypto_auth_hmacsha512_verify(a, guard_page, 0U, key) == 0); return 0; } diff --git a/test/default/box_easy.c b/test/default/box_easy.c index b7d0a028..2e6a20f9 100644 --- a/test/default/box_easy.c +++ b/test/default/box_easy.c @@ -50,7 +50,7 @@ main(void) /* Null message */ - ret = crypto_box_easy(c, NULL, 0, nonce, bobpk, alicesk); + ret = crypto_box_easy(c, guard_page, 0, nonce, bobpk, alicesk); assert(ret == 0); for (i = 0; i < 1 + crypto_box_MACBYTES; ++i) { printf(",0x%02x", (unsigned int) c[i]); diff --git a/test/default/cmptest.h b/test/default/cmptest.h index 4625d551..1ecc5cd9 100644 --- a/test/default/cmptest.h +++ b/test/default/cmptest.h @@ -178,11 +178,15 @@ int main(void) if (sodium_init() != 0) { return 99; } +# if defined(__EMSCRIPTEN__) || defined(__SANITIZE_ADDRESS__) + guard_page = _guard_page = NULL; +#else if ((_guard_page = (unsigned char *) sodium_malloc(0)) == NULL) { perror("sodium_malloc()"); return 99; } guard_page = _guard_page + 1; +#endif if (xmain() != 0) { return 99; } diff --git a/test/default/codecs.c b/test/default/codecs.c index 0ca7a49b..726c96bc 100644 --- a/test/default/codecs.c +++ b/test/default/codecs.c @@ -20,10 +20,10 @@ main(void) printf("%s\n", sodium_bin2hex(buf3, 33U, (const unsigned char *) "0123456789ABCDEF", 16U)); - printf("bin2hex(..., NULL, 0):%s\n", - sodium_bin2hex(buf4, sizeof(buf4), NULL, 0U)); + printf("bin2hex(..., guard_page, 0):%s\n", + sodium_bin2hex(buf3, sizeof buf3, guard_page, 0U)); printf("bin2hex(..., \"\", 0):%s\n", - sodium_bin2hex(buf4, sizeof(buf4), (const unsigned char *) "", 0U)); + sodium_bin2hex(buf3, sizeof buf3, (const unsigned char *) "", 0U)); hex = "Cafe : 6942"; sodium_hex2bin(buf4, sizeof buf4, hex, strlen(hex), ": ", &bin_len, @@ -84,10 +84,11 @@ main(void) printf("sodium_hex2bin() with an extra character and no end pointer\n"); } - assert(sodium_hex2bin(buf4, sizeof(buf4), NULL, 0U, NULL, &bin_len, NULL) == 0); + assert(sodium_hex2bin(buf4, sizeof buf4, (const char *) guard_page, 0U, + NULL, &bin_len, NULL) == 0); assert(bin_len == 0); - assert(sodium_hex2bin(buf4, sizeof(buf4), "", 0U, NULL, &bin_len, NULL) == 0); + assert(sodium_hex2bin(buf4, sizeof buf4, "", 0U, NULL, &bin_len, NULL) == 0); assert(bin_len == 0); printf("%s\n", @@ -105,9 +106,6 @@ main(void) printf("%s\n", sodium_bin2base64(buf3, 1U, guard_page, 0U, sodium_base64_VARIANT_ORIGINAL)); - printf("%s\n", - sodium_bin2base64(buf3, 1U, NULL, - 0U, sodium_base64_VARIANT_ORIGINAL)); printf("%s\n", sodium_bin2base64(buf3, 5U, (const unsigned char *) "a", 1U, sodium_base64_VARIANT_ORIGINAL)); @@ -215,10 +213,11 @@ main(void) assert(sodium_base642bin(buf1, sizeof buf1, "ka*w*=*", (size_t) 7U, "*~", NULL, NULL, sodium_base64_VARIANT_ORIGINAL) == 0); - assert(sodium_base642bin(buf1, sizeof buf1, "", 0U, NULL, &bin_len, NULL, - sodium_base64_VARIANT_ORIGINAL) == 0); + assert(sodium_base642bin(buf1, sizeof buf1, (const char *) guard_page, 0U, + NULL, &bin_len, NULL, sodium_base64_VARIANT_ORIGINAL) == 0); assert(bin_len == 0); - assert(sodium_base642bin(buf1, sizeof buf1, NULL, 0U, NULL, &bin_len, NULL, + + assert(sodium_base642bin(buf1, sizeof buf1, "", 0U, NULL, &bin_len, NULL, sodium_base64_VARIANT_ORIGINAL) == 0); assert(bin_len == 0); diff --git a/test/default/codecs.exp b/test/default/codecs.exp index 748b1a18..171834ed 100644 --- a/test/default/codecs.exp +++ b/test/default/codecs.exp @@ -1,5 +1,5 @@ 30313233343536373839414243444546 -bin2hex(..., NULL, 0): +bin2hex(..., guard_page, 0): bin2hex(..., "", 0): 4:cafe6942 dt1: 11 @@ -14,7 +14,6 @@ dt6: 11 -_DxMDEyMzQ1Njc4OUFCQ0RFRmFi -_DxMDEyMzQ1Njc4OUFCQ0RFRmFiYw - YQ== YWI= YWJj diff --git a/test/default/sodium_utils.c b/test/default/sodium_utils.c index 8bd8509c..844e16cf 100644 --- a/test/default/sodium_utils.c +++ b/test/default/sodium_utils.c @@ -29,10 +29,10 @@ main(void) printf("%d\n", sodium_memcmp(buf1, buf2, 0U)); sodium_memzero(buf2, sizeof buf2 / 2); printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1)); - printf("%d\n", sodium_memcmp(buf1, NULL, 0U)); - printf("%d\n", sodium_memcmp(NULL, buf2, 0U)); - printf("%d\n", sodium_memcmp(NULL, NULL, 0U)); - sodium_memzero(NULL, 0U); + printf("%d\n", sodium_memcmp(buf1, guard_page, 0U)); + printf("%d\n", sodium_memcmp(guard_page, buf2, 0U)); + printf("%d\n", sodium_memcmp(guard_page, guard_page, 0U)); + sodium_memzero(guard_page, 0U); memset(nonce, 0, sizeof nonce); sodium_increment(nonce, sizeof nonce); @@ -163,18 +163,18 @@ main(void) sodium_add(nonce, nonce, 0U); printf("%s\n", sodium_bin2hex(nonce_hex, sizeof nonce_hex, nonce, sizeof nonce)); - sodium_add(nonce, NULL, 0U); + sodium_add(nonce, guard_page, 0U); printf("%s\n", sodium_bin2hex(nonce_hex, sizeof nonce_hex, nonce, sizeof nonce)); - sodium_add(NULL, nonce, 0U); + sodium_add(guard_page, nonce, 0U); sodium_sub(nonce, nonce, 0U); printf("%s\n", sodium_bin2hex(nonce_hex, sizeof nonce_hex, nonce, sizeof nonce)); - sodium_sub(nonce, NULL, 0U); + sodium_sub(nonce, guard_page, 0U); printf("%s\n", sodium_bin2hex(nonce_hex, sizeof nonce_hex, nonce, sizeof nonce)); - sodium_sub(NULL, nonce, 0U); + sodium_sub(guard_page, nonce, 0U); randombytes_buf(buf1, 64U); randombytes_buf(buf2, 64U);