blob: 1dfac143f7669680a67417903c391695df4eebad [file] [log] [blame]
Miguel Osorio43c73822019-09-13 01:54:26 -07001// Copyright lowRISC contributors.
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
Miguel Young de la Sota960fd8e2020-01-14 13:52:13 -05005#ifndef OPENTITAN_SW_DEVICE_LIB_HW_SHA256_H_
6#define OPENTITAN_SW_DEVICE_LIB_HW_SHA256_H_
Miguel Osorio43c73822019-09-13 01:54:26 -07007
8#include <stddef.h>
Miguel Osorio43c73822019-09-13 01:54:26 -07009
Miguel Osorio5759f272019-11-15 11:11:57 -080010#include "sw/vendor/cryptoc/include/cryptoc/hash-internal.h"
Miguel Osorio43c73822019-09-13 01:54:26 -070011
12typedef HASH_CTX HW_SHA256_CTX;
13
14#define SHA256_DIGEST_SIZE 32
15
16/**
Sam Elliott812eb332020-03-31 17:29:35 +010017 * hw_SHA256_init initializes `ctx`.
Miguel Osorio43c73822019-09-13 01:54:26 -070018 *
19 * @param ctx SHA256 context.
20 */
21void hw_SHA256_init(HW_SHA256_CTX *ctx);
22
23/**
Sam Elliott812eb332020-03-31 17:29:35 +010024 * hw_SHA256_update adds `len` bytes from `data` to `ctx`.
Miguel Osorio43c73822019-09-13 01:54:26 -070025 *
26 * @param ctx SHA256 context.
27 * @param data Input buffer.
28 * @param len Number of bytes to add.
29 */
30void hw_SHA256_update(HW_SHA256_CTX *ctx, const void *data, size_t len);
31
32/**
Sam Elliott812eb332020-03-31 17:29:35 +010033 * hw_SHA256_final adds the final padding to `ctx` and calculates digest.
Miguel Osorio43c73822019-09-13 01:54:26 -070034 *
35 * @param ctx SHA256 context.
36 *
Sam Elliott812eb332020-03-31 17:29:35 +010037 * @return pointer to digest buffer held in `ctx`.
Miguel Osorio43c73822019-09-13 01:54:26 -070038 */
39const uint8_t *hw_SHA256_final(HW_SHA256_CTX *ctx);
40
41/**
Sam Elliott812eb332020-03-31 17:29:35 +010042 * hw_SHA256_hash writes `digest` from `len` bytes of `data`.
Miguel Osorio43c73822019-09-13 01:54:26 -070043 *
44 * @param data Input buffer.
45 * @param len Number of bytes to add.
Sam Elliottff85e052020-08-28 12:58:55 +010046 * @param[out] digest Output buffer.
Miguel Osorio43c73822019-09-13 01:54:26 -070047 */
48const uint8_t *hw_SHA256_hash(const void *data, size_t len, uint8_t *digest);
49
Miguel Young de la Sota960fd8e2020-01-14 13:52:13 -050050#endif // OPENTITAN_SW_DEVICE_LIB_HW_SHA256_H_