2 #define TEST_NAME "hash"
5 static unsigned char x[] = "testing\n";
6 static unsigned char x2[] =
7 "The Conscience of a Hacker is a small essay written January 8, 1986 by a "
8 "computer security hacker who went by the handle of The Mentor, who "
9 "belonged to the 2nd generation of Legion of Doom.";
10 static unsigned char h[crypto_hash_BYTES];
17 crypto_hash(h, x, sizeof x - 1U);
18 for (i = 0; i < crypto_hash_BYTES; ++i) {
19 printf("%02x", (unsigned int) h[i]);
22 crypto_hash(h, x2, sizeof x2 - 1U);
23 for (i = 0; i < crypto_hash_BYTES; ++i) {
24 printf("%02x", (unsigned int) h[i]);
27 crypto_hash_sha256(h, x, sizeof x - 1U);
28 for (i = 0; i < crypto_hash_sha256_BYTES; ++i) {
29 printf("%02x", (unsigned int) h[i]);
32 crypto_hash_sha256(h, x2, sizeof x2 - 1U);
33 for (i = 0; i < crypto_hash_sha256_BYTES; ++i) {
34 printf("%02x", (unsigned int) h[i]);
38 assert(crypto_hash_bytes() > 0U);
39 assert(strcmp(crypto_hash_primitive(), "sha512") == 0);
40 assert(crypto_hash_sha256_bytes() > 0U);
41 assert(crypto_hash_sha512_bytes() >= crypto_hash_sha256_bytes());
42 assert(crypto_hash_sha512_bytes() == crypto_hash_bytes());
43 assert(crypto_hash_sha256_statebytes() == sizeof(crypto_hash_sha256_state));
44 assert(crypto_hash_sha512_statebytes() == sizeof(crypto_hash_sha512_state));