ipsec.h
Go to the documentation of this file.
1 /**
2  * @file ipsec.h
3  * @brief IPsec (IP security)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2022-2026 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneIPSEC 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.6
29  **/
30 
31 #ifndef _IPSEC_H
32 #define _IPSEC_H
33 
34 //Forward declaration of IpsecSadEntry structure
35 struct _IpsecSadEntry;
36 #define IpsecSadEntry struct _IpsecSadEntry
37 
38 //Forward declaration of IpsecContext structure
39 struct _IpsecContext;
40 #define IpsecContext struct _IpsecContext
41 
42 //Dependencies
43 #include "ipsec_config.h"
44 #include "core/net.h"
45 #include "core/udp.h"
46 #include "core/tcp.h"
47 #include "ipv4/icmp.h"
48 #include "core/crypto.h"
49 #include "ah/ah.h"
50 #include "esp/esp.h"
53 #include "hash/hash_algorithms.h"
54 #include "mac/mac_algorithms.h"
55 
56 
57 /*
58  * CycloneIPSEC Open is licensed under GPL version 2. In particular:
59  *
60  * - If you link your program to CycloneIPSEC Open, the result is a derivative
61  * work that can only be distributed under the same GPL license terms.
62  *
63  * - If additions or changes to CycloneIPSEC Open are made, the result is a
64  * derivative work that can only be distributed under the same license terms.
65  *
66  * - The GPL license requires that you make the source code available to
67  * whoever you make the binary available to.
68  *
69  * - If you sell or distribute a hardware product that runs CycloneIPSEC Open,
70  * the GPL license requires you to provide public and full access to all
71  * source code on a nondiscriminatory basis.
72  *
73  * If you fully understand and accept the terms of the GPL license, then edit
74  * the os_port_config.h header and add the following directive:
75  *
76  * #define GPL_LICENSE_TERMS_ACCEPTED
77  */
78 
79 #ifndef GPL_LICENSE_TERMS_ACCEPTED
80  #error Before compiling CycloneIPSEC Open, you must accept the terms of the GPL license
81 #endif
82 
83 //Version string
84 #define CYCLONE_IPSEC_VERSION_STRING "2.6.6"
85 //Major version
86 #define CYCLONE_IPSEC_MAJOR_VERSION 2
87 //Minor version
88 #define CYCLONE_IPSEC_MINOR_VERSION 6
89 //Revision number
90 #define CYCLONE_IPSEC_REV_NUMBER 6
91 
92 //IPsec support
93 #ifndef IPSEC_SUPPORT
94  #define IPSEC_SUPPORT ENABLED
95 #elif (IPSEC_SUPPORT != ENABLED && IPSEC_SUPPORT != DISABLED)
96  #error IPSEC_SUPPORT parameter is not valid
97 #endif
98 
99 //Anti-replay mechanism
100 #ifndef IPSEC_ANTI_REPLAY_SUPPORT
101  #define IPSEC_ANTI_REPLAY_SUPPORT ENABLED
102 #elif (IPSEC_ANTI_REPLAY_SUPPORT != ENABLED && IPSEC_ANTI_REPLAY_SUPPORT != DISABLED)
103  #error IPSEC_ANTI_REPLAY_SUPPORT parameter is not valid
104 #endif
105 
106 //Size of the sliding window for replay protection
107 #ifndef IPSEC_ANTI_REPLAY_WINDOW_SIZE
108  #define IPSEC_ANTI_REPLAY_WINDOW_SIZE 64
109 #elif (IPSEC_ANTI_REPLAY_WINDOW_SIZE < 1)
110  #error IPSEC_ANTI_REPLAY_WINDOW_SIZE parameter is not valid
111 #endif
112 
113 //Maximum length of ID
114 #ifndef IPSEC_MAX_ID_LEN
115  #define IPSEC_MAX_ID_LEN 64
116 #elif (IPSEC_MAX_ID_LEN < 0)
117  #error IPSEC_MAX_ID_LEN is not valid
118 #endif
119 
120 //Maximum length of pre-shared keys
121 #ifndef IPSEC_MAX_PSK_LEN
122  #define IPSEC_MAX_PSK_LEN 64
123 #elif (IPSEC_MAX_PSK_LEN < 0)
124  #error IPSEC_MAX_PSK_LEN is not valid
125 #endif
126 
127 //Maximum length of encryption keys
128 #ifndef IPSEC_MAX_ENC_KEY_LEN
129  #define IPSEC_MAX_ENC_KEY_LEN 36
130 #elif (IPSEC_MAX_ENC_KEY_LEN < 1)
131  #error IPSEC_MAX_ENC_KEY_LEN parameter is not valid
132 #endif
133 
134 //Maximum length of integrity protection keys
135 #ifndef IPSEC_MAX_AUTH_KEY_LEN
136  #define IPSEC_MAX_AUTH_KEY_LEN 64
137 #elif (IPSEC_MAX_AUTH_KEY_LEN < 1)
138  #error IPSEC_MAX_AUTH_KEY_LEN parameter is not valid
139 #endif
140 
141 //UDP port number used by IPsec NAT traversal
142 #define IPSEC_NAT_PORT 4500
143 
144 //Size of SPI for AH and ESP protocols
145 #define IPSEC_SPI_SIZE 4
146 
147 //ANY protocol selector
148 #define IPSEC_PROTOCOL_ANY 0
149 
150 //ANY port selector
151 #define IPSEC_PORT_START_ANY 0
152 #define IPSEC_PORT_END_ANY 65535
153 
154 //OPAQUE port selector
155 #define IPSEC_PORT_START_OPAQUE 65535
156 #define IPSEC_PORT_END_OPAQUE 0
157 
158 //ICMP port selector
159 #define IPSEC_ICMP_PORT(type, code) (((type) * 256) + (code))
160 
161 //C++ guard
162 #ifdef __cplusplus
163 extern "C" {
164 #endif
165 
166 
167 /**
168  * @brief Direction
169  **/
170 
171 typedef enum
172 {
177 
178 
179 /**
180  * @brief Authentication methods
181  **/
182 
183 typedef enum
184 {
190 
191 
192 /**
193  * @brief Security protocols
194  **/
195 
196 typedef enum
197 {
202 
203 
204 /**
205  * @brief IPsec protocol modes
206  **/
207 
208 typedef enum
209 {
214 
215 
216 /**
217  * @brief ID types
218  **/
219 
220 typedef enum
221 {
222  IPSEC_ID_TYPE_IPV4_ADDR = 1, ///<IPv4 address
223  IPSEC_ID_TYPE_FQDN = 2, ///<Fully-qualified domain name
224  IPSEC_ID_TYPE_RFC822_ADDR = 3, ///<RFC 822 email address
225  IPSEC_ID_TYPE_IPV6_ADDR = 5, ///<IPv6 address
226  IPSEC_ID_TYPE_DN = 9, ///<X.500 distinguished name
227  IPSEC_ID_TYPE_KEY_ID = 11 ///<Key ID
229 
230 
231 /**
232  * @brief Policy action
233  **/
234 
235 typedef enum
236 {
242 
243 
244 /**
245  * @brief PFP flags
246  **/
247 
248 typedef enum
249 {
256 
257 
258 /**
259  * @brief DF flag policy
260  **/
261 
262 typedef enum
263 {
268 
269 
270 /**
271  * @brief IPsec SAD entry state
272  **/
273 
274 typedef enum
275 {
280 
281 
282 /**
283  * @brief IP address range
284  **/
285 
286 typedef struct
287 {
291 
292 
293 /**
294  * @brief Port range
295  **/
296 
297 typedef struct
298 {
299  uint16_t start;
300  uint16_t end;
302 
303 
304 /**
305  * @brief IPsec selector
306  **/
307 
308 typedef struct
309 {
310  IpsecAddrRange localIpAddr; ///<Local IP address range
311  IpsecAddrRange remoteIpAddr; ///<Remote IP address range
312  uint8_t nextProtocol; ///<Next layer protocol
313  IpsecPortRange localPort; ///<Local port range
314  IpsecPortRange remotePort; ///<Remote port range
315 } IpsecSelector;
316 
317 
318 /**
319  * @brief IP packet information
320  **/
321 
322 typedef struct
323 {
324  IpAddr localIpAddr; ///<Local IP address
325  IpAddr remoteIpAddr; ///<Remote IP address
326  uint8_t nextProtocol; ///<Next layer protocol
327  uint16_t localPort; ///<Local port
328  uint16_t remotePort; ///<Remote port
330 
331 
332 /**
333  * @brief IPsec ID
334  **/
335 
336 typedef union
337 {
338  char_t fqdn[IPSEC_MAX_ID_LEN + 1]; ///<Fully-qualified domain name
339  char_t email[IPSEC_MAX_ID_LEN + 1]; ///<RFC 822 email address
340  uint8_t dn[IPSEC_MAX_ID_LEN]; ///<X.500 Distinguished Name
341  uint8_t keyId[IPSEC_MAX_ID_LEN]; ///<Key ID
342  IpsecAddrRange ipAddr; ///<IPv4 or IPv6 address range
343 } IpsecId;
344 
345 
346 /**
347  * @brief Security Policy Database (SPD) entry
348  **/
349 
350 typedef struct
351 {
352  IpsecPolicyAction policyAction; ///<Processing choice (DISCARD, BYPASS or PROTECT)
353  uint_t pfpFlags; ///<PFP flags
354  IpsecSelector selector; ///<Traffic selector
355  IpsecMode mode; ///<IPsec mode (tunnel or transport)
356  IpsecProtocol protocol; ///<Security protocol (AH or ESP)
357  bool_t esn; ///<Extended sequence numbers
358  bool_t pfs; ///<Perfect forward secrecy
359  IpAddr localTunnelAddr; ///<Local tunnel IP address
360  IpAddr remoteTunnelAddr; ///<Remote tunnel IP address
361 } IpsecSpdEntry;
362 
363 
364 /**
365  * @brief Security Association Database (SAD) entry
366  **/
367 
369 {
370  IpsecSaState state; ///<SAD entry state
371  IpsecDirection direction; ///<Direction
372  IpsecMode mode; ///<IPsec mode (tunnel or transport)
373  IpsecProtocol protocol; ///<Security protocol (AH or ESP)
374  IpsecSelector selector; ///<Traffic selector
375  IpsecDfPolicy dfPolicy; ///<DF flag policy
376  uint32_t spi; ///<Security parameter index
377 #if (ESP_SUPPORT == ENABLED)
378  CipherMode cipherMode; ///<Cipher mode of operation
379  const CipherAlgo *cipherAlgo; ///<Cipher algorithm
380  CipherContext cipherContext; ///<Cipher context
381  uint8_t encKey[IPSEC_MAX_ENC_KEY_LEN]; ///<Encryption key
382  size_t encKeyLen; ///<Length of the encryption key, in bytes
383  size_t saltLen; ///<Length of the salt, in bytes
384  uint8_t iv[16]; ///<Initialization vector
385  size_t ivLen; ///<Length of the initialization vector, in bytes
386 #endif
387 #if (ESP_SUPPORT == ENABLED && ESP_UDP_ENCAPS_SUPPORT == ENABLED)
388  bool_t udpEncapsulation; ///<UDP encapsulation of IPsec ESP packets
389 #endif
390  MacAlgo authMacAlgo; ///<MAC algorithm for integrity calculations
391  const HashAlgo *authHashAlgo; ///<Hash algorithm for HMAC-based integrity calculations
392  const CipherAlgo *authCipherAlgo; ///<Cipher algorithm for CMAC-based integrity calculations
393  uint8_t authKey[IPSEC_MAX_AUTH_KEY_LEN]; ///<Integrity protection key
394  size_t authKeyLen; ///<Length of the integrity protection key, in bytes
395  size_t icvLen; ///<Length of the ICV tag, in bytes
396  bool_t esn; ///<Extended sequence numbers
397  uint64_t seqNum; ///<Sequence number counter
398  systime_t lifetimeStart; ///<Timestamp
399 #if (IPSEC_ANTI_REPLAY_SUPPORT == ENABLED)
400  bool_t antiReplayEnabled; ///<Anti-replay mechanism enabled
401  uint32_t antiReplayWindow[(IPSEC_ANTI_REPLAY_WINDOW_SIZE + 31) / 32]; ///<Anti-replay window
402 #endif
403  IpAddr tunnelDestIpAddr; ///<Tunnel header IP destination address
404 };
405 
406 
407 /**
408  * @brief Peer Authorization Database (PAD) entry
409  **/
410 
411 typedef struct
412 {
413  IpsecAuthMethod authMethod; ///<Authentication method (IKEv1, IKEv2, KINK)
414  IpsecIdType idType; ///<ID type
415  IpsecId id; ///<ID
416  size_t idLen; ///<Length of the ID, in bytes
417  uint8_t psk[IPSEC_MAX_PSK_LEN]; ///<Pre-shared key
418  size_t pskLen; ///<Length of the pre-shared key, in bytes
419  const char_t *trustedCaList; ///Trusted CA list (PEM format)
420  size_t trustedCaListLen; ///<Total length of the trusted CA list
421 } IpsecPadEntry;
422 
423 
424 /**
425  * @brief IPsec settings
426  **/
427 
428 typedef struct
429 {
430  NetContext *netContext; ///<TCP/IP stack context
431  const PrngAlgo *prngAlgo; ///<Pseudo-random number generator to be used
432  void *prngContext; ///<Pseudo-random number generator context
433  IpsecSpdEntry *spdEntries; ///<Security Policy Database (SPD)
434  uint_t numSpdEntries; ///<Number of entries in the SPD database
435  IpsecSadEntry *sadEntries; ///<Security Association Database (SAD)
436  uint_t numSadEntries; ///<Number of entries in the SAD database
437  IpsecPadEntry *padEntries; ///<Peer Authorization Database (PAD)
438  uint_t numPadEntries; ///<Number of entries in the PAD database
439 } IpsecSettings;
440 
441 
442 /**
443  * @brief IPsec context
444  **/
445 
447 {
448  NetContext *netContext; ///<TCP/IP stack context
449  const PrngAlgo *prngAlgo; ///<Pseudo-random number generator to be used
450  void *prngContext; ///<Pseudo-random number generator context
451  IpsecSpdEntry *spd; ///<Security Policy Database (SPD)
452  uint_t numSpdEntries; ///<Number of entries in the SPD database
453  IpsecSadEntry *sad; ///<Security Association Database (SAD)
454  uint_t numSadEntries; ///<Number of entries in the SAD database
455  IpsecPadEntry *pad; ///<Peer Authorization Database (PAD)
456  uint_t numPadEntries; ///<Number of entries in the PAD database
457  MacContext macContext; ///<MAC context
458 #if (ESP_SUPPORT == ENABLED)
459  uint8_t buffer[ESP_BUFFER_SIZE]; ///<Memory buffer for input/output operations
460 #endif
461 };
462 
463 
464 //IPsec related functions
465 void ipsecGetDefaultSettings(IpsecSettings *settings);
466 
467 error_t ipsecInit(IpsecContext *context, const IpsecSettings *settings);
468 
470  IpsecSpdEntry *params);
471 
473 
475  IpsecSadEntry *params);
476 
478 
480  IpsecPadEntry *params);
481 
483 
484 void ipsecDeinit(IpsecContext *context);
485 
486 //C++ guard
487 #ifdef __cplusplus
488 }
489 #endif
490 
491 #endif
uint_t numPadEntries
Number of entries in the PAD database.
Definition: ipsec.h:456
IpsecAddrRange ipAddr
IPv4 or IPv6 address range.
Definition: ipsec.h:342
@ IPSEC_ID_TYPE_KEY_ID
Key ID.
Definition: ipsec.h:227
#define NetContext
Definition: net.h:36
@ IPSEC_DIR_INVALID
Definition: ipsec.h:173
const PrngAlgo * prngAlgo
Pseudo-random number generator to be used.
Definition: ipsec.h:449
IpsecMode
IPsec protocol modes.
Definition: ipsec.h:209
int bool_t
Definition: compiler_port.h:63
uint_t numSadEntries
Number of entries in the SAD database.
Definition: ipsec.h:436
size_t icvLen
Length of the ICV tag, in bytes.
Definition: ipsec.h:395
uint16_t end
Definition: ipsec.h:300
@ IPSEC_SA_STATE_CLOSED
Definition: ipsec.h:276
@ IPSEC_ID_TYPE_IPV4_ADDR
IPv4 address.
Definition: ipsec.h:222
uint_t numSadEntries
Number of entries in the SAD database.
Definition: ipsec.h:454
@ IPSEC_DIR_INBOUND
Definition: ipsec.h:174
@ IPSEC_PROTOCOL_AH
Definition: ipsec.h:199
@ IPSEC_AUTH_METHOD_KINK
Definition: ipsec.h:188
uint32_t spi
Security parameter index.
Definition: ipsec.h:376
IPsec selector.
Definition: ipsec.h:309
IP network address.
Definition: ip.h:94
#define PrngAlgo
Definition: crypto.h:1140
IpsecSelector selector
Traffic selector.
Definition: ipsec.h:374
void * prngContext
Pseudo-random number generator context.
Definition: ipsec.h:432
IpsecDirection
Direction.
Definition: ipsec.h:172
const CipherAlgo * authCipherAlgo
Cipher algorithm for CMAC-based integrity calculations.
Definition: ipsec.h:392
IpsecSpdEntry * spd
Security Policy Database (SPD)
Definition: ipsec.h:451
IpsecIdType
ID types.
Definition: ipsec.h:221
Collection of cipher algorithms.
IpAddr remoteIpAddr
Remote IP address.
Definition: ipsec.h:325
Generic cipher algorithm context.
bool_t antiReplayEnabled
Anti-replay mechanism enabled.
Definition: ipsec.h:400
IpAddr end
Definition: ipsec.h:289
size_t pskLen
Length of the pre-shared key, in bytes.
Definition: ipsec.h:418
@ IPSEC_PFP_FLAG_REMOTE_ADDR
Definition: ipsec.h:251
#define IPSEC_MAX_ENC_KEY_LEN
Definition: ipsec.h:129
IpsecId id
ID.
Definition: ipsec.h:415
#define IPSEC_ANTI_REPLAY_WINDOW_SIZE
Definition: ipsec.h:108
systime_t lifetimeStart
Timestamp.
Definition: ipsec.h:398
#define ESP_BUFFER_SIZE
Definition: esp.h:277
@ IPSEC_PFP_FLAG_LOCAL_ADDR
Definition: ipsec.h:250
uint8_t authKey[IPSEC_MAX_AUTH_KEY_LEN]
Integrity protection key.
Definition: ipsec.h:393
@ IPSEC_MODE_TUNNEL
Definition: ipsec.h:211
bool_t udpEncapsulation
UDP encapsulation of IPsec ESP packets.
Definition: ipsec.h:388
IPsec context.
Definition: ipsec.h:447
#define IPSEC_MAX_AUTH_KEY_LEN
Definition: ipsec.h:136
@ IPSEC_POLICY_ACTION_PROTECT
Definition: ipsec.h:240
@ IPSEC_ID_TYPE_RFC822_ADDR
RFC 822 email address.
Definition: ipsec.h:224
@ IPSEC_PROTOCOL_ESP
Definition: ipsec.h:200
void * prngContext
Pseudo-random number generator context.
Definition: ipsec.h:450
@ IPSEC_DIR_OUTBOUND
Definition: ipsec.h:175
Peer Authorization Database (PAD) entry.
Definition: ipsec.h:412
uint16_t remotePort
Remote port.
Definition: ipsec.h:328
bool_t esn
Extended sequence numbers.
Definition: ipsec.h:396
ESP (IP Encapsulating Security Payload)
uint64_t seqNum
Sequence number counter.
Definition: ipsec.h:397
IpsecSadEntry * sadEntries
Security Association Database (SAD)
Definition: ipsec.h:435
IpAddr localTunnelAddr
Local tunnel IP address.
Definition: ipsec.h:359
ICMP (Internet Control Message Protocol)
IpsecAuthMethod authMethod
Authentication method (IKEv1, IKEv2, KINK)
Definition: ipsec.h:413
uint8_t nextProtocol
Next layer protocol.
Definition: ipsec.h:326
uint8_t nextProtocol
Next layer protocol.
Definition: ipsec.h:312
uint16_t localPort
Local port.
Definition: ipsec.h:327
@ IPSEC_MODE_TRANSPORT
Definition: ipsec.h:212
@ IPSEC_DF_POLICY_COPY
Definition: ipsec.h:266
error_t
Error codes.
Definition: error.h:43
@ IPSEC_ID_TYPE_FQDN
Fully-qualified domain name.
Definition: ipsec.h:223
IpsecPolicyAction
Policy action.
Definition: ipsec.h:236
MacAlgo authMacAlgo
MAC algorithm for integrity calculations.
Definition: ipsec.h:390
uint8_t encKey[IPSEC_MAX_ENC_KEY_LEN]
Encryption key.
Definition: ipsec.h:381
IpsecPolicyAction policyAction
Processing choice (DISCARD, BYPASS or PROTECT)
Definition: ipsec.h:352
@ IPSEC_PFP_FLAG_REMOTE_PORT
Definition: ipsec.h:254
IpsecPortRange remotePort
Remote port range.
Definition: ipsec.h:314
@ IPSEC_POLICY_ACTION_DISCARD
Definition: ipsec.h:238
IpsecProtocol protocol
Security protocol (AH or ESP)
Definition: ipsec.h:356
@ IPSEC_AUTH_METHOD_IKEV1
Definition: ipsec.h:186
Security Association Database (SAD) entry.
Definition: ipsec.h:369
IpsecSadEntry * sad
Security Association Database (SAD)
Definition: ipsec.h:453
@ IPSEC_ID_TYPE_IPV6_ADDR
IPv6 address.
Definition: ipsec.h:225
size_t saltLen
Length of the salt, in bytes.
Definition: ipsec.h:383
General definitions for cryptographic algorithms.
IpAddr tunnelDestIpAddr
Tunnel header IP destination address.
Definition: ipsec.h:403
void ipsecDeinit(IpsecContext *context)
Release IPsec context.
Definition: ipsec.c:401
uint32_t antiReplayWindow[(IPSEC_ANTI_REPLAY_WINDOW_SIZE+31)/32]
Anti-replay window.
Definition: ipsec.h:401
@ IPSEC_AUTH_METHOD_IKEV2
Definition: ipsec.h:187
IpsecPadEntry * padEntries
Peer Authorization Database (PAD)
Definition: ipsec.h:437
Block cipher modes of operation.
const CipherAlgo * cipherAlgo
Cipher algorithm.
Definition: ipsec.h:379
IpsecSaState state
SAD entry state.
Definition: ipsec.h:370
IpsecDfPolicy
DF flag policy.
Definition: ipsec.h:263
bool_t pfs
Perfect forward secrecy.
Definition: ipsec.h:358
size_t trustedCaListLen
Trusted CA list (PEM format)
Definition: ipsec.h:420
IpsecMode mode
IPsec mode (tunnel or transport)
Definition: ipsec.h:355
const HashAlgo * authHashAlgo
Hash algorithm for HMAC-based integrity calculations.
Definition: ipsec.h:391
IpsecDirection direction
Direction.
Definition: ipsec.h:371
@ IPSEC_DF_POLICY_SET
Definition: ipsec.h:265
error_t ipsecClearSpdEntry(IpsecContext *context, uint_t index)
Clear entry at specified index in SPD database.
Definition: ipsec.c:176
uint_t pfpFlags
PFP flags.
Definition: ipsec.h:353
IpsecIdType idType
ID type.
Definition: ipsec.h:414
AH (IP Authentication Header)
IpsecProtocol
Security protocols.
Definition: ipsec.h:197
IpAddr start
Definition: ipsec.h:288
const PrngAlgo * prngAlgo
Pseudo-random number generator to be used.
Definition: ipsec.h:431
#define IpsecSadEntry
Definition: ipsec.h:36
const char_t * trustedCaList
Definition: ipsec.h:419
uint16_t start
Definition: ipsec.h:299
Collection of hash algorithms.
NetContext * netContext
TCP/IP stack context.
Definition: ipsec.h:448
uint32_t systime_t
System time.
IPsec ID.
Definition: ipsec.h:337
error_t ipsecClearPadEntry(IpsecContext *context, uint_t index)
Clear entry at specified index in PAD database.
Definition: ipsec.c:378
bool_t esn
Extended sequence numbers.
Definition: ipsec.h:357
@ IPSEC_DF_POLICY_CLEAR
Definition: ipsec.h:264
char char_t
Definition: compiler_port.h:55
size_t idLen
Length of the ID, in bytes.
Definition: ipsec.h:416
size_t authKeyLen
Length of the integrity protection key, in bytes.
Definition: ipsec.h:394
IpsecPfpFlags
PFP flags.
Definition: ipsec.h:249
IpsecPadEntry * pad
Peer Authorization Database (PAD)
Definition: ipsec.h:455
Port range.
Definition: ipsec.h:298
#define IPSEC_MAX_ID_LEN
Definition: ipsec.h:115
TCP (Transmission Control Protocol)
uint_t numPadEntries
Number of entries in the PAD database.
Definition: ipsec.h:438
uint8_t iv[16]
Initialization vector.
Definition: ipsec.h:384
IP packet information.
Definition: ipsec.h:323
uint_t numSpdEntries
Number of entries in the SPD database.
Definition: ipsec.h:434
IpsecAddrRange localIpAddr
Local IP address range.
Definition: ipsec.h:310
@ IPSEC_POLICY_ACTION_INVALID
Definition: ipsec.h:237
IpAddr localIpAddr
Local IP address.
Definition: ipsec.h:324
@ IPSEC_PFP_FLAG_NEXT_PROTOCOL
Definition: ipsec.h:252
uint_t numSpdEntries
Number of entries in the SPD database.
Definition: ipsec.h:452
UDP (User Datagram Protocol)
@ IPSEC_ID_TYPE_DN
X.500 distinguished name.
Definition: ipsec.h:226
CipherMode cipherMode
Cipher mode of operation.
Definition: ipsec.h:378
IpAddr remoteTunnelAddr
Remote tunnel IP address.
Definition: ipsec.h:360
@ IPSEC_PFP_FLAG_LOCAL_PORT
Definition: ipsec.h:253
#define IpsecContext
Definition: ipsec.h:40
Common interface for encryption algorithms.
Definition: crypto.h:1285
@ IPSEC_POLICY_ACTION_BYPASS
Definition: ipsec.h:239
#define IPSEC_MAX_PSK_LEN
Definition: ipsec.h:122
Collection of MAC algorithms.
@ IPSEC_MODE_INVALID
Definition: ipsec.h:210
@ IPSEC_AUTH_METHOD_INVALID
Definition: ipsec.h:185
void ipsecGetDefaultSettings(IpsecSettings *settings)
Initialize settings with default values.
Definition: ipsec.c:48
IpsecProtocol protocol
Security protocol (AH or ESP)
Definition: ipsec.h:373
IpsecSaState
IPsec SAD entry state.
Definition: ipsec.h:275
Common interface for hash algorithms.
Definition: crypto.h:1243
IP address range.
Definition: ipsec.h:287
error_t ipsecSetSpdEntry(IpsecContext *context, uint_t index, IpsecSpdEntry *params)
Set entry at specified index in SPD database.
Definition: ipsec.c:150
error_t ipsecSetPadEntry(IpsecContext *context, uint_t index, IpsecPadEntry *params)
Set entry at specified index in PAD database.
Definition: ipsec.c:352
IpsecAuthMethod
Authentication methods.
Definition: ipsec.h:184
Security Policy Database (SPD) entry.
Definition: ipsec.h:351
unsigned int uint_t
Definition: compiler_port.h:57
size_t ivLen
Length of the initialization vector, in bytes.
Definition: ipsec.h:385
TCP/IP stack core.
MacAlgo
MAC algorithms.
IpsecSelector selector
Traffic selector.
Definition: ipsec.h:354
MacContext macContext
MAC context.
Definition: ipsec.h:457
NetContext * netContext
TCP/IP stack context.
Definition: ipsec.h:430
CipherContext cipherContext
Cipher context.
Definition: ipsec.h:380
@ IPSEC_SA_STATE_RESERVED
Definition: ipsec.h:277
error_t ipsecInit(IpsecContext *context, const IpsecSettings *settings)
IPsec service initialization.
Definition: ipsec.c:78
uint8_t buffer[ESP_BUFFER_SIZE]
Memory buffer for input/output operations.
Definition: ipsec.h:459
IpsecDfPolicy dfPolicy
DF flag policy.
Definition: ipsec.h:375
@ IPSEC_SA_STATE_OPEN
Definition: ipsec.h:278
error_t ipsecClearSadEntry(IpsecContext *context, uint_t index)
Clear entry at specified index in SAD database.
Definition: ipsec.c:291
Generic MAC algorithm context.
@ IPSEC_PROTOCOL_INVALID
Definition: ipsec.h:198
IpsecPortRange localPort
Local port range.
Definition: ipsec.h:313
size_t encKeyLen
Length of the encryption key, in bytes.
Definition: ipsec.h:382
IpsecAddrRange remoteIpAddr
Remote IP address range.
Definition: ipsec.h:311
IpsecMode mode
IPsec mode (tunnel or transport)
Definition: ipsec.h:372
IpsecSpdEntry * spdEntries
Security Policy Database (SPD)
Definition: ipsec.h:433
error_t ipsecSetSadEntry(IpsecContext *context, uint_t index, IpsecSadEntry *params)
Set entry at specified index in SAD database.
Definition: ipsec.c:202
CipherMode
Cipher operation modes.
Definition: cipher_modes.h:78
IPsec settings.
Definition: ipsec.h:429