libsodium: updated to 1.0.10
[tomato.git] / release / src / router / libsodium / test / default / auth7.c
blob94823d215c036ea964993c446ae5f7392c1c1be5
2 #define TEST_NAME "auth7"
3 #include "cmptest.h"
5 static unsigned char key[32];
6 static unsigned char c[600];
7 static unsigned char a[64];
9 int main(void)
11 size_t clen;
13 for (clen = 0; clen < sizeof c; ++clen) {
14 randombytes_buf(key, sizeof key);
15 randombytes_buf(c, clen);
16 crypto_auth_hmacsha512(a, c, clen, key);
17 if (crypto_auth_hmacsha512_verify(a, c, clen, key) != 0) {
18 printf("fail %u\n", (unsigned int) clen);
19 return 100;
21 if (clen > 0) {
22 c[(size_t) rand() % clen] += 1 + (rand() % 255);
23 if (crypto_auth_hmacsha512_verify(a, c, clen, key) == 0) {
24 printf("forgery %u\n", (unsigned int) clen);
25 return 100;
27 a[rand() % sizeof a] += 1 + (rand() % 255);
28 if (crypto_auth_hmacsha512_verify(a, c, clen, key) == 0) {
29 printf("forgery %u\n", (unsigned int) clen);
30 return 100;
34 return 0;