hash.c 817 Bytes
Newer Older
lwc-tester committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
//  hash.c
//  2019-02-20  Markku-Juhani O. Saarinen <mjos@pqshield.com>
//  Copyright (C) 2019, PQShield Ltd. Please see LICENSE.

//  Reference SNEIKHA hash using the BLNK calls

#include "api.h"
#include "crypto_hash.h"
#include "blnk.h"

//  Single-call NIST interface

int crypto_hash(
    unsigned char *out,
    const unsigned char *in,
    unsigned long long inlen)
{
    blnk_t  ctx;                        //  Local state

    //  Clear state, set parameters
    blnk_clr(&ctx, SNEIKHA_RATE, SNEIKHA_ROUNDS);

    //  Process input
    blnk_put(&ctx, BLNK_AD, in, (size_t) inlen);
    blnk_fin(&ctx, BLNK_AD);

    //  Get the hash
    blnk_get(&ctx, BLNK_HASH, out, CRYPTO_BYTES);

    //  blnk_fin(&ctx, BLNK_HASH);      //  For intermediate hashes

    return 0;                           //  Success
}