1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-19 01:55:02 -07:00

Add a simple test for the secretbox easy interface.

This commit is contained in:
Frank Denis 2013-12-31 18:46:10 +01:00
parent e8509072a9
commit aaa4dab74a
4 changed files with 35 additions and 0 deletions

1
.gitignore vendored
View File

@ -88,6 +88,7 @@ test/default/secretbox2
test/default/secretbox7
test/default/secretbox8
test/default/secretbox_easy
test/default/secretbox_easy2
test/default/shorthash
test/default/sodium_core
test/default/sodium_utils

View File

@ -38,6 +38,7 @@ EXTRA_DIST = \
secretbox7.exp \
secretbox8.exp \
secretbox_easy.exp \
secretbox_easy2.exp \
shorthash.exp \
sodium_core.exp \
sodium_utils.exp \
@ -86,6 +87,7 @@ DISTCLEANFILES = \
secretbox7.res \
secretbox8.res \
secretbox_easy.res \
secretbox_easy2.res \
shorthash.res \
sodium_core.res \
sodium_utils.res \
@ -142,6 +144,7 @@ TESTS_TARGETS = \
secretbox7 \
secretbox8 \
secretbox_easy \
secretbox_easy2 \
shorthash \
sodium_core \
sodium_utils \
@ -268,6 +271,9 @@ secretbox8_LDADD = $(TESTS_LDADD)
secretbox_easy_SOURCE = cmptest.h secretbox_easy.c
secretbox_easy_LDADD = $(TESTS_LDADD)
secretbox_easy2_SOURCE = cmptest.h secretbox_easy2.c
secretbox_easy2_LDADD = $(TESTS_LDADD)
shorthash_SOURCE = cmptest.h shorthash.c
shorthash_LDADD = $(TESTS_LDADD)

View File

@ -0,0 +1,27 @@
#include <stdio.h>
#include <string.h>
#define TEST_NAME "secretbox_easy2"
#include "cmptest.h"
unsigned char m[10000];
unsigned char m2[10000];
unsigned char c[crypto_secretbox_MACBYTES + 10000];
unsigned char nonce[crypto_secretbox_NONCEBYTES];
unsigned char k[crypto_secretbox_KEYBYTES];
int main(void)
{
unsigned long long mlen;
randombytes_buf(k, sizeof k);
mlen = (unsigned long long) randombytes_uniform((uint32_t) sizeof m);
randombytes_buf(m, mlen);
randombytes_buf(nonce, sizeof nonce);
crypto_secretbox_easy(c, m, mlen, nonce, k);
crypto_secretbox_open_easy(m2, c, mlen + crypto_secretbox_MACBYTES,
nonce, k);
printf("%d\n", memcmp(m, m2, mlen));
return 0;
}

View File

@ -0,0 +1 @@
0