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:
parent
e8509072a9
commit
aaa4dab74a
1
.gitignore
vendored
1
.gitignore
vendored
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
27
test/default/secretbox_easy2.c
Normal file
27
test/default/secretbox_easy2.c
Normal 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;
|
||||
}
|
1
test/default/secretbox_easy2.exp
Normal file
1
test/default/secretbox_easy2.exp
Normal file
@ -0,0 +1 @@
|
||||
0
|
Loading…
Reference in New Issue
Block a user