API参考
载入中...
搜索中...
未找到
record.h
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 RECORD_H
17#define RECORD_H
18
19#include "tls.h"
20#include "rec.h"
21#include "rec_header.h"
22#include "rec_unprocessed_msg.h"
23#include "rec_buf.h"
24#include "rec_conn.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#define REC_MAX_PLAIN_TEXT_LENGTH 16384 /* Plain content length */
31
32#define REC_MAX_ENCRYPTED_OVERHEAD 2048u /* Maximum Encryption Overhead rfc5246 */
33#ifdef HITLS_TLS_FEATURE_RECORD_SIZE_LIMIT
34#define REC_MAX_READ_ENCRYPTED_OVERHEAD (256u + 64u) /* Maximum Encryption Overhead maxPadding + max(iv + mac) */
35#define REC_MAX_WRITE_ENCRYPTED_OVERHEAD (16u + 64u) /* Maximum Encryption Overhead minPadding + max(iv + mac) */
36#else
37#define REC_MAX_READ_ENCRYPTED_OVERHEAD REC_MAX_ENCRYPTED_OVERHEAD
38#define REC_MAX_WRITE_ENCRYPTED_OVERHEAD REC_MAX_ENCRYPTED_OVERHEAD
39#endif /* HITLS_TLS_FEATURE_RECORD_SIZE_LIMIT */
40#define REC_MAX_CIPHER_TEXT_LEN (REC_MAX_PLAIN_LENGTH + REC_MAX_ENCRYPTED_OVERHEAD) /* Maximum ciphertext length */
41
42#define REC_MAX_AES_GCM_ENCRYPTION_LIMIT 23726566u /* RFC 8446 5.5 Limits on Key Usage AES-GCM SHOULD under 2^24.5 */
43
44typedef struct {
45 RecConnState *outdatedState;
46 RecConnState *currentState;
47 RecConnState *pendingState;
49
50typedef int32_t (*REC_ReadFunc)(TLS_Ctx *, REC_Type, uint8_t *, uint32_t *, uint32_t);
51typedef int32_t (*REC_WriteFunc)(TLS_Ctx *, REC_Type, const uint8_t *, uint32_t);
52typedef struct {
53 ListHead head; /* Linked list header */
54 bool isExistCcsMsg; /* Check whether CCS messages exist in the retransmission message queue */
55 REC_Type type; /* message type */
56 uint8_t *msg; /* message data */
57 uint32_t len; /* message length */
59
60typedef struct RecCtx {
61 RecBuf *inBuf; /* Buffer for reading data */
62 RecBuf *outBuf; /* Buffer for writing data */
63 RecConnStates readStates;
64 RecConnStates writeStates;
65 RecBufList *hsRecList; /* hs plaintext data cache */
66 RecBufList *appRecList; /* app plaintext data cache */
67 uint32_t emptyRecordCnt; /* Count of empty records */
68#ifdef HITLS_TLS_PROTO_DTLS12
69 uint16_t writeEpoch;
70 uint16_t readEpoch;
71
72 RecRetransmitList retransmitList; /* Cache the messages that may be retransmitted during the handshake */
73
74 /* Process out-of-order messages */
75 UnprocessedHsMsg unprocessedHsMsg; /* used to cache out-of-order finished messages */
76 /* unprocessed app message: app messages received in the CCS and finished receiving phases */
77 UnprocessedAppMsg unprocessedAppMsgList;
78#endif
79 REC_ReadFunc recRead;
80 void *rUserData;
81 REC_WriteFunc recWrite;
82 void *wUserData;
83 REC_Type unexpectedMsgType;
84 uint32_t pendingDataSize; /* Data length */
85 const uint8_t *pendingData; /* Plain Data content */
86} RecCtx;
87
88
97uint32_t RecGetInitBufferSize(const TLS_Ctx *ctx, bool isRead);
98
99int32_t RecDerefBufList(TLS_Ctx *ctx);
100
107void RecTryFreeRecBuf(TLS_Ctx *ctx, bool isOut);
108
119int32_t RecIoBufInit(TLS_Ctx *ctx, RecCtx *recordCtx, bool isRead);
120#ifdef __cplusplus
121}
122#endif
123
124#endif /* RECORD_H */
定义 rec_buf.h:27
定义 rec_conn.h:67
定义 record.h:44
定义 record.h:60
定义 record.h:52