• 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_SCRYPT_H
17 #define CRYPT_SCRYPT_H
18 
19 #include "hitls_build.h"
20 #ifdef HITLS_CRYPTO_SCRYPT
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 CryptScryptCtx CRYPT_SCRYPT_Ctx;
31 
32 typedef int32_t (*PBKDF2_PRF)(const EAL_MacMethod *macMeth, CRYPT_MAC_AlgId macId,
33     const EAL_MdMethod *mdMeth, const uint8_t *key, uint32_t keyLen,
34     const uint8_t *salt, uint32_t saltLen,
35     uint32_t iterCnt, uint8_t *out, uint32_t len);
36 
37 /**
38  * @ingroup  SCRYPT
39  * @brief Generate SCRYPT context.
40  *
41  * @retval Success: cipher ctx.
42  *         Fails: NULL.
43  */
44 CRYPT_SCRYPT_Ctx* CRYPT_SCRYPT_NewCtx(void);
45 
46 /**
47  * @ingroup SCRYPT
48  * @brief Set parameters for the SCRYPT context.
49  *
50  * @param ctx   [in, out] Pointer to the SCRYPT context.
51  * @param param [in] Either a MAC algorithm ID, a seed, a password, or a label.
52  *
53  * @retval Success: CRYPT_SUCCESS
54  *         For other error codes, see crypt_errno.h.
55  */
56 int32_t CRYPT_SCRYPT_SetParam(CRYPT_SCRYPT_Ctx *ctx, const BSL_Param *param);
57 
58 /**
59  * @ingroup SCRYPT
60  * @brief Obtain the derived key based on the passed SCRYPT context..
61  *
62  * @param ctx   [in, out] Pointer to the SCRYPT context.
63  * @param out   [out] Derived key buffer.
64  * @param len   [in] Derived key buffer size.
65  *
66  * @retval Success: CRYPT_SUCCESS
67  *         For other error codes, see crypt_errno.h.
68  */
69 int32_t CRYPT_SCRYPT_Derive(CRYPT_SCRYPT_Ctx *ctx, uint8_t *out, uint32_t len);
70 
71 /**
72  * @ingroup SCRYPT
73  * @brief SCRYPT deinitialization API
74  *
75  * @param ctx [in, out]   Pointer to the SCRYPT context.
76  *
77  * @retval #CRYPT_SUCCESS       Deinitialization succeeded.
78  * @retval #CRYPT_NULL_INPUT    Pointer ctx is NULL
79  */
80 int32_t CRYPT_SCRYPT_Deinit(CRYPT_SCRYPT_Ctx *ctx);
81 
82 /**
83  * @ingroup SCRYPT
84  * @brief free SCRYPT context.
85  *
86  * @param ctx [IN] SCRYPT handle
87  */
88 void CRYPT_SCRYPT_FreeCtx(CRYPT_SCRYPT_Ctx *ctx);
89 
90 #ifdef __cplusplus
91 }
92 #endif // __cplusplus
93 
94 #endif // HITLS_CRYPTO_SCRYPT
95 
96 #endif // CRYPT_SCRYPT_H
97