blob: d8783591b84b66ba9297bc2ee779f216a7b50d5c [file] [log] [blame]
lowRISC Contributors802543a2019-08-31 12:12:56 +01001// 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_HMAC_H_
6#define OPENTITAN_SW_DEVICE_LIB_HMAC_H_
lowRISC Contributors802543a2019-08-31 12:12:56 +01007
8#include <stddef.h>
9#include <stdint.h>
10
Miguel Osorio06f18b22019-09-13 14:25:15 -070011/**
12 * Supported HMAC operations
13 */
14typedef enum hmac_ops { HMAC_OP_HMAC = 0, HMAC_OP_SHA256 = 1 } hmac_ops_t;
lowRISC Contributors802543a2019-08-31 12:12:56 +010015
Miguel Osorio06f18b22019-09-13 14:25:15 -070016/**
17 * HMAC Configuration options.
18 */
lowRISC Contributors802543a2019-08-31 12:12:56 +010019typedef struct hmac_cfg {
Miguel Osorio06f18b22019-09-13 14:25:15 -070020 /** Operational mode @see hmac_ops. */
lowRISC Contributors802543a2019-08-31 12:12:56 +010021 hmac_ops_t mode;
Miguel Osorio06f18b22019-09-13 14:25:15 -070022 /** Set to 1 to swap input bytes. */
lowRISC Contributors802543a2019-08-31 12:12:56 +010023 uint32_t input_endian_swap;
Miguel Osorio06f18b22019-09-13 14:25:15 -070024 /** Set to 1 to swap output bytes. */
lowRISC Contributors802543a2019-08-31 12:12:56 +010025 uint32_t digest_endian_swap;
Miguel Osorio06f18b22019-09-13 14:25:15 -070026 /** Input key used in HMAC mode. */
lowRISC Contributors802543a2019-08-31 12:12:56 +010027 uint32_t keys[8];
28} hmac_cfg_t;
29
Miguel Osorio06f18b22019-09-13 14:25:15 -070030/**
31 * Intialize HMAC to desired mode.
32 *
33 * @param hmac_cfg HMAC configuration settings.
34 */
lowRISC Contributors802543a2019-08-31 12:12:56 +010035void hmac_init(hmac_cfg_t hmac_cfg);
36
Miguel Osorio06f18b22019-09-13 14:25:15 -070037/**
Sam Elliott812eb332020-03-31 17:29:35 +010038 * Write `size_in_bytes` bytes of `data` to HMAC input buffer
Miguel Osorio06f18b22019-09-13 14:25:15 -070039 *
40 * @param data pointer to input buffer.
Tim Shepardae281b62019-10-17 10:33:33 -040041 * @param size_in_bytes number of bytes to write.
Miguel Osorio06f18b22019-09-13 14:25:15 -070042 */
Miguel Osorio068002c2019-09-13 11:20:39 -070043void hmac_update(const void *data, size_t size_in_bytes);
lowRISC Contributors802543a2019-08-31 12:12:56 +010044
Miguel Osorio06f18b22019-09-13 14:25:15 -070045/**
46 * Poll for hmac done and read out digest.
47 *
Tim Shepardae281b62019-10-17 10:33:33 -040048 * @param digest pointer to output digest buffer.
Miguel Osorio06f18b22019-09-13 14:25:15 -070049 */
Miguel Osorio068002c2019-09-13 11:20:39 -070050void hmac_done(uint32_t *digest);
lowRISC Contributors802543a2019-08-31 12:12:56 +010051
Miguel Young de la Sota960fd8e2020-01-14 13:52:13 -050052#endif // OPENTITAN_SW_DEVICE_LIB_HMAC_H_