#ifndef SHA3_H
#define SHA3_H

#include <Uefi.h>

#ifndef KECCAKF_ROUNDS
#define KECCAKF_ROUNDS 24
#endif

#ifndef ROTL64
#define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y))))
#endif

// state context
typedef struct {
    union {                                 // state:
        UINT8 b[200];                     // 8-bit bytes
        UINT64 q[25];                     // 64-bit words
    } st;
    INTN pt, rsiz, mdlen;                    // these don't overflow
} SHA3_CTX;

// Compression function.
VOID sha3_keccakf(UINT64 st[25]);

// OpenSSL - like interfece
INTN sha3_init(SHA3_CTX *c, INTN mdlen);    // mdlen = hash output in bytes
INTN sha3_update(SHA3_CTX *c, const VOID *data, UINTN len);
INTN sha3_final(VOID *md, SHA3_CTX *c);    // digest goes to md

// compute a sha3 hash (md) of given byte length from "in"
VOID *sha3(const VOID *in, UINTN inlen, VOID *md, UINTN mdlen);

#endif
