• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_HEADER_H
17 #define RECORD_HEADER_H
18 
19 #include <stdint.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #define REC_TLS_RECORD_HEADER_LEN 5u
26 #define REC_TLS_RECORD_LENGTH_OFFSET 3
27 #define REC_TLS_SN_MAX_VALUE (~((uint64_t)0))       /* TLS sequence number wrap Threshold */
28 
29 #ifdef HITLS_TLS_PROTO_DTLS12
30 
31 #define REC_IP_UDP_HEAD_SIZE 28                     /* IP protocol header 20 + UDP header 8 */
32 #define REC_DTLS_RECORD_HEADER_LEN 13
33 #define REC_DTLS_RECORD_EPOCH_OFFSET 3
34 #define REC_DTLS_RECORD_LENGTH_OFFSET 11
35 /* DTLS sequence number cannot be greater than this value. Otherwise, it will wrapped */
36 #define REC_DTLS_SN_MAX_VALUE 0xFFFFFFFFFFFFllu
37 
38 #define REC_SEQ_GET(n)      ((n) & 0x0000FFFFFFFFFFFFull)
39 #define REC_EPOCH_GET(n)    ((uint16_t)((n) >> 48))
40 #define REC_EPOCHSEQ_CAL(epoch, seq) (((uint64_t)(epoch) << 48) | (seq))
41 /* Epoch cannot be greater than this value. Otherwise, it will wrapped */
42 #define REC_EPOCH_MAX_VALUE 0xFFFFu
43 
44 #endif
45 
46 typedef struct {
47     uint8_t type;
48     uint8_t reverse[3];     /* Reserved, 4-byte aligned */
49     uint16_t version;
50     uint16_t bodyLen;       /* body length */
51 
52 #ifdef HITLS_TLS_PROTO_DTLS12
53     uint64_t epochSeq;      /* only for dtls */
54 #endif
55 } RecHdr;
56 
57 #ifdef __cplusplus
58 }
59 #endif
60 
61 #endif /* RECORD_HEADER_H */
62