/*
 * SHA-256 (FIPS 180-4) and HMAC-SHA-256 (RFC 2104).
 *
 * Written for LanMan98; placed in the public domain.  The interface
 * deliberately matches md5.h, which is what the rest of this module
 * already uses, so the two can be swapped by name.
 *
 * SMB2 signs with HMAC-SHA-256 over the whole message.  Nothing else
 * here needs a SHA, so this is the smallest implementation that is
 * still readable rather than the fastest one.
 *   Portions Copyright RISC OS Developments 2019+, credited to the RISC OS One Project.
 */

#ifndef _SHA512_
#define _SHA512_

#include <stdlib.h>

#define SHA512_RESULTLEN (64)
#define SHA512_BLOCKLEN  (128)

typedef unsigned long long sha512_uint64;

struct sha512_context
{
    sha512_uint64 state[8];
    sha512_uint64 count;            /* message length in bytes */
    unsigned char buffer[SHA512_BLOCKLEN];
    unsigned int  used;             /* bytes currently in buffer */
};

void sha512_init(struct sha512_context *ctx);
void sha512_update(struct sha512_context *ctx, const void *data, size_t size);
void sha512_final(struct sha512_context *ctx,
                  unsigned char result[SHA512_RESULTLEN]);

void sha512_get_digest(const void *data, size_t size,
                       unsigned char result[SHA512_RESULTLEN]);
/*
    Wanted for SMB 3.1.1's pre-authentication integrity hash, which is a
    running digest over the negotiate and session setup messages that then
    feeds the key derivation.  There is no HMAC here because nothing asks
    for one: the hash is used bare, as the context of a derivation.
*/

#endif
