Use guarded memory for the box_easy/box_detached tests.

This commit is contained in:
Frank Denis 2014-12-18 00:00:19 +01:00
parent 9af34c5766
commit 9036d62fc9
2 changed files with 23 additions and 9 deletions

View File

@ -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);
@ -54,6 +60,13 @@ int main(void)
crypto_box_open_detached(m2, c, mac, (unsigned long long) mlen,
nonce, alicepk, bobsk);
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;
}

View File

@ -2,3 +2,4 @@
0
0
0
OK