summaryrefslogtreecommitdiff
path: root/nacl/tests/box5.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/tests/box5.cpp')
-rw-r--r--nacl/tests/box5.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/nacl/tests/box5.cpp b/nacl/tests/box5.cpp
new file mode 100644
index 00000000..366e2e30
--- /dev/null
+++ b/nacl/tests/box5.cpp
@@ -0,0 +1,30 @@
1#include <string>
2using std::string;
3#include <stdio.h>
4#include "crypto_box.h"
5#include "randombytes.h"
6
7main()
8{
9 int mlen;
10 for (mlen = 0;mlen < 1000;++mlen) {
11 string alicesk;
12 string alicepk = crypto_box_keypair(&alicesk);
13 string bobsk;
14 string bobpk = crypto_box_keypair(&bobsk);
15 unsigned char nbytes[crypto_box_NONCEBYTES];
16 randombytes(nbytes,crypto_box_NONCEBYTES);
17 string n((char *) nbytes,crypto_box_NONCEBYTES);
18 unsigned char mbytes[mlen];
19 randombytes(mbytes,mlen);
20 string m((char *) mbytes,mlen);
21 string c = crypto_box(m,n,bobpk,alicesk);
22 try {
23 string m2 = crypto_box_open(c,n,alicepk,bobsk);
24 if (m != m2) printf("bad decryption\n");
25 } catch(const char *s) {
26 printf("%s\n",s);
27 }
28 }
29 return 0;
30}