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 #include "hitls_build.h" 16 #include "hitls_crypt_reg.h" 17 #include "crypt_default.h" 18 HITLS_CryptMethodInit(void)19void HITLS_CryptMethodInit(void) 20 { 21 #ifdef HITLS_TLS_CALLBACK_CRYPT 22 HITLS_CRYPT_BaseMethod baseMethod = {0}; 23 baseMethod.randBytes = CRYPT_DEFAULT_RandomBytes; 24 baseMethod.hmacSize = CRYPT_DEFAULT_HMAC_Size; 25 #ifdef HITLS_TLS_CALLBACK_CRYPT_HMAC_PRIMITIVES 26 baseMethod.hmacInit = CRYPT_DEFAULT_HMAC_Init; 27 baseMethod.hmacReinit = CRYPT_DEFAULT_HMAC_ReInit; 28 baseMethod.hmacFree = CRYPT_DEFAULT_HMAC_Free; 29 baseMethod.hmacUpdate = CRYPT_DEFAULT_HMAC_Update; 30 baseMethod.hmacFinal = CRYPT_DEFAULT_HMAC_Final; 31 #endif 32 baseMethod.hmac = CRYPT_DEFAULT_HMAC; 33 baseMethod.digestSize = CRYPT_DEFAULT_DigestSize; 34 baseMethod.digestInit = CRYPT_DEFAULT_DigestInit; 35 baseMethod.digestCopy = CRYPT_DEFAULT_DigestCopy; 36 baseMethod.digestFree = CRYPT_DEFAULT_DigestFree; 37 baseMethod.digestUpdate = CRYPT_DEFAULT_DigestUpdate; 38 baseMethod.digestFinal = CRYPT_DEFAULT_DigestFinal; 39 baseMethod.digest = CRYPT_DEFAULT_Digest; 40 baseMethod.encrypt = CRYPT_DEFAULT_Encrypt; 41 baseMethod.decrypt = CRYPT_DEFAULT_Decrypt; 42 baseMethod.cipherFree = CRYPT_DEFAULT_CipherFree; 43 HITLS_CRYPT_RegisterBaseMethod(&baseMethod); 44 45 HITLS_CRYPT_EcdhMethod ecdhMethod = {0}; 46 ecdhMethod.generateEcdhKeyPair = CRYPT_DEFAULT_GenerateEcdhKey; 47 ecdhMethod.freeEcdhKey = CRYPT_DEFAULT_FreeKey; 48 ecdhMethod.getEcdhPubKey = CRYPT_DEFAULT_GetPubKey; 49 ecdhMethod.calcEcdhSharedSecret = CRYPT_DEFAULT_EcdhCalcSharedSecret; 50 #ifdef HITLS_TLS_PROTO_TLCP11 51 ecdhMethod.sm2CalEcdhSharedSecret = CRYPT_DEFAULT_CalcSM2SharedSecret; 52 #endif /* HITLS_TLS_PROTO_TLCP11 */ 53 #ifdef HITLS_TLS_FEATURE_KEM 54 ecdhMethod.kemEncapsulate = CRYPT_DEFAULT_KemEncapsulate; 55 ecdhMethod.kemDecapsulate = CRYPT_DEFAULT_KemDecapsulate; 56 #endif /* HITLS_TLS_FEATURE_KEM */ 57 HITLS_CRYPT_RegisterEcdhMethod(&ecdhMethod); 58 59 #ifdef HITLS_TLS_SUITE_KX_DHE 60 HITLS_CRYPT_DhMethod dhMethod = {0}; 61 dhMethod.generateDhKeyBySecbits = CRYPT_DEFAULT_GenerateDhKeyBySecbits; 62 dhMethod.generateDhKeyByParams = CRYPT_DEFAULT_GenerateDhKeyByParameters; 63 #ifdef HITLS_TLS_CONFIG_MANUAL_DH 64 dhMethod.dupDhKey = CRYPT_DEFAULT_DupKey; 65 #endif /* HITLS_TLS_CONFIG_MANUAL_DH */ 66 dhMethod.freeDhKey = CRYPT_DEFAULT_FreeKey; 67 dhMethod.getDhParameters = CRYPT_DEFAULT_GetDhParameters; 68 dhMethod.getDhPubKey = CRYPT_DEFAULT_GetPubKey; 69 dhMethod.calcDhSharedSecret = CRYPT_DEFAULT_DhCalcSharedSecret; 70 HITLS_CRYPT_RegisterDhMethod(&dhMethod); 71 #endif /* HITLS_TLS_SUITE_KX_DHE */ 72 73 #ifdef HITLS_TLS_PROTO_TLS13 74 HITLS_CRYPT_KdfMethod hkdfMethod = {0}; 75 hkdfMethod.hkdfExtract = CRYPT_DEFAULT_HkdfExtract; 76 hkdfMethod.hkdfExpand = CRYPT_DEFAULT_HkdfExpand; 77 HITLS_CRYPT_RegisterHkdfMethod(&hkdfMethod); 78 #endif 79 #endif /* HITLS_TLS_CALLBACK_CRYPT */ 80 }