Merge branch 'master' of github.com:jedisct1/libsodium
* 'master' of github.com:jedisct1/libsodium: C++ compat Use guarded memory for the box_easy/box_detached tests.
This commit is contained in:
commit
b5e1a5afc1
@ -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 = (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);
|
||||
@ -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;
|
||||
}
|
||||
|
@ -2,3 +2,4 @@
|
||||
0
|
||||
0
|
||||
0
|
||||
OK
|
||||
|
Loading…
Reference in New Issue
Block a user