• 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_PROVIDER_H
17 #define CRYPT_PROVIDER_H
18 
19 #include "hitls_build.h"
20 #ifdef HITLS_CRYPTO_PROVIDER
21 
22 #include "crypt_eal_provider.h"
23 #include "crypt_eal_implprovider.h"
24 #include "bsl_list.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif /* __cpluscplus */
29 
30 #define CRYPT_EAL_DEFAULT_PROVIDER "default"
31 
32 // Maximum length of provider name
33 #define DEFAULT_PROVIDER_NAME_LEN_MAX 255
34 
35 typedef enum {
36     CRYPT_PROVIDER_GET_USER_CTX = 1,
37     CRYPT_PROVIDER_CTRL_MAX,
38 } CRYPT_ProviderCtrlCmd;
39 
40 struct EAL_LibCtx {
41     BslList *providers; // managing providers
42     BSL_SAL_ThreadLockHandle lock;
43     char *searchProviderPath;
44     void *drbg;
45 };
46 
47 #if defined(HITLS_CRYPTO_ENTROPY) &&                                                        \
48     (defined(HITLS_CRYPTO_ENTROPY_GETENTROPY) || defined(HITLS_CRYPTO_ENTROPY_DEVRANDOM) || \
49     defined(HITLS_CRYPTO_ENTROPY_SYS) || defined(HITLS_CRYPTO_ENTROPY_HARDWARE))
50 #define HITLS_CRYPTO_ENTROPY_DEFAULT
51 #endif
52 
53 int32_t CRYPT_EAL_InitPreDefinedProviders(void);
54 void CRYPT_EAL_FreePreDefinedProviders(void);
55 
56 int32_t CRYPT_EAL_DefaultProvInit(CRYPT_EAL_ProvMgrCtx *mgrCtx, BSL_Param *param,
57     CRYPT_EAL_Func *capFuncs, CRYPT_EAL_Func **outFuncs, void **provCtx);
58 
59 int32_t CRYPT_EAL_LoadPreDefinedProvider(CRYPT_EAL_LibCtx *libCtx, const char* providerName,
60     CRYPT_EAL_ProvMgrCtx **ctx);
61 
62 int32_t CRYPT_EAL_ProviderGetFuncsAndMgrCtx(CRYPT_EAL_LibCtx *libCtx, int32_t operaId, int32_t algId,
63     const char *attribute, const CRYPT_EAL_Func **funcs, CRYPT_EAL_ProvMgrCtx **mgrCtx);
64 
65 CRYPT_EAL_LibCtx* CRYPT_EAL_GetGlobalLibCtx(void);
66 
67 int32_t CRYPT_EAL_ProviderQuery(CRYPT_EAL_ProvMgrCtx *ctx, int32_t operaId, CRYPT_EAL_AlgInfo **algInfos);
68 #ifdef __cplusplus
69 }
70 #endif /* __cpluscplus */
71 
72 #endif /* HITLS_CRYPTO_PROVIDER */
73 #endif // CRYPT_SHA1_H
74