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 #ifndef REC_CRYPT_H 16 #define REC_CRYPT_H 17 #include "hitls_build.h" 18 #include "hitls_error.h" 19 #include "record.h" 20 #include "rec_conn.h" 21 22 #ifdef HITLS_TLS_PROTO_TLS 23 typedef struct { 24 REC_Type recordType; /* Protocol type */ 25 uint32_t plainLen; /* message length */ 26 uint8_t *plainData; /* message data */ 27 #ifdef HITLS_TLS_PROTO_TLS13 28 /* Length of the tls1.3 padding content. Currently, the value is 0. The value can be used as required */ 29 uint64_t recPaddingLength; 30 #endif 31 bool isTlsInnerPlaintext; /* Whether it is a TLSInnerPlaintext message for tls1.3 */ 32 } RecordPlaintext; /* Record protocol data before encryption */ 33 #else 34 typedef struct DtlsRecordPlaintext RecordPlaintext; 35 #endif 36 37 typedef uint32_t (*CalCiphertextLenFunc)(const TLS_Ctx *ctx, RecConnSuitInfo *suitInfo, 38 uint32_t plantextLen, bool isRead); 39 typedef int32_t (*CalPlantextBufLenFunc)(TLS_Ctx *ctx, RecConnSuitInfo *suitInfo, 40 uint32_t ciphertextLen, uint32_t *offset, uint32_t *plaintextLen); 41 typedef int32_t (*DecryptFunc)(TLS_Ctx *ctx, RecConnState *state, const REC_TextInput *cryptMsg, 42 uint8_t *data, uint32_t *dataLen); 43 typedef int32_t (*EncryptFunc)(TLS_Ctx *ctx, RecConnState *state, const REC_TextInput *plainMsg, 44 uint8_t *cipherText, uint32_t cipherTextLen); 45 typedef int32_t (*DecryptPostProcess)(TLS_Ctx *ctx, RecConnSuitInfo *suitInfo, REC_TextInput *cryptMsg, 46 uint8_t *data, uint32_t *dataLen); 47 typedef int32_t (*EncryptPreProcess)(TLS_Ctx *ctx, uint8_t recordType, const uint8_t *data, uint32_t plainLen, 48 RecordPlaintext *recPlaintext); 49 50 typedef struct { 51 CalCiphertextLenFunc calCiphertextLen; 52 CalPlantextBufLenFunc calPlantextBufLen; 53 DecryptFunc decrypt; 54 DecryptPostProcess decryptPostProcess; 55 EncryptFunc encryt; 56 EncryptPreProcess encryptPreProcess; 57 } RecCryptoFunc; 58 59 const RecCryptoFunc *RecGetCryptoFuncs(const RecConnSuitInfo *suiteInfo); 60 #endif