Software APIs
kmac.h
Go to the documentation of this file.
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_KMAC_H_
6 #define OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_KMAC_H_
7 
8 #include "datatypes.h"
9 
10 /**
11  * @file
12  * @brief Message authentication codes for the OpenTitan cryptography library.
13  *
14  * Supports message authentication based on either HMAC or KMAC.
15  */
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif // __cplusplus
20 
21 /**
22  * Performs the KMAC function on the input data.
23  *
24  * This function computes the KMAC on the `input_message` using the `key` and
25  * returns a `tag` of `required_output_len`. The customization string is passed
26  * through `customization_string` parameter. If no customization is desired it
27  * can be be left empty (by settings its `data` to NULL and `length` to 0).
28  *
29  * The caller should set the `key_length` field of `key.config` to the number
30  * of bytes in the key. Only the following key sizes (in bytes) are supported:
31  * [16, 24, 32, 48, 64]. If any other size is given, the function will return
32  * an error.
33  *
34  * The KMAC mode (KMAC-128 or KMAC-256) is inferred from the key mode.
35  *
36  * The caller should allocate enough space in the `tag` buffer to hold
37  * `required_output_len` bytes, rounded up to the nearest word, and then set
38  * the `len` field of `tag` to the word length. If the word length is not long
39  * enough to hold `required_output_len` bytes, then the function will return an
40  * error.
41  *
42  * @param key Pointer to the blinded key struct with key shares.
43  * @param input_message Input message to be hashed.
44  * @param customization_string Customization string.
45  * @param required_output_len Required output length, in bytes.
46  * @param[out] tag Output authentication tag.
47  * @return The result of the KMAC operation.
48  */
51  otcrypto_const_byte_buf_t input_message,
52  otcrypto_const_byte_buf_t customization_string,
53  size_t required_output_len,
55 
56 #ifdef __cplusplus
57 } // extern "C"
58 #endif // __cplusplus
59 
60 #endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_KMAC_H_