diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-02 09:53:34 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-02 09:53:34 -0400 |
commit | e2967396ac73cb7410787886cdaf072a184ffc49 (patch) | |
tree | 527a74d25a4a0705fc641994fd35bfab22662034 /nacl/tests/onetimeauth8.cpp | |
parent | 8928c817df345f29aa0b194743595aa11bd6a8ba (diff) |
Added NaCl crypto library.
Diffstat (limited to 'nacl/tests/onetimeauth8.cpp')
-rw-r--r-- | nacl/tests/onetimeauth8.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/nacl/tests/onetimeauth8.cpp b/nacl/tests/onetimeauth8.cpp new file mode 100644 index 00000000..ce554fb4 --- /dev/null +++ b/nacl/tests/onetimeauth8.cpp | |||
@@ -0,0 +1,46 @@ | |||
1 | #include <string> | ||
2 | using std::string; | ||
3 | #include <stdio.h> | ||
4 | #include <stdlib.h> | ||
5 | #include "crypto_onetimeauth_poly1305.h" | ||
6 | #include "randombytes.h" | ||
7 | |||
8 | main() | ||
9 | { | ||
10 | int clen; | ||
11 | int i; | ||
12 | for (clen = 0;clen < 10000;++clen) { | ||
13 | unsigned char key_bytes[32]; | ||
14 | randombytes(key_bytes,sizeof key_bytes); | ||
15 | string key((char *) key_bytes,sizeof key_bytes); | ||
16 | unsigned char c_bytes[clen]; | ||
17 | randombytes(c_bytes,sizeof c_bytes); | ||
18 | string c((char *) c_bytes,sizeof c_bytes); | ||
19 | string a = crypto_onetimeauth_poly1305(c,key); | ||
20 | try { | ||
21 | crypto_onetimeauth_poly1305_verify(a,c,key); | ||
22 | } catch(const char *s) { | ||
23 | printf("fail %d %s\n",clen,s); | ||
24 | return 100; | ||
25 | } | ||
26 | if (clen > 0) { | ||
27 | size_t pos = random() % clen; | ||
28 | c.replace(pos,1,1,c[pos] + 1 + (random() % 255)); | ||
29 | try { | ||
30 | crypto_onetimeauth_poly1305_verify(a,c,key); | ||
31 | printf("forgery %d\n",clen); | ||
32 | } catch(const char *s) { | ||
33 | ; | ||
34 | } | ||
35 | pos = random() % a.size(); | ||
36 | a.replace(pos,1,1,a[pos] + 1 + (random() % 255)); | ||
37 | try { | ||
38 | crypto_onetimeauth_poly1305_verify(a,c,key); | ||
39 | printf("forgery %d\n",clen); | ||
40 | } catch(const char *s) { | ||
41 | ; | ||
42 | } | ||
43 | } | ||
44 | } | ||
45 | return 0; | ||
46 | } | ||