summaryrefslogtreecommitdiff
path: root/nacl/tests/box8.c
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/tests/box8.c')
-rw-r--r--nacl/tests/box8.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/nacl/tests/box8.c b/nacl/tests/box8.c
new file mode 100644
index 00000000..dac676ef
--- /dev/null
+++ b/nacl/tests/box8.c
@@ -0,0 +1,41 @@
1#include <stdio.h>
2#include "crypto_box.h"
3#include "randombytes.h"
4
5unsigned char alicesk[crypto_box_SECRETKEYBYTES];
6unsigned char alicepk[crypto_box_PUBLICKEYBYTES];
7unsigned char bobsk[crypto_box_SECRETKEYBYTES];
8unsigned char bobpk[crypto_box_PUBLICKEYBYTES];
9unsigned char n[crypto_box_NONCEBYTES];
10unsigned char m[10000];
11unsigned char c[10000];
12unsigned char m2[10000];
13
14main()
15{
16 int mlen;
17 int i;
18 int caught;
19
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 caught = 0;
27 while (caught < 10) {
28 c[random() % (mlen + crypto_box_ZEROBYTES)] = random();
29 if (crypto_box_open(m2,c,mlen + crypto_box_ZEROBYTES,n,alicepk,bobsk) == 0) {
30 for (i = 0;i < mlen + crypto_box_ZEROBYTES;++i)
31 if (m2[i] != m[i]) {
32 printf("forgery\n");
33 return 100;
34 }
35 } else {
36 ++caught;
37 }
38 }
39 }
40 return 0;
41}