libsodium: Needed for Dnscrypto-proxy Release 1.3.0
[tomato.git] / release / src / router / libsodium / test / default / box7.c
blobea7b484e1c2f5754055a5b156d0f674bb1d566d3
1 #include <stdio.h>
3 #define TEST_NAME "box7"
4 #include "cmptest.h"
6 unsigned char alicesk[crypto_box_SECRETKEYBYTES];
7 unsigned char alicepk[crypto_box_PUBLICKEYBYTES];
8 unsigned char bobsk[crypto_box_SECRETKEYBYTES];
9 unsigned char bobpk[crypto_box_PUBLICKEYBYTES];
10 unsigned char n[crypto_box_NONCEBYTES];
11 unsigned char m[10000];
12 unsigned char c[10000];
13 unsigned char m2[10000];
15 int main(void)
17 size_t mlen;
18 size_t i;
20 for (mlen = 0;mlen < 1000 && mlen + crypto_box_ZEROBYTES < sizeof m;++mlen) {
21 crypto_box_keypair(alicepk,alicesk);
22 crypto_box_keypair(bobpk,bobsk);
23 randombytes(n,crypto_box_NONCEBYTES);
24 randombytes(m + crypto_box_ZEROBYTES,mlen);
25 crypto_box(c,m,mlen + crypto_box_ZEROBYTES,n,bobpk,alicesk);
26 if (crypto_box_open(m2,c,mlen + crypto_box_ZEROBYTES,n,alicepk,bobsk) == 0) {
27 for (i = 0;i < mlen + crypto_box_ZEROBYTES;++i)
28 if (m2[i] != m[i]) {
29 printf("bad decryption\n");
30 break;
32 } else {
33 printf("ciphertext fails verification\n");
36 return 0;