blob: 36f0651397e8a03b109846a6d79829093dcb82e8 [file] [log] [blame]
// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
#ifndef _F_LIB_SHA256_H__
#define _F_LIB_SHA256_H__
#include <stddef.h>
#include <stdint.h>
#include "sw/vendor/cryptoc/hash-internal.h"
typedef HASH_CTX HW_SHA256_CTX;
#define SHA256_DIGEST_SIZE 32
/**
* hw_SHA256_init initializes |ctx|.
*
* @param ctx SHA256 context.
*/
void hw_SHA256_init(HW_SHA256_CTX *ctx);
/**
* hw_SHA256_update adds |len| bytes from |data| to |ctx|.
*
* @param ctx SHA256 context.
* @param data Input buffer.
* @param len Number of bytes to add.
*/
void hw_SHA256_update(HW_SHA256_CTX *ctx, const void *data, size_t len);
/**
* hw_SHA256_final adds the final padding to |ctx| and calculates digest.
*
* @param ctx SHA256 context.
*
* @return pointer to digest buffer held in |ctx|.
*/
const uint8_t *hw_SHA256_final(HW_SHA256_CTX *ctx);
/**
* hw_SHA256_hash writes |digest| from |len| bytes of |data|.
*
* @param data Input buffer.
* @param len Number of bytes to add.
* @param digest Output buffer.
*/
const uint8_t *hw_SHA256_hash(const void *data, size_t len, uint8_t *digest);
#endif // _F_LIB_SHA256_H__