• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_HKDF_H
17 #define CRYPT_HKDF_H
18 
19 #include "hitls_build.h"
20 #ifdef HITLS_CRYPTO_HKDF
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 CryptHkdfCtx CRYPT_HKDF_Ctx;
31 
32 /**
33  * @ingroup HKDF
34  * @brief Generate HKDF context.
35  *
36  * @retval Success: cipher ctx.
37  *         Fails: NULL.
38  */
39 CRYPT_HKDF_Ctx* CRYPT_HKDF_NewCtx(void);
40 
41 /**
42  * @ingroup HKDF
43  * @brief Set parameters for the HKDF context.
44  *
45  * @param ctx   [in, out] Pointer to the HKDF 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_HKDF_SetParam(CRYPT_HKDF_Ctx *ctx, const BSL_Param *param);
52 
53 /**
54  * @ingroup HKDF
55  * @brief Obtain the derived key based on the passed HKDF context..
56  *
57  * @param ctx   [in, out] Pointer to the HKDF 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_HKDF_Derive(CRYPT_HKDF_Ctx *ctx, uint8_t *out, uint32_t len);
65 
66 /**
67  * @ingroup HKDF
68  * @brief HKDF deinitialization API
69  *
70  * @param ctx [in, out]   Pointer to the HKDF context.
71  *
72  * @retval #CRYPT_SUCCESS       Deinitialization succeeded.
73  * @retval #CRYPT_NULL_INPUT    Pointer ctx is NULL
74  */
75 int32_t CRYPT_HKDF_Deinit(CRYPT_HKDF_Ctx *ctx);
76 
77 /**
78  * @ingroup HKDF
79  * @brief free HKDF context.
80  *
81  * @param ctx [IN] HKDF handle
82  */
83 void CRYPT_HKDF_FreeCtx(CRYPT_HKDF_Ctx *ctx);
84 
85 #ifdef __cplusplus
86 }
87 #endif // __cplusplus
88 
89 #endif // HITLS_CRYPTO_HKDF
90 
91 #endif // CRYPT_HKDF_H
92