Blame SOURCES/libsodium-1.0.18/test/default/hash.c

ca16be
ca16be
#define TEST_NAME "hash"
ca16be
#include "cmptest.h"
ca16be
ca16be
static unsigned char x[] = "testing\n";
ca16be
static unsigned char x2[] =
ca16be
    "The Conscience of a Hacker is a small essay written January 8, 1986 by a "
ca16be
    "computer security hacker who went by the handle of The Mentor, who "
ca16be
    "belonged to the 2nd generation of Legion of Doom.";
ca16be
static unsigned char h[crypto_hash_BYTES];
ca16be
ca16be
int
ca16be
main(void)
ca16be
{
ca16be
    size_t i;
ca16be
ca16be
    crypto_hash(h, x, sizeof x - 1U);
ca16be
    for (i = 0; i < crypto_hash_BYTES; ++i) {
ca16be
        printf("%02x", (unsigned int) h[i]);
ca16be
    }
ca16be
    printf("\n");
ca16be
    crypto_hash(h, x2, sizeof x2 - 1U);
ca16be
    for (i = 0; i < crypto_hash_BYTES; ++i) {
ca16be
        printf("%02x", (unsigned int) h[i]);
ca16be
    }
ca16be
    printf("\n");
ca16be
    crypto_hash_sha256(h, x, sizeof x - 1U);
ca16be
    for (i = 0; i < crypto_hash_sha256_BYTES; ++i) {
ca16be
        printf("%02x", (unsigned int) h[i]);
ca16be
    }
ca16be
    printf("\n");
ca16be
    crypto_hash_sha256(h, x2, sizeof x2 - 1U);
ca16be
    for (i = 0; i < crypto_hash_sha256_BYTES; ++i) {
ca16be
        printf("%02x", (unsigned int) h[i]);
ca16be
    }
ca16be
    printf("\n");
ca16be
ca16be
    assert(crypto_hash_bytes() > 0U);
ca16be
    assert(strcmp(crypto_hash_primitive(), "sha512") == 0);
ca16be
    assert(crypto_hash_sha256_bytes() > 0U);
ca16be
    assert(crypto_hash_sha512_bytes() >= crypto_hash_sha256_bytes());
ca16be
    assert(crypto_hash_sha512_bytes() == crypto_hash_bytes());
ca16be
    assert(crypto_hash_sha256_statebytes() == sizeof(crypto_hash_sha256_state));
ca16be
    assert(crypto_hash_sha512_statebytes() == sizeof(crypto_hash_sha512_state));
ca16be
ca16be
    return 0;
ca16be
}