• 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 EAL_PKEY_H
17 #define EAL_PKEY_H
18 
19 #include "crypt_eal_pkey.h"
20 #include "crypt_eal_provider.h"
21 #include "crypt_local_types.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif // __cplusplus
26 
27 typedef struct {
28     int32_t algId;
29     CRYPT_EAL_ProvMgrCtx *mgrCtx;
30     EAL_PkeyUnitaryMethod *keyMgmtMethod;
31 } CRYPT_EAL_PkeyMgmtInfo;
32 
33 typedef struct {
34     CRYPT_EAL_ProvMgrCtx *mgrCtx;
35     const CRYPT_EAL_Func *funcsAsyCipher;
36     const CRYPT_EAL_Func *funcsExch;
37     const CRYPT_EAL_Func *funcSign;
38     const CRYPT_EAL_Func *funcKem;
39     const CRYPT_EAL_Func *funcsKeyMgmt;
40 } CRYPT_EAL_AsyAlgFuncsInfo;
41 
42 /**
43  * @ingroup crypt_eal_pkey
44  * @brief Create a new asymmetric key context by key management information.
45  *
46  * @param pkey [IN/OUT] The asymmetric key context to be created.
47  * @param pkeyAlgInfo [IN] The key management information.
48  * @param keyRef [IN] The reference to the key.
49  * @param keyRefLen [IN] The length of the key reference.
50  *
51  * @return CRYPT_SUCCESS on success, CRYPT_ERROR on failure.
52  */
53 CRYPT_EAL_PkeyCtx *CRYPT_EAL_MakeKeyByPkeyAlgInfo(CRYPT_EAL_PkeyMgmtInfo *pkeyAlgInfo, void *keyRef,
54     uint32_t keyRefLen);
55 
56 /**
57  * @ingroup crypt_eal_pkey
58  * @brief Get the key management information by algorithm ID and attribute name.
59  *
60  * @param libCtx [IN] The library context.
61  * @param algId [IN] The algorithm ID.
62  * @param attrName [IN] The attribute name.
63  * @param pkeyAlgInfo [OUT] The key management information.
64  */
65 int32_t CRYPT_EAL_GetPkeyAlgInfo(CRYPT_EAL_LibCtx *libCtx, int32_t algId, const char *attrName,
66     CRYPT_EAL_PkeyMgmtInfo *pkeyAlgInfo);
67 
68 int32_t CRYPT_EAL_SetPkeyMethod(EAL_PkeyUnitaryMethod **pkeyMethod, const CRYPT_EAL_Func *funcsKeyMgmt,
69     const CRYPT_EAL_Func *funcsAsyCipher, const CRYPT_EAL_Func *funcsExch, const CRYPT_EAL_Func *funcSign,
70     const CRYPT_EAL_Func *funcKem);
71 
72 int32_t CRYPT_EAL_ProviderGetAsyAlgFuncs(CRYPT_EAL_LibCtx *libCtx, int32_t algId, uint32_t pkeyOperType,
73     const char *attrName, CRYPT_EAL_AsyAlgFuncsInfo *funcs);
74 #ifdef __cplusplus
75 }
76 #endif // __cplusplus
77 
78 #endif // EAL_PKEY_H
79