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 COMMON_FUNC_H 17 #define COMMON_FUNC_H 18 19 #include <stdatomic.h> 20 #include "hlt_type.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 typedef enum { 27 EE_CERT, 28 PRIVE_KEY, 29 CA_CERT, 30 CHAIN_CERT 31 } CERT_TYPE; 32 33 typedef struct { 34 atomic_int mallocCnt; 35 atomic_int freeCnt; 36 atomic_int mallocSize; 37 atomic_int freeSize; 38 atomic_int maxMemSize; 39 } MemCnt; 40 41 /** 42 * @brief Load a certificate from a file. 43 */ 44 int LoadCertFromFile(void *ctx, char *pCert, CERT_TYPE certType); 45 46 /** 47 * @brief Memory application that contains the count 48 */ 49 void *CountMalloc(uint32_t len); 50 51 /** 52 * @brief Memory release that contains the count 53 */ 54 void CountFree(void *addr); 55 56 /** 57 * @brief Clear the memory count. 58 */ 59 void ClearMemCntData(void); 60 61 /** 62 * @brief Obtain the memory count. 63 */ 64 MemCnt *GetMemCntData(void); 65 66 int32_t ExampleSetPsk(char *psk); 67 68 uint32_t ExampleClientCb(HITLS_Ctx *ctx, const uint8_t *hint, uint8_t *identity, uint32_t maxIdentityLen, 69 uint8_t *psk, uint32_t maxPskLen); 70 71 uint32_t ExampleServerCb(HITLS_Ctx *ctx, const uint8_t *identity, uint8_t *psk, uint32_t maxPskLen); 72 73 int32_t ExampleTicketKeySuccessCb(uint8_t *keyName, uint32_t keyNameSize, void *cipher, uint8_t isEncrypt); 74 int32_t ExampleTicketKeyRenewCb(uint8_t *keyName, uint32_t keyNameSize, void *cipher, uint8_t isEncrypt); 75 void *GetTicketKeyCb(char *str); 76 77 void *GetExtensionCb(const char *str); 78 void *GetExampleData(const char *str); 79 80 #ifdef __cplusplus 81 } 82 #endif 83 84 #endif // COMMON_FUNC_H