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

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