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/box6.cpp | |
parent | 835ef0320d47372eac14bef31c979b8217d04498 (diff) |
NaCl moved to other repo.
Diffstat (limited to 'nacl/tests/box6.cpp')
-rw-r--r-- | nacl/tests/box6.cpp | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/nacl/tests/box6.cpp b/nacl/tests/box6.cpp deleted file mode 100644 index bab18105..00000000 --- a/nacl/tests/box6.cpp +++ /dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | #include <string> | ||
2 | using std::string; | ||
3 | #include <stdlib.h> | ||
4 | #include <stdio.h> | ||
5 | #include "crypto_box.h" | ||
6 | #include "randombytes.h" | ||
7 | |||
8 | main() | ||
9 | { | ||
10 | int mlen; | ||
11 | for (mlen = 0;mlen < 1000;++mlen) { | ||
12 | string alicesk; | ||
13 | string alicepk = crypto_box_keypair(&alicesk); | ||
14 | string bobsk; | ||
15 | string bobpk = crypto_box_keypair(&bobsk); | ||
16 | unsigned char nbytes[crypto_box_NONCEBYTES]; | ||
17 | randombytes(nbytes,crypto_box_NONCEBYTES); | ||
18 | string n((char *) nbytes,crypto_box_NONCEBYTES); | ||
19 | unsigned char mbytes[mlen]; | ||
20 | randombytes(mbytes,mlen); | ||
21 | string m((char *) mbytes,mlen); | ||
22 | string c = crypto_box(m,n,bobpk,alicesk); | ||
23 | int caught = 0; | ||
24 | while (caught < 10) { | ||
25 | c.replace(random() % c.size(),1,1,random()); | ||
26 | try { | ||
27 | string m2 = crypto_box_open(c,n,alicepk,bobsk); | ||
28 | if (m != m2) { | ||
29 | printf("forgery\n"); | ||
30 | return 100; | ||
31 | } | ||
32 | } catch(const char *s) { | ||
33 | if (string(s) == string("ciphertext fails verification")) | ||
34 | ++caught; | ||
35 | else { | ||
36 | printf("%s\n",s); | ||
37 | return 111; | ||
38 | } | ||
39 | } | ||
40 | } | ||
41 | } | ||
42 | return 0; | ||
43 | } | ||