API参考
载入中...
搜索中...
未找到
rec.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 REC_H
17#define REC_H
18
19#include <stdbool.h>
20#include <stdint.h>
21#include "hitls_build.h"
22#include "hitls_crypt_type.h"
23#include "tls.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#define DTLS_MIN_MTU 256 /* Minimum MTU setting size */
30#define REC_MAX_PLAIN_LENGTH 16384 /* Maximum plain length */
31/* TLS13 Maximum MAC address padding */
32#define REC_MAX_TLS13_ENCRYPTED_OVERHEAD 256u
33/* TLS13 Maximum ciphertext length */
34#define REC_MAX_TLS13_ENCRYPTED_LEN (REC_MAX_PLAIN_LENGTH + REC_MAX_TLS13_ENCRYPTED_OVERHEAD)
35
36#define REC_MASTER_SECRET_LEN 48
37#define REC_RANDOM_LEN 32
38
39#define RECORD_HEADER 0x100
40#define RECORD_INNER_CONTENT_TYPE 0x101
41/*
42 * record type
43 */
44typedef enum {
45 REC_TYPE_CHANGE_CIPHER_SPEC = 20,
46 REC_TYPE_ALERT = 21,
47 REC_TYPE_HANDSHAKE = 22,
48 REC_TYPE_APP = 23,
49 REC_TYPE_UNKNOWN = 255
50} REC_Type;
51
52/*
53 * SecurityParameters, used to generate keys and initialize the connect state
54 */
55typedef struct {
56 bool isClient; /* Connection Endpoint */
57 bool isClientTrafficSecret; /* TrafficSecret type */
58 HITLS_HashAlgo prfAlg; /* prf_algorithm */
59 HITLS_MacAlgo macAlg; /* mac algorithm */
60 HITLS_CipherAlgo cipherAlg; /* symmetric encryption algorithm */
61 HITLS_CipherType cipherType; /* encryption algorithm type */
62
63 /* key length */
64 uint8_t fixedIvLength; /* iv length. In TLS1.2 AEAD algorithm is the implicit IV length */
65 uint8_t encKeyLen; /* Length of the symmetric key */
66 uint8_t macKeyLen; /* MAC key length: If the AEAD algorithm is used, the MAC key length is 0 */
67
68 uint8_t blockLength; /* If the block length is not zero, the alignment should be handled. */
69 uint8_t recordIvLength; /* The explicit IV needs to be sent to the peer */
70 uint8_t macLen; /* MAC length. For AEAD, it is the mark length */
71
72 uint8_t masterSecret[MAX_DIGEST_SIZE]; /* tls1.2 master key. TLS1.3 carries the TrafficSecret */
73 uint8_t clientRandom[REC_RANDOM_LEN]; /* Client random number */
74 uint8_t serverRandom[REC_RANDOM_LEN]; /* service random number */
76
88int32_t REC_Init(TLS_Ctx *ctx);
89
96void REC_DeInit(TLS_Ctx *ctx);
97
105bool REC_ReadHasPending(const TLS_Ctx *ctx);
106
128int32_t REC_Read(TLS_Ctx *ctx, REC_Type recordType, uint8_t *data, uint32_t *readLen, uint32_t num);
129
153int32_t REC_Write(TLS_Ctx *ctx, REC_Type recordType, const uint8_t *data, uint32_t num);
154
163void REC_ActiveOutdatedWriteState(TLS_Ctx *ctx);
164
173void REC_DeActiveOutdatedWriteState(TLS_Ctx *ctx);
174
187int32_t REC_InitPendingState(const TLS_Ctx *ctx, const REC_SecParameters *param);
188
201int32_t REC_ActivePendingState(TLS_Ctx *ctx, bool isOut);
202
211int32_t REC_QueryMtu(TLS_Ctx *ctx);
212
223int32_t REC_GetMaxWriteSize(const TLS_Ctx *ctx, uint32_t *len);
224
235int32_t REC_GetMaxDataMtu(const TLS_Ctx *ctx, uint32_t *len);
236
250int32_t REC_TLS13InitPendingState(const TLS_Ctx *ctx, const REC_SecParameters *param, bool isOut);
251
263int32_t REC_RetransmitListAppend(REC_Ctx *recCtx, REC_Type type, const uint8_t *msg, uint32_t len);
264
270void REC_RetransmitListClean(REC_Ctx *recCtx);
271
280int32_t REC_RetransmitListFlush(TLS_Ctx *ctx);
281
282REC_Type REC_GetUnexpectedMsgType(TLS_Ctx *ctx);
283
284bool REC_HaveReadSuiteInfo(const TLS_Ctx *ctx);
285
293uint32_t APP_GetReadPendingBytes(const TLS_Ctx *ctx);
294
295int32_t REC_RecOutBufReSet(TLS_Ctx *ctx);
296
306int32_t REC_FlightTransmit(TLS_Ctx *ctx);
307
315uint32_t REC_GetOutBufPendingSize(const TLS_Ctx *ctx);
316
325int32_t REC_OutBufFlush(TLS_Ctx *ctx);
326
327#ifdef __cplusplus
328}
329#endif
330
331#endif /* REC_H */
定义 rec.h:55