diff options
Diffstat (limited to 'nacl/tests/box7.c')
-rw-r--r-- | nacl/tests/box7.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/nacl/tests/box7.c b/nacl/tests/box7.c new file mode 100644 index 00000000..809301c1 --- /dev/null +++ b/nacl/tests/box7.c | |||
@@ -0,0 +1,36 @@ | |||
1 | #include <stdio.h> | ||
2 | #include "crypto_box.h" | ||
3 | #include "randombytes.h" | ||
4 | |||
5 | unsigned char alicesk[crypto_box_SECRETKEYBYTES]; | ||
6 | unsigned char alicepk[crypto_box_PUBLICKEYBYTES]; | ||
7 | unsigned char bobsk[crypto_box_SECRETKEYBYTES]; | ||
8 | unsigned char bobpk[crypto_box_PUBLICKEYBYTES]; | ||
9 | unsigned char n[crypto_box_NONCEBYTES]; | ||
10 | unsigned char m[10000]; | ||
11 | unsigned char c[10000]; | ||
12 | unsigned char m2[10000]; | ||
13 | |||
14 | main() | ||
15 | { | ||
16 | int mlen; | ||
17 | int i; | ||
18 | |||
19 | for (mlen = 0;mlen < 1000 && mlen + crypto_box_ZEROBYTES < sizeof m;++mlen) { | ||
20 | crypto_box_keypair(alicepk,alicesk); | ||
21 | crypto_box_keypair(bobpk,bobsk); | ||
22 | randombytes(n,crypto_box_NONCEBYTES); | ||
23 | randombytes(m + crypto_box_ZEROBYTES,mlen); | ||
24 | crypto_box(c,m,mlen + crypto_box_ZEROBYTES,n,bobpk,alicesk); | ||
25 | if (crypto_box_open(m2,c,mlen + crypto_box_ZEROBYTES,n,alicepk,bobsk) == 0) { | ||
26 | for (i = 0;i < mlen + crypto_box_ZEROBYTES;++i) | ||
27 | if (m2[i] != m[i]) { | ||
28 | printf("bad decryption\n"); | ||
29 | break; | ||
30 | } | ||
31 | } else { | ||
32 | printf("ciphertext fails verification\n"); | ||
33 | } | ||
34 | } | ||
35 | return 0; | ||
36 | } | ||