dtls13_misc.h
Go to the documentation of this file.
1 /**
2  * @file dtls13_misc.h
3  * @brief DTLS 1.3 (Datagram Transport Layer Security)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSSL Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.6.2
29  **/
30 
31 #ifndef _DTLS13_MISC_H
32 #define _DTLS13_MISC_H
33 
34 //Dependencies
35 #include "tls/tls.h"
36 
37 //Maximum number of retransmissions
38 #ifndef DTLS13_MAX_ACK_RECORDS
39  #define DTLS13_MAX_ACK_RECORDS 32
40 #elif (DTLS13_MAX_ACK_RECORDS < 1)
41  #error DTLS13_MAX_ACK_RECORDS parameter is not valid
42 #endif
43 
44 //DTLS 1.3 unified header
45 #define DTLS13_HEADER_MASK 0xE0
46 #define DTLS13_HEADER_FIXED 0x20
47 #define DTLS13_HEADER_FLAG_C 0x10
48 #define DTLS13_HEADER_FLAG_S 0x08
49 #define DTLS13_HEADER_FLAG_L 0x04
50 #define DTLS13_HEADER_FLAG_E 0x03
51 
52 //C++ guard
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 //CC-RX, CodeWarrior or Win32 compiler?
58 #if defined(__CCRX__)
59  #pragma pack
60 #elif defined(__CWCC__) || defined(_WIN32)
61  #pragma pack(push, 1)
62 #endif
63 
64 
65 /**
66  * @brief Record number
67  **/
68 
70 {
71  uint64_t epoch; //0-7
72  uint64_t seqNum; //8-15
74 
75 
76 /**
77  * @brief ACK message
78  **/
79 
80 typedef __packed_struct
81 {
82  uint16_t length; //0-1
85 
86 
87 //CC-RX, CodeWarrior or Win32 compiler?
88 #if defined(__CCRX__)
89  #pragma unpack
90 #elif defined(__CWCC__) || defined(_WIN32)
91  #pragma pack(pop)
92 #endif
93 
94 
95 /**
96  * @brief Retransmission state
97  **/
98 
99 typedef struct
100 {
101  uint64_t start;
104  uint32_t mask;
106 
107 
108 //DTLS 1.3 specific functions
109 void dtls13SaveRecordNumber(TlsContext *context, uint64_t epoch,
110  uint64_t seqNum);
111 
113 
115  size_t *length);
116 
118  size_t length);
119 
120 void dtls13FormatNonce(TlsEncryptionEngine *encryptionEngine,
121  const DtlsSequenceNumber *seqNum, uint8_t *nonce, size_t *nonceLen);
122 
123 size_t dtls13ComputeEncryptionOverhead(TlsEncryptionEngine *encryptionEngine);
124 
125 //C++ guard
126 #ifdef __cplusplus
127 }
128 #endif
129 
130 #endif
Dtls13Ack
Definition: dtls13_misc.h:84
void dtls13SaveRecordNumber(TlsContext *context, uint64_t epoch, uint64_t seqNum)
Update the list of record numbers.
Definition: dtls13_misc.c:53
error_t dtls13FormatAck(TlsContext *context, Dtls13Ack *message, size_t *length)
Format ACK message.
Definition: dtls13_misc.c:190
uint8_t message[]
Definition: chap.h:154
typedef __packed_struct
Record number.
Definition: dtls13_misc.h:70
void dtls13FormatNonce(TlsEncryptionEngine *encryptionEngine, const DtlsSequenceNumber *seqNum, uint8_t *nonce, size_t *nonceLen)
Format nonce.
Definition: dtls13_misc.c:381
uint64_t seqNum
Definition: dtls13_misc.h:72
size_t dtls13ComputeEncryptionOverhead(TlsEncryptionEngine *encryptionEngine)
Compute overhead caused by encryption.
Definition: dtls13_misc.c:416
Dtls13RecordNumber
Definition: dtls13_misc.h:73
Dtls13RecordNumber recordNumbers[]
Definition: dtls13_misc.h:83
Retransmission state.
Definition: dtls13_misc.h:100
#define TlsContext
Definition: tls.h:36
error_t
Error codes.
Definition: error.h:43
uint16_t epoch
Definition: dtls_misc.h:181
uint8_t length
Definition: tcp.h:375
error_t dtls13SendAck(TlsContext *context)
Send ACK message.
Definition: dtls13_misc.c:117
DtlsSequenceNumber
Definition: dtls_misc.h:148
TLS (Transport Layer Security)
error_t dtls13ParseAck(TlsContext *context, const Dtls13Ack *message, size_t length)
Parse ACK message.
Definition: dtls13_misc.c:257
unsigned int uint_t
Definition: compiler_port.h:57
#define TlsEncryptionEngine
Definition: tls.h:40
uint8_t nonce[]
Definition: ntp_common.h:239