libsodium: Needed for Dnscrypto-proxy Release 1.3.0
[tomato.git] / release / src / router / libsodium / test / default / secretbox7.c
blob337f081bcbe7a91cd367bb5d3d292912969ffe05
1 #include <stdio.h>
3 #define TEST_NAME "secretbox7"
4 #include "cmptest.h"
6 unsigned char k[crypto_secretbox_KEYBYTES];
7 unsigned char n[crypto_secretbox_NONCEBYTES];
8 unsigned char m[10000];
9 unsigned char c[10000];
10 unsigned char m2[10000];
12 int main(void)
14 size_t mlen;
15 size_t i;
17 for (mlen = 0;mlen < 1000 && mlen + crypto_secretbox_ZEROBYTES < sizeof m;++mlen) {
18 randombytes(k,crypto_secretbox_KEYBYTES);
19 randombytes(n,crypto_secretbox_NONCEBYTES);
20 randombytes(m + crypto_secretbox_ZEROBYTES,mlen);
21 crypto_secretbox(c,m,mlen + crypto_secretbox_ZEROBYTES,n,k);
22 if (crypto_secretbox_open(m2,c,mlen + crypto_secretbox_ZEROBYTES,n,k) == 0) {
23 for (i = 0;i < mlen + crypto_secretbox_ZEROBYTES;++i)
24 if (m2[i] != m[i]) {
25 printf("bad decryption\n");
26 break;
28 } else {
29 printf("ciphertext fails verification\n");
32 return 0;