1*0ac341f1SConrad Meyer
2*0ac341f1SConrad Meyer #define TEST_NAME "hash"
3*0ac341f1SConrad Meyer #include "cmptest.h"
4*0ac341f1SConrad Meyer
5*0ac341f1SConrad Meyer static unsigned char x[] = "testing\n";
6*0ac341f1SConrad Meyer static unsigned char x2[] =
7*0ac341f1SConrad Meyer "The Conscience of a Hacker is a small essay written January 8, 1986 by a "
8*0ac341f1SConrad Meyer "computer security hacker who went by the handle of The Mentor, who "
9*0ac341f1SConrad Meyer "belonged to the 2nd generation of Legion of Doom.";
10*0ac341f1SConrad Meyer static unsigned char h[crypto_hash_BYTES];
11*0ac341f1SConrad Meyer
12*0ac341f1SConrad Meyer int
main(void)13*0ac341f1SConrad Meyer main(void)
14*0ac341f1SConrad Meyer {
15*0ac341f1SConrad Meyer size_t i;
16*0ac341f1SConrad Meyer
17*0ac341f1SConrad Meyer crypto_hash(h, x, sizeof x - 1U);
18*0ac341f1SConrad Meyer for (i = 0; i < crypto_hash_BYTES; ++i) {
19*0ac341f1SConrad Meyer printf("%02x", (unsigned int) h[i]);
20*0ac341f1SConrad Meyer }
21*0ac341f1SConrad Meyer printf("\n");
22*0ac341f1SConrad Meyer crypto_hash(h, x2, sizeof x2 - 1U);
23*0ac341f1SConrad Meyer for (i = 0; i < crypto_hash_BYTES; ++i) {
24*0ac341f1SConrad Meyer printf("%02x", (unsigned int) h[i]);
25*0ac341f1SConrad Meyer }
26*0ac341f1SConrad Meyer printf("\n");
27*0ac341f1SConrad Meyer crypto_hash_sha256(h, x, sizeof x - 1U);
28*0ac341f1SConrad Meyer for (i = 0; i < crypto_hash_sha256_BYTES; ++i) {
29*0ac341f1SConrad Meyer printf("%02x", (unsigned int) h[i]);
30*0ac341f1SConrad Meyer }
31*0ac341f1SConrad Meyer printf("\n");
32*0ac341f1SConrad Meyer crypto_hash_sha256(h, x2, sizeof x2 - 1U);
33*0ac341f1SConrad Meyer for (i = 0; i < crypto_hash_sha256_BYTES; ++i) {
34*0ac341f1SConrad Meyer printf("%02x", (unsigned int) h[i]);
35*0ac341f1SConrad Meyer }
36*0ac341f1SConrad Meyer printf("\n");
37*0ac341f1SConrad Meyer
38*0ac341f1SConrad Meyer assert(crypto_hash_bytes() > 0U);
39*0ac341f1SConrad Meyer assert(strcmp(crypto_hash_primitive(), "sha512") == 0);
40*0ac341f1SConrad Meyer assert(crypto_hash_sha256_bytes() > 0U);
41*0ac341f1SConrad Meyer assert(crypto_hash_sha512_bytes() >= crypto_hash_sha256_bytes());
42*0ac341f1SConrad Meyer assert(crypto_hash_sha512_bytes() == crypto_hash_bytes());
43*0ac341f1SConrad Meyer assert(crypto_hash_sha256_statebytes() == sizeof(crypto_hash_sha256_state));
44*0ac341f1SConrad Meyer assert(crypto_hash_sha512_statebytes() == sizeof(crypto_hash_sha512_state));
45*0ac341f1SConrad Meyer
46*0ac341f1SConrad Meyer return 0;
47*0ac341f1SConrad Meyer }
48