Add a simple test for crypto_box_open_easy()

This commit is contained in:
Frank Denis 2013-12-31 14:24:28 +01:00
parent 02ec147a00
commit a29fcf90a6
4 changed files with 39 additions and 0 deletions

1
.gitignore vendored
View File

@ -61,6 +61,7 @@ test/default/box2
test/default/box7 test/default/box7
test/default/box8 test/default/box8
test/default/box_easy test/default/box_easy
test/default/box_easy2
test/default/core1 test/default/core1
test/default/core2 test/default/core2
test/default/core3 test/default/core3

View File

@ -11,6 +11,7 @@ EXTRA_DIST = \
box7.exp \ box7.exp \
box8.exp \ box8.exp \
box_easy.exp \ box_easy.exp \
box_easy2.exp \
core1.exp \ core1.exp \
core2.exp \ core2.exp \
core3.exp \ core3.exp \
@ -57,6 +58,7 @@ DISTCLEANFILES = \
box7.res \ box7.res \
box8.res \ box8.res \
box_easy.res \ box_easy.res \
box_easy2.res \
core1.res \ core1.res \
core2.res \ core2.res \
core3.res \ core3.res \
@ -111,6 +113,7 @@ TESTS_TARGETS = \
box7 \ box7 \
box8 \ box8 \
box_easy \ box_easy \
box_easy2 \
core1 \ core1 \
core2 \ core2 \
core3 \ core3 \
@ -181,6 +184,9 @@ box8_LDADD = $(TESTS_LDADD)
box_easy_SOURCE = cmptest.h box_easy.c box_easy_SOURCE = cmptest.h box_easy.c
box_easy_LDADD = $(TESTS_LDADD) box_easy_LDADD = $(TESTS_LDADD)
box_easy2_SOURCE = cmptest.h box_easy2.c
box_easy2_LDADD = $(TESTS_LDADD)
core1_SOURCE = cmptest.h core1.c core1_SOURCE = cmptest.h core1.c
core1_LDADD = $(TESTS_LDADD) core1_LDADD = $(TESTS_LDADD)

31
test/default/box_easy2.c Normal file
View File

@ -0,0 +1,31 @@
#include <stdio.h>
#include <string.h>
#define TEST_NAME "box_easy2"
#include "cmptest.h"
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];
int main(void)
{
unsigned long long mlen;
crypto_box_keypair(alicepk, alicesk);
crypto_box_keypair(bobpk, bobsk);
mlen = (unsigned long long) randombytes_uniform((uint32_t) sizeof m);
randombytes_buf(m, mlen);
randombytes_buf(nonce, sizeof nonce);
crypto_box_easy(c, m, mlen, nonce, bobpk, alicesk);
crypto_box_open_easy(m2, c, mlen + crypto_box_MACBYTES,
nonce, alicepk, bobsk);
printf("%d\n", memcmp(m, m2, mlen));
return 0;
}

View File

@ -0,0 +1 @@
0