Miguel Osorio | 43c7382 | 2019-09-13 01:54:26 -0700 | [diff] [blame] | 1 | // 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 Sota | 960fd8e | 2020-01-14 13:52:13 -0500 | [diff] [blame] | 5 | #ifndef OPENTITAN_SW_DEVICE_LIB_HW_SHA256_H_ |
| 6 | #define OPENTITAN_SW_DEVICE_LIB_HW_SHA256_H_ |
Miguel Osorio | 43c7382 | 2019-09-13 01:54:26 -0700 | [diff] [blame] | 7 | |
| 8 | #include <stddef.h> |
Miguel Osorio | 43c7382 | 2019-09-13 01:54:26 -0700 | [diff] [blame] | 9 | |
Miguel Osorio | 5759f27 | 2019-11-15 11:11:57 -0800 | [diff] [blame] | 10 | #include "sw/vendor/cryptoc/include/cryptoc/hash-internal.h" |
Miguel Osorio | 43c7382 | 2019-09-13 01:54:26 -0700 | [diff] [blame] | 11 | |
| 12 | typedef HASH_CTX HW_SHA256_CTX; |
| 13 | |
| 14 | #define SHA256_DIGEST_SIZE 32 |
| 15 | |
| 16 | /** |
Sam Elliott | 812eb33 | 2020-03-31 17:29:35 +0100 | [diff] [blame] | 17 | * hw_SHA256_init initializes `ctx`. |
Miguel Osorio | 43c7382 | 2019-09-13 01:54:26 -0700 | [diff] [blame] | 18 | * |
| 19 | * @param ctx SHA256 context. |
| 20 | */ |
| 21 | void hw_SHA256_init(HW_SHA256_CTX *ctx); |
| 22 | |
| 23 | /** |
Sam Elliott | 812eb33 | 2020-03-31 17:29:35 +0100 | [diff] [blame] | 24 | * hw_SHA256_update adds `len` bytes from `data` to `ctx`. |
Miguel Osorio | 43c7382 | 2019-09-13 01:54:26 -0700 | [diff] [blame] | 25 | * |
| 26 | * @param ctx SHA256 context. |
| 27 | * @param data Input buffer. |
| 28 | * @param len Number of bytes to add. |
| 29 | */ |
| 30 | void hw_SHA256_update(HW_SHA256_CTX *ctx, const void *data, size_t len); |
| 31 | |
| 32 | /** |
Sam Elliott | 812eb33 | 2020-03-31 17:29:35 +0100 | [diff] [blame] | 33 | * hw_SHA256_final adds the final padding to `ctx` and calculates digest. |
Miguel Osorio | 43c7382 | 2019-09-13 01:54:26 -0700 | [diff] [blame] | 34 | * |
| 35 | * @param ctx SHA256 context. |
| 36 | * |
Sam Elliott | 812eb33 | 2020-03-31 17:29:35 +0100 | [diff] [blame] | 37 | * @return pointer to digest buffer held in `ctx`. |
Miguel Osorio | 43c7382 | 2019-09-13 01:54:26 -0700 | [diff] [blame] | 38 | */ |
| 39 | const uint8_t *hw_SHA256_final(HW_SHA256_CTX *ctx); |
| 40 | |
| 41 | /** |
Sam Elliott | 812eb33 | 2020-03-31 17:29:35 +0100 | [diff] [blame] | 42 | * hw_SHA256_hash writes `digest` from `len` bytes of `data`. |
Miguel Osorio | 43c7382 | 2019-09-13 01:54:26 -0700 | [diff] [blame] | 43 | * |
| 44 | * @param data Input buffer. |
| 45 | * @param len Number of bytes to add. |
Sam Elliott | ff85e05 | 2020-08-28 12:58:55 +0100 | [diff] [blame] | 46 | * @param[out] digest Output buffer. |
Miguel Osorio | 43c7382 | 2019-09-13 01:54:26 -0700 | [diff] [blame] | 47 | */ |
| 48 | const uint8_t *hw_SHA256_hash(const void *data, size_t len, uint8_t *digest); |
| 49 | |
Miguel Young de la Sota | 960fd8e | 2020-01-14 13:52:13 -0500 | [diff] [blame] | 50 | #endif // OPENTITAN_SW_DEVICE_LIB_HW_SHA256_H_ |