libsodium: Needed for Dnscrypto-proxy Release 1.3.0
[tomato.git] / release / src / router / libsodium / test / default / box8.c
blobcc85057af9ad597967d95e4de2efb67f2e4a3c1f
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "windows/windows-quirks.h"
5 #define TEST_NAME "box8"
6 #include "cmptest.h"
8 unsigned char alicesk[crypto_box_SECRETKEYBYTES];
9 unsigned char alicepk[crypto_box_PUBLICKEYBYTES];
10 unsigned char bobsk[crypto_box_SECRETKEYBYTES];
11 unsigned char bobpk[crypto_box_PUBLICKEYBYTES];
12 unsigned char n[crypto_box_NONCEBYTES];
13 unsigned char m[10000];
14 unsigned char c[10000];
15 unsigned char m2[10000];
17 int main(void)
19 size_t mlen;
20 size_t i;
21 int caught;
23 for (mlen = 0;mlen < 1000 && mlen + crypto_box_ZEROBYTES < sizeof m;++mlen) {
24 crypto_box_keypair(alicepk,alicesk);
25 crypto_box_keypair(bobpk,bobsk);
26 randombytes(n,crypto_box_NONCEBYTES);
27 randombytes(m + crypto_box_ZEROBYTES,mlen);
28 crypto_box(c,m,mlen + crypto_box_ZEROBYTES,n,bobpk,alicesk);
29 caught = 0;
30 while (caught < 10) {
31 c[rand() % (mlen + crypto_box_ZEROBYTES)] = rand();
32 if (crypto_box_open(m2,c,mlen + crypto_box_ZEROBYTES,n,alicepk,bobsk) == 0) {
33 for (i = 0;i < mlen + crypto_box_ZEROBYTES;++i)
34 if (m2[i] != m[i]) {
35 printf("forgery\n");
36 return 100;
38 } else {
39 ++caught;
43 return 0;