xref: /freebsd/sys/contrib/libsodium/test/default/auth5.c (revision b9f654b163bce26de79705e77b872427c9f2afa1)
1 
2 #define TEST_NAME "auth5"
3 #include "cmptest.h"
4 
5 static unsigned char key[32];
6 static unsigned char c[1000];
7 static unsigned char a[32];
8 
9 int
10 main(void)
11 {
12     size_t clen;
13 
14     for (clen = 0; clen < 1000; ++clen) {
15         crypto_auth_keygen(key);
16         randombytes_buf(c, clen);
17         crypto_auth(a, c, clen, key);
18         if (crypto_auth_verify(a, c, clen, key) != 0) {
19             printf("fail %u\n", (unsigned int) clen);
20             return 100;
21         }
22         if (clen > 0) {
23             c[rand() % clen] += 1 + (rand() % 255);
24             if (crypto_auth_verify(a, c, clen, key) == 0) {
25                 printf("forgery %u\n", (unsigned int) clen);
26                 return 100;
27             }
28             a[rand() % sizeof a] += 1 + (rand() % 255);
29             if (crypto_auth_verify(a, c, clen, key) == 0) {
30                 printf("forgery %u\n", (unsigned int) clen);
31                 return 100;
32             }
33         }
34     }
35     return 0;
36 }
37