• 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 #include <stdint.h>
17 #include <stdlib.h>
18 #include <stdio.h>
19 #include <stdbool.h>
20 #include "hitls_build.h"
21 #include "cert_callback.h"
22 #include "bsl_sal.h"
23 #include "bsl_log.h"
24 #include "bsl_err.h"
25 #include "crypt_algid.h"
26 #include "hitls_crypt_init.h"
27 #include "crypt_eal_rand.h"
28 #include "hitls_cert_init.h"
29 #include "bsl_log.h"
30 
StdMalloc(uint32_t len)31 static void *StdMalloc(uint32_t len)
32 {
33     return malloc((uint32_t)len);
34 }
35 
StdFree(void * addr)36 static void StdFree(void *addr)
37 {
38     free(addr);
39 }
40 
StdMallocFail(uint32_t len)41 static void *StdMallocFail(uint32_t len)
42 {
43     (void)len;
44     return NULL;
45 }
46 
47 void BinLogFixLenFunc(uint32_t logId, uint32_t logLevel, uint32_t logType,
48     void *format, void *para1, void *para2, void *para3, void *para4);
49 
50 void BinLogVarLenFunc(uint32_t logId, uint32_t logLevel, uint32_t logType, void *format, void *para);
FRAME_Init(void)51 void FRAME_Init(void)
52 {
53     BSL_SAL_CallBack_Ctrl(BSL_SAL_MEM_MALLOC, StdMalloc);
54     BSL_SAL_CallBack_Ctrl(BSL_SAL_MEM_FREE, StdFree);
55     BSL_ERR_Init();
56 #ifdef TLS_DEBUG
57     BSL_LOG_SetBinLogLevel(BSL_LOG_LEVEL_DEBUG);
58     BSL_LOG_BinLogFuncs logFunc = { BinLogFixLenFunc, BinLogVarLenFunc };
59     BSL_LOG_RegBinLogFunc(&logFunc);
60 #endif
61 #ifdef HITLS_TLS_FEATURE_PROVIDER
62     CRYPT_EAL_ProviderRandInitCtx(NULL, CRYPT_RAND_SHA256, "provider=default", NULL, 0, NULL);
63 #else
64     CRYPT_EAL_RandInit(CRYPT_RAND_SHA256, NULL, NULL, NULL, 0);
65     HITLS_CertMethodInit();
66     HITLS_CryptMethodInit();
67 #endif
68     return;
69 }
70 
FRAME_DeInit(void)71 void FRAME_DeInit(void)
72 {
73     BSL_SAL_CallBack_Ctrl(BSL_SAL_MEM_MALLOC, StdMallocFail);
74     BSL_SAL_CallBack_Ctrl(BSL_SAL_MEM_FREE, StdFree);
75 
76     BSL_ERR_DeInit();
77     return;
78 }