diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-13 10:09:38 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-13 10:09:38 -0400 |
commit | d4fe483efd3e0062f12430efe9deb66d43d914d7 (patch) | |
tree | e6aa9ac716ae82cdb15c6e6cb5d9d1d9d29f053b /nacl/tests/secretbox6.cpp | |
parent | 835ef0320d47372eac14bef31c979b8217d04498 (diff) |
NaCl moved to other repo.
Diffstat (limited to 'nacl/tests/secretbox6.cpp')
-rw-r--r-- | nacl/tests/secretbox6.cpp | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/nacl/tests/secretbox6.cpp b/nacl/tests/secretbox6.cpp deleted file mode 100644 index e8274006..00000000 --- a/nacl/tests/secretbox6.cpp +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | #include <string> | ||
2 | using std::string; | ||
3 | #include <stdlib.h> | ||
4 | #include <stdio.h> | ||
5 | #include "crypto_secretbox.h" | ||
6 | #include "randombytes.h" | ||
7 | |||
8 | main() | ||
9 | { | ||
10 | int mlen; | ||
11 | for (mlen = 0;mlen < 1000;++mlen) { | ||
12 | unsigned char kbytes[crypto_secretbox_KEYBYTES]; | ||
13 | randombytes(kbytes,crypto_secretbox_KEYBYTES); | ||
14 | string k((char *) kbytes,crypto_secretbox_KEYBYTES); | ||
15 | unsigned char nbytes[crypto_secretbox_NONCEBYTES]; | ||
16 | randombytes(nbytes,crypto_secretbox_NONCEBYTES); | ||
17 | string n((char *) nbytes,crypto_secretbox_NONCEBYTES); | ||
18 | unsigned char mbytes[mlen]; | ||
19 | randombytes(mbytes,mlen); | ||
20 | string m((char *) mbytes,mlen); | ||
21 | string c = crypto_secretbox(m,n,k); | ||
22 | int caught = 0; | ||
23 | while (caught < 10) { | ||
24 | c.replace(random() % c.size(),1,1,random()); | ||
25 | try { | ||
26 | string m2 = crypto_secretbox_open(c,n,k); | ||
27 | if (m != m2) { | ||
28 | printf("forgery\n"); | ||
29 | return 100; | ||
30 | } | ||
31 | } catch(const char *s) { | ||
32 | if (string(s) == string("ciphertext fails verification")) | ||
33 | ++caught; | ||
34 | else { | ||
35 | printf("%s\n",s); | ||
36 | return 111; | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | } | ||
41 | return 0; | ||
42 | } | ||