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 #ifndef CRYPT_PBKDF2_H 17 #define CRYPT_PBKDF2_H 18 19 #include "hitls_build.h" 20 #ifdef HITLS_CRYPTO_PBKDF2 21 22 #include <stdint.h> 23 #include "crypt_local_types.h" 24 #include "bsl_params.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif // __cplusplus 29 30 typedef struct CryptPbkdf2Ctx CRYPT_PBKDF2_Ctx; 31 32 /** 33 * @ingroup PBKDF2 34 * @brief Generate PBKDF2 context. 35 * 36 * @retval Success: cipher ctx. 37 * Fails: NULL. 38 */ 39 CRYPT_PBKDF2_Ctx* CRYPT_PBKDF2_NewCtx(void); 40 41 /** 42 * @ingroup PBKDF2 43 * @brief Set parameters for the PBKDF2 context. 44 * 45 * @param ctx [in, out] Pointer to the PBKDF2 context. 46 * @param param [in] Either a MAC algorithm ID, a salt, a password, or an iteration count. 47 * 48 * @retval Success: CRYPT_SUCCESS 49 * For other error codes, see crypt_errno.h. 50 */ 51 int32_t CRYPT_PBKDF2_SetParam(CRYPT_PBKDF2_Ctx *ctx, const BSL_Param *param); 52 53 /** 54 * @ingroup PBKDF2 55 * @brief Obtain the derived key based on the passed PBKDF2 context.. 56 * 57 * @param ctx [in, out] Pointer to the PBKDF2 context. 58 * @param out [out] Derived key buffer. 59 * @param out [out] Derived key buffer size. 60 * 61 * @retval Success: CRYPT_SUCCESS 62 * For other error codes, see crypt_errno.h. 63 */ 64 int32_t CRYPT_PBKDF2_Derive(CRYPT_PBKDF2_Ctx *ctx, uint8_t *out, uint32_t len); 65 66 /** 67 * @ingroup PBKDF2 68 * @brief PBKDF2 deinitialization API 69 * 70 * @param ctx [in, out] Pointer to the PBKDF2 context. 71 * 72 * @retval #CRYPT_SUCCESS Deinitialization succeeded. 73 * @retval #CRYPT_NULL_INPUT Pointer ctx is NULL 74 */ 75 int32_t CRYPT_PBKDF2_Deinit(CRYPT_PBKDF2_Ctx *ctx); 76 77 /** 78 * @ingroup PBKDF2 79 * @brief free PBKDF2 context. 80 * 81 * @param ctx [IN] PBKDF2 handle 82 */ 83 void CRYPT_PBKDF2_FreeCtx(CRYPT_PBKDF2_Ctx *ctx); 84 85 #ifdef __cplusplus 86 } 87 #endif // __cplusplus 88 89 #endif // HITLS_CRYPTO_PBKDF2 90 91 #endif // CRYPT_PBKDF2_H 92