libsodium 1.0.8
[tomato.git] / release / src / router / libsodium / test / default / hash.c
blobef27beef394938a1a29bf791efc3c27c33673551
2 #define TEST_NAME "hash"
3 #include "cmptest.h"
5 static unsigned char x[] = "testing\n";
6 static unsigned char x2[] = "The Conscience of a Hacker is a small essay written January 8, 1986 by a computer security hacker who went by the handle of The Mentor, who belonged to the 2nd generation of Legion of Doom.";
7 static unsigned char h[crypto_hash_BYTES];
9 int main(void)
11 size_t i;
13 crypto_hash(h, x, sizeof x - 1U);
14 for (i = 0; i < crypto_hash_BYTES; ++i) {
15 printf("%02x", (unsigned int)h[i]);
17 printf("\n");
18 crypto_hash(h, x2, sizeof x2 - 1U);
19 for (i = 0; i < crypto_hash_BYTES; ++i) {
20 printf("%02x", (unsigned int)h[i]);
22 printf("\n");
23 crypto_hash_sha256(h, x, sizeof x - 1U);
24 for (i = 0; i < crypto_hash_sha256_BYTES; ++i) {
25 printf("%02x", (unsigned int)h[i]);
27 printf("\n");
28 crypto_hash_sha256(h, x2, sizeof x2 - 1U);
29 for (i = 0; i < crypto_hash_sha256_BYTES; ++i) {
30 printf("%02x", (unsigned int)h[i]);
32 printf("\n");
34 assert(crypto_hash_bytes() > 0U);
35 assert(strcmp(crypto_hash_primitive(), "sha512") == 0);
36 assert(crypto_hash_sha256_bytes() > 0U);
37 assert(crypto_hash_sha512_bytes() >= crypto_hash_sha256_bytes());
38 assert(crypto_hash_sha512_bytes() == crypto_hash_bytes());
39 assert(crypto_hash_sha256_statebytes() == sizeof(crypto_hash_sha256_state));
40 assert(crypto_hash_sha512_statebytes() == sizeof(crypto_hash_sha512_state));
42 return 0;