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