1 /* 2 * This file is part of the openHiTLS project. 3 * 4 * openHiTLS is licensed under the Mulan PSL v2. 5 * You can use this software according to the terms and conditions of the Mulan PSL v2. 6 * You may obtain a copy of Mulan PSL v2 at: 7 * 8 * http://license.coscl.org.cn/MulanPSL2 9 * 10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13 * See the Mulan PSL v2 for more details. 14 */ 15 16 /** 17 * @defgroup crypt_eal_kdf 18 * @ingroup crypt 19 * @brief kdf of crypto module 20 */ 21 22 #ifndef CRYPT_EAL_KDF_H 23 #define CRYPT_EAL_KDF_H 24 25 #include <stdbool.h> 26 #include <stdint.h> 27 #include "crypt_algid.h" 28 #include "crypt_types.h" 29 #include "bsl_params.h" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif // __cplusplus 34 35 typedef struct EalKdfCtx CRYPT_EAL_KdfCTX; 36 37 /** 38 * @ingroup crypt_eal_kdf 39 * @brief Generate kdf handles in the providers 40 * 41 * @param libCtx [IN] Library context 42 * @param attrName [IN] Specify expected attribute values 43 * @param algId [IN] kdf algorithm ID. 44 * @retval Success: cipher ctx. 45 * Fails: NULL. 46 */ 47 CRYPT_EAL_KdfCTX *CRYPT_EAL_ProviderKdfNewCtx(CRYPT_EAL_LibCtx *libCtx, int32_t algId, const char *attrName); 48 49 /** 50 * @ingroup crypt_eal_kdf 51 * @brief Generate kdf handles 52 * @param algId [IN] kdf algorithm ID. 53 * @retval Success: cipher ctx. 54 * Fails: NULL. 55 */ 56 CRYPT_EAL_KdfCTX *CRYPT_EAL_KdfNewCtx(CRYPT_KDF_AlgId algId); 57 58 /** 59 * @ingroup crypt_eal_kdf 60 * @brief Set the parameters of Algorithm kdf 61 * 62 * @param ctx [IN] kdf context 63 * @param param [IN] parameters 64 * 65 * @retval #CRYPT_SUCCESS. 66 * For other error codes, see crypt_errno.h. 67 */ 68 int32_t CRYPT_EAL_KdfSetParam(CRYPT_EAL_KdfCTX *ctx, const BSL_Param *param); 69 70 /** 71 * @ingroup crypt_eal_kdf 72 * @brief Derived key 73 * 74 * @param ctx [IN] kdf context 75 * @param key [OUT] Derived key 76 * @param keyLen [IN] Specify the key derivation length 77 * 78 * @retval #CRYPT_SUCCESS. 79 * For other error codes, see crypt_errno.h. 80 */ 81 int32_t CRYPT_EAL_KdfDerive(CRYPT_EAL_KdfCTX *ctx, uint8_t *key, uint32_t keyLen); 82 83 /** 84 * @ingroup crypt_eal_kdf 85 * @brief Deinitialize the context of kdf 86 * 87 * @param ctx [IN] kdf context 88 * 89 * @retval #CRYPT_SUCCESS. 90 * For other error codes, see crypt_errno.h. 91 */ 92 int32_t CRYPT_EAL_KdfDeInitCtx(CRYPT_EAL_KdfCTX *ctx); 93 94 /** 95 * @ingroup crypt_eal_kdf 96 * @brief Free the context of kdf 97 * 98 * @param ctx [IN] kdf context 99 * 100 */ 101 void CRYPT_EAL_KdfFreeCtx(CRYPT_EAL_KdfCTX *ctx); 102 103 #ifdef __cplusplus 104 } 105 #endif // __cplusplus 106 107 #endif // CRYPT_EAL_KDF_H