1
2#define TEST_NAME "hash"
3#include "cmptest.h"
4
5static unsigned char x[] = "testing\n";
6static 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.";
10static unsigned char h[crypto_hash_BYTES];
11
12int
13main(void)
14{
15    size_t i;
16
17    crypto_hash(h, x, sizeof x - 1U);
18    for (i = 0; i < crypto_hash_BYTES; ++i) {
19        printf("%02x", (unsigned int) h[i]);
20    }
21    printf("\n");
22    crypto_hash(h, x2, sizeof x2 - 1U);
23    for (i = 0; i < crypto_hash_BYTES; ++i) {
24        printf("%02x", (unsigned int) h[i]);
25    }
26    printf("\n");
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]);
30    }
31    printf("\n");
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]);
35    }
36    printf("\n");
37
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));
45
46    return 0;
47}
48