libsodium 1.0.8
[tomato.git] / release / src / router / libsodium / test / default / auth.c
blob83fc393dea92c2896c33bddcc013dc50bff678b5
2 #define TEST_NAME "auth"
3 #include "cmptest.h"
5 /* "Test Case 2" from RFC 4231 */
6 static unsigned char key[32] = "Jefe";
7 static unsigned char c[] = "what do ya want for nothing?";
9 /* Hacker manifesto */
10 static unsigned char key2[] = "Another one got caught today, it's all over the papers. \"Teenager Arrested in Computer Crime Scandal\", \"Hacker Arrested after Bank Tampering\"... Damn kids. They're all alike.";
12 static unsigned char a[crypto_auth_BYTES];
13 static unsigned char a2[crypto_auth_hmacsha512_BYTES];
15 int main(void)
17 crypto_auth_hmacsha512_state st;
18 size_t i;
20 assert(crypto_auth_hmacsha512_statebytes() ==
21 sizeof(crypto_auth_hmacsha512_state));
22 crypto_auth(a, c, sizeof c - 1U, key);
23 for (i = 0; i < sizeof a; ++i) {
24 printf(",0x%02x", (unsigned int)a[i]);
25 if (i % 8 == 7)
26 printf("\n");
28 printf("\n");
30 crypto_auth_hmacsha512_init(&st, key, sizeof key);
31 crypto_auth_hmacsha512_update(&st, c, 1U);
32 crypto_auth_hmacsha512_update(&st, c, sizeof c - 2U);
33 crypto_auth_hmacsha512_final(&st, a2);
34 for (i = 0; i < sizeof a2; ++i) {
35 printf(",0x%02x", (unsigned int)a2[i]);
36 if (i % 8 == 7)
37 printf("\n");
39 printf("\n");
41 crypto_auth_hmacsha512_init(&st, key2, sizeof key2);
42 crypto_auth_hmacsha512_update(&st, c, 1U);
43 crypto_auth_hmacsha512_update(&st, c, sizeof c - 2U);
44 crypto_auth_hmacsha512_final(&st, a2);
45 for (i = 0; i < sizeof a2; ++i) {
46 printf(",0x%02x", (unsigned int)a2[i]);
47 if (i % 8 == 7)
48 printf("\n");
51 assert(crypto_auth_bytes() > 0U);
52 assert(crypto_auth_keybytes() > 0U);
53 assert(strcmp(crypto_auth_primitive(), "hmacsha512256") == 0);
54 assert(crypto_auth_hmacsha256_bytes() > 0U);
55 assert(crypto_auth_hmacsha256_keybytes() > 0U);
56 assert(crypto_auth_hmacsha512_bytes() > 0U);
57 assert(crypto_auth_hmacsha512_keybytes() > 0U);
58 assert(crypto_auth_hmacsha512256_bytes() == crypto_auth_bytes());
59 assert(crypto_auth_hmacsha512256_keybytes() == crypto_auth_keybytes());
60 assert(crypto_auth_hmacsha512256_statebytes() >=
61 crypto_auth_hmacsha512256_keybytes());
62 assert(crypto_auth_hmacsha256_statebytes() ==
63 sizeof(crypto_auth_hmacsha256_state));
64 assert(crypto_auth_hmacsha512_statebytes() ==
65 sizeof(crypto_auth_hmacsha512_state));
67 return 0;