diff options
Diffstat (limited to 'nacl/tests/auth6.cpp')
-rw-r--r-- | nacl/tests/auth6.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/nacl/tests/auth6.cpp b/nacl/tests/auth6.cpp new file mode 100644 index 00000000..dffb6388 --- /dev/null +++ b/nacl/tests/auth6.cpp | |||
@@ -0,0 +1,46 @@ | |||
1 | #include <string> | ||
2 | using std::string; | ||
3 | #include <stdio.h> | ||
4 | #include <stdlib.h> | ||
5 | #include "crypto_auth_hmacsha512256.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_auth_hmacsha512256(c,key); | ||
20 | try { | ||
21 | crypto_auth_hmacsha512256_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_auth_hmacsha512256_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_auth_hmacsha512256_verify(a,c,key); | ||
39 | printf("forgery %d\n",clen); | ||
40 | } catch(const char *s) { | ||
41 | ; | ||
42 | } | ||
43 | } | ||
44 | } | ||
45 | return 0; | ||
46 | } | ||