1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-20 02:25:14 -07:00

Reduce the number of rounds in the box7 test, use guarded memory

This commit is contained in:
Frank Denis 2015-12-09 01:41:30 +01:00
parent fb09514949
commit d9e38003dc

View File

@ -13,14 +13,21 @@ static unsigned char m2[10000];
int main(void)
{
size_t mlen;
size_t i;
int ret;
unsigned char *m;
unsigned char *c;
unsigned char *m2;
size_t mlen;
size_t mlen_max = 600;
size_t i;
int ret;
for (mlen = 0; mlen < 1000 && mlen + crypto_box_ZEROBYTES < sizeof m;
++mlen) {
crypto_box_keypair(alicepk, alicesk);
crypto_box_keypair(bobpk, bobsk);
m = (unsigned char *) sodium_malloc(mlen_max);
c = (unsigned char *) sodium_malloc(mlen_max);
m2 = (unsigned char *) sodium_malloc(mlen_max);
memset(m, 0, crypto_box_ZEROBYTES);
crypto_box_keypair(alicepk, alicesk);
crypto_box_keypair(bobpk, bobsk);
for (mlen = 0; mlen + crypto_box_ZEROBYTES <= mlen_max; mlen++) {
randombytes_buf(n, crypto_box_NONCEBYTES);
randombytes_buf(m + crypto_box_ZEROBYTES, mlen);
ret = crypto_box(c, m, mlen + crypto_box_ZEROBYTES, n, bobpk, alicesk);
@ -37,5 +44,9 @@ int main(void)
printf("ciphertext fails verification\n");
}
}
sodium_free(m);
sodium_free(c);
sodium_free(m2);
return 0;
}