From 9036d62fc9473bd7c3e912f6fa701943782bb990 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Thu, 18 Dec 2014 00:00:19 +0100 Subject: [PATCH 1/2] Use guarded memory for the box_easy/box_detached tests. --- test/default/box_easy2.c | 31 ++++++++++++++++++++++--------- test/default/box_easy2.exp | 1 + 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/test/default/box_easy2.c b/test/default/box_easy2.c index c7035138..8ee3cea3 100644 --- a/test/default/box_easy2.c +++ b/test/default/box_easy2.c @@ -5,18 +5,24 @@ unsigned char m[10000]; unsigned char m2[10000]; unsigned char c[crypto_box_MACBYTES + 10000]; -unsigned char nonce[crypto_box_NONCEBYTES]; -unsigned char alicepk[crypto_box_PUBLICKEYBYTES]; -unsigned char alicesk[crypto_box_SECRETKEYBYTES]; -unsigned char bobpk[crypto_box_PUBLICKEYBYTES]; -unsigned char bobsk[crypto_box_SECRETKEYBYTES]; -unsigned char mac[crypto_box_MACBYTES]; int main(void) { - size_t mlen; - size_t i; + unsigned char *alicepk; + unsigned char *alicesk; + unsigned char *bobpk; + unsigned char *bobsk; + unsigned char *mac; + unsigned char *nonce; + size_t mlen; + size_t i; + alicepk = sodium_malloc(crypto_box_PUBLICKEYBYTES); + alicesk = sodium_malloc(crypto_box_SECRETKEYBYTES); + bobpk = sodium_malloc(crypto_box_PUBLICKEYBYTES); + bobsk = sodium_malloc(crypto_box_SECRETKEYBYTES); + mac = sodium_malloc(crypto_box_MACBYTES); + nonce = sodium_malloc(crypto_box_NONCEBYTES); crypto_box_keypair(alicepk, alicesk); crypto_box_keypair(bobpk, bobsk); mlen = (size_t) randombytes_uniform((uint32_t)sizeof m); @@ -53,7 +59,14 @@ int main(void) nonce, bobsk, alicepk); crypto_box_open_detached(m2, c, mac, (unsigned long long) mlen, nonce, alicepk, bobsk); - printf("%d\n", memcmp(m, m2, mlen)); + printf("%d\n", memcmp(m, m2, mlen)); + sodium_free(alicepk); + sodium_free(alicesk); + sodium_free(bobpk); + sodium_free(bobsk); + sodium_free(mac); + sodium_free(nonce); + printf("OK\n"); return 0; } diff --git a/test/default/box_easy2.exp b/test/default/box_easy2.exp index 44e0be8e..524cb98e 100644 --- a/test/default/box_easy2.exp +++ b/test/default/box_easy2.exp @@ -2,3 +2,4 @@ 0 0 0 +OK From bfcd1612c719110794de39ac11d4c2b0f1fa23ed Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Thu, 18 Dec 2014 00:12:50 +0100 Subject: [PATCH 2/2] C++ compat --- test/default/box_easy2.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/default/box_easy2.c b/test/default/box_easy2.c index 8ee3cea3..2e366bf8 100644 --- a/test/default/box_easy2.c +++ b/test/default/box_easy2.c @@ -17,12 +17,12 @@ int main(void) size_t mlen; size_t i; - alicepk = sodium_malloc(crypto_box_PUBLICKEYBYTES); - alicesk = sodium_malloc(crypto_box_SECRETKEYBYTES); - bobpk = sodium_malloc(crypto_box_PUBLICKEYBYTES); - bobsk = sodium_malloc(crypto_box_SECRETKEYBYTES); - mac = sodium_malloc(crypto_box_MACBYTES); - nonce = sodium_malloc(crypto_box_NONCEBYTES); + alicepk = (unsigned char *) sodium_malloc(crypto_box_PUBLICKEYBYTES); + alicesk = (unsigned char *) sodium_malloc(crypto_box_SECRETKEYBYTES); + bobpk = (unsigned char *) sodium_malloc(crypto_box_PUBLICKEYBYTES); + bobsk = (unsigned char *) sodium_malloc(crypto_box_SECRETKEYBYTES); + mac = (unsigned char *) sodium_malloc(crypto_box_MACBYTES); + nonce = (unsigned char *) sodium_malloc(crypto_box_NONCEBYTES); crypto_box_keypair(alicepk, alicesk); crypto_box_keypair(bobpk, bobsk); mlen = (size_t) randombytes_uniform((uint32_t)sizeof m); @@ -59,7 +59,7 @@ int main(void) nonce, bobsk, alicepk); crypto_box_open_detached(m2, c, mac, (unsigned long long) mlen, nonce, alicepk, bobsk); - printf("%d\n", memcmp(m, m2, mlen)); + printf("%d\n", memcmp(m, m2, mlen)); sodium_free(alicepk); sodium_free(alicesk); sodium_free(bobpk);