/*-
 * Copyright(C) 2017-2021. Huawei Technologies Co.,Ltd. All Rights Reserved.
 * Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
 * Copyright 2017 Ribose Inc. All Rights Reserved.
 *
 * Licensed under the Apache License 2.0 (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */

#ifndef _SM3_H_
#define _SM3_H_

#include "crypt-port.h"

#include <stddef.h>
#include <stdint.h>

/*
 * Use #defines in order to avoid namespace collisions with anyone else's
 * SM3 code (e.g., the code in OpenSSL).
 */
#define SM3_Init libcperciva_SM3_Init
#define SM3_Update libcperciva_SM3_Update
#define SM3_Final libcperciva_SM3_Final
#define SM3_Buf libcperciva_SM3_Buf
#define SM3_CTX libcperciva_SM3_CTX

/* Context structure for SM3 operations. */
typedef struct {
	uint32_t state[8];
	uint64_t count;
	uint8_t buf[64];
} SM3_CTX;

/**
 * SM3_Init(ctx):
 * Initialize the SM3 context ${ctx}.
 */
void SM3_Init(SM3_CTX *);

/**
 * SM3_Update(ctx, in, len):
 * Input ${len} bytes from ${in} into the SM3 context ${ctx}.
 */
void SM3_Update(SM3_CTX *, const void *, size_t);

/**
 * SM3_Final(digest, ctx):
 * Output the SM3 hash of the data input to the context ${ctx} into the
 * buffer ${digest}.
 */
void SM3_Final(uint8_t[32], SM3_CTX *);

/**
 * SM3_Buf(in, len, digest):
 * Compute the SM3 hash of ${len} bytes from ${in} and write it to ${digest}.
 */
void SM3_Buf(const void *, size_t, uint8_t[32]);

#endif /* !_SM3_H_ */