diff options
Diffstat (limited to 'nacl/tests/secretbox5.cpp')
-rw-r--r-- | nacl/tests/secretbox5.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/nacl/tests/secretbox5.cpp b/nacl/tests/secretbox5.cpp new file mode 100644 index 00000000..e8cc0eeb --- /dev/null +++ b/nacl/tests/secretbox5.cpp | |||
@@ -0,0 +1,29 @@ | |||
1 | #include <string> | ||
2 | using std::string; | ||
3 | #include <stdio.h> | ||
4 | #include "crypto_secretbox.h" | ||
5 | #include "randombytes.h" | ||
6 | |||
7 | main() | ||
8 | { | ||
9 | int mlen; | ||
10 | for (mlen = 0;mlen < 1000;++mlen) { | ||
11 | unsigned char kbytes[crypto_secretbox_KEYBYTES]; | ||
12 | randombytes(kbytes,crypto_secretbox_KEYBYTES); | ||
13 | string k((char *) kbytes,crypto_secretbox_KEYBYTES); | ||
14 | unsigned char nbytes[crypto_secretbox_NONCEBYTES]; | ||
15 | randombytes(nbytes,crypto_secretbox_NONCEBYTES); | ||
16 | string n((char *) nbytes,crypto_secretbox_NONCEBYTES); | ||
17 | unsigned char mbytes[mlen]; | ||
18 | randombytes(mbytes,mlen); | ||
19 | string m((char *) mbytes,mlen); | ||
20 | string c = crypto_secretbox(m,n,k); | ||
21 | try { | ||
22 | string m2 = crypto_secretbox_open(c,n,k); | ||
23 | if (m != m2) printf("bad decryption\n"); | ||
24 | } catch(const char *s) { | ||
25 | printf("%s\n",s); | ||
26 | } | ||
27 | } | ||
28 | return 0; | ||
29 | } | ||