1 /* 2 * Copyright (C) 2018-2022 Intel Corporation. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 /** 8 * @file crypto_api.h 9 * 10 * @brief public APIs for crypto functions 11 */ 12 13 #ifndef CRYPTO_API_H 14 #define CRYPTO_API_H 15 16 #include <types.h> 17 18 /** 19 * @brief HMAC-based Extract-and-Expand Key Derivation Function. 20 * 21 * @param out_key Pointer to key buffer which is used to save 22 * hkdf_sha256 result 23 * @param out_len The length of out_key 24 * @param secret Pointer to input keying material 25 * @param secret_len The length of secret 26 * @param salt Pointer to salt buffer, it is optional 27 * if not provided (salt == NULL), it is set internally 28 * to a string of hashlen(32) zeros 29 * @param salt_len The length of the salt value 30 * Ignored if salt is NULL 31 * @param info Pointer to application specific information, it is 32 * optional. Ignored if info == NULL or a zero-length string 33 * @param info_len: The length of the info, ignored if info is NULL 34 * 35 * @return int32_t 1 - Success 0 - Failure 36 */ 37 int32_t hkdf_sha256(uint8_t *out_key, size_t out_len, 38 const uint8_t *secret, size_t secret_len, 39 const uint8_t *salt, size_t salt_len, 40 const uint8_t *info, size_t info_len); 41 42 /** 43 * @brief This function calculates the full generic HMAC 44 * on the input buffer with the provided key. 45 * 46 * The function allocates the context, performs the 47 * calculation, and frees the context. 48 * 49 * The HMAC result is calculated as 50 * output = generic HMAC(hmac key, input buffer). 51 * 52 * @param out_key The generic HMAC result 53 * @param secret The HMAC secret key 54 * @param secret_len The length of the HMAC secret key in Bytes 55 * @param salt The buffer holding the input data 56 * @param salt_len The length of the input data 57 * 58 * @return int32_t 1 - Success 0 - Failure 59 */ 60 int32_t hmac_sha256(uint8_t *out_key, 61 const uint8_t *secret, size_t secret_len, 62 const uint8_t *salt, size_t salt_len); 63 64 #endif /* CRYPTO_API_H */ 65