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.0
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.0"
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 0
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 //Size of SPI for AH and ESP protocols
142 #define IPSEC_SPI_SIZE 4
143 
144 //ANY protocol selector
145 #define IPSEC_PROTOCOL_ANY 0
146 
147 //ANY port selector
148 #define IPSEC_PORT_START_ANY 0
149 #define IPSEC_PORT_END_ANY 65535
150 
151 //OPAQUE port selector
152 #define IPSEC_PORT_START_OPAQUE 65535
153 #define IPSEC_PORT_END_OPAQUE 0
154 
155 //ICMP port selector
156 #define IPSEC_ICMP_PORT(type, code) (((type) * 256) + (code))
157 
158 //C++ guard
159 #ifdef __cplusplus
160 extern "C" {
161 #endif
162 
163 
164 /**
165  * @brief Direction
166  **/
167 
168 typedef enum
169 {
174 
175 
176 /**
177  * @brief Authentication methods
178  **/
179 
180 typedef enum
181 {
187 
188 
189 /**
190  * @brief Security protocols
191  **/
192 
193 typedef enum
194 {
199 
200 
201 /**
202  * @brief IPsec protocol modes
203  **/
204 
205 typedef enum
206 {
211 
212 
213 /**
214  * @brief ID types
215  **/
216 
217 typedef enum
218 {
219  IPSEC_ID_TYPE_IPV4_ADDR = 1, ///<IPv4 address
220  IPSEC_ID_TYPE_FQDN = 2, ///<Fully-qualified domain name
221  IPSEC_ID_TYPE_RFC822_ADDR = 3, ///<RFC 822 email address
222  IPSEC_ID_TYPE_IPV6_ADDR = 5, ///<IPv6 address
223  IPSEC_ID_TYPE_DN = 9, ///<X.500 distinguished name
224  IPSEC_ID_TYPE_KEY_ID = 11 ///<Key ID
226 
227 
228 /**
229  * @brief Policy action
230  **/
231 
232 typedef enum
233 {
239 
240 
241 /**
242  * @brief PFP flags
243  **/
244 
245 typedef enum
246 {
253 
254 
255 /**
256  * @brief DF flag policy
257  **/
258 
259 typedef enum
260 {
265 
266 
267 /**
268  * @brief IPsec SAD entry state
269  **/
270 
271 typedef enum
272 {
277 
278 
279 /**
280  * @brief IP address range
281  **/
282 
283 typedef struct
284 {
288 
289 
290 /**
291  * @brief Port range
292  **/
293 
294 typedef struct
295 {
296  uint16_t start;
297  uint16_t end;
299 
300 
301 /**
302  * @brief IPsec selector
303  **/
304 
305 typedef struct
306 {
307  IpsecAddrRange localIpAddr; ///<Local IP address range
308  IpsecAddrRange remoteIpAddr; ///<Remote IP address range
309  uint8_t nextProtocol; ///<Next layer protocol
310  IpsecPortRange localPort; ///<Local port range
311  IpsecPortRange remotePort; ///<Remote port range
312 } IpsecSelector;
313 
314 
315 /**
316  * @brief IP packet information
317  **/
318 
319 typedef struct
320 {
321  IpAddr localIpAddr; ///<Local IP address
322  IpAddr remoteIpAddr; ///<Remote IP address
323  uint8_t nextProtocol; ///<Next layer protocol
324  uint16_t localPort; ///<Local port
325  uint16_t remotePort; ///<Remote port
327 
328 
329 /**
330  * @brief IPsec ID
331  **/
332 
333 typedef union
334 {
335  char_t fqdn[IPSEC_MAX_ID_LEN + 1]; ///<Fully-qualified domain name
336  char_t email[IPSEC_MAX_ID_LEN + 1]; ///<RFC 822 email address
337  uint8_t dn[IPSEC_MAX_ID_LEN]; ///<X.500 Distinguished Name
338  uint8_t keyId[IPSEC_MAX_ID_LEN]; ///<Key ID
339  IpsecAddrRange ipAddr; ///<IPv4 or IPv6 address range
340 } IpsecId;
341 
342 
343 /**
344  * @brief Security Policy Database (SPD) entry
345  **/
346 
347 typedef struct
348 {
349  IpsecPolicyAction policyAction; ///<Processing choice (DISCARD, BYPASS or PROTECT)
350  uint_t pfpFlags; ///<PFP flags
351  IpsecSelector selector; ///<Traffic selector
352  IpsecMode mode; ///<IPsec mode (tunnel or transport)
353  IpsecProtocol protocol; ///<Security protocol (AH or ESP)
354  bool_t esn; ///<Extended sequence numbers
355  IpAddr localTunnelAddr; ///<Local tunnel IP address
356  IpAddr remoteTunnelAddr; ///<Remote tunnel IP address
357 } IpsecSpdEntry;
358 
359 
360 /**
361  * @brief Security Association Database (SAD) entry
362  **/
363 
365 {
366  IpsecSaState state; ///<SAD entry state
367  IpsecDirection direction; ///<Direction
368  IpsecMode mode; ///<IPsec mode (tunnel or transport)
369  IpsecProtocol protocol; ///<Security protocol (AH or ESP)
370  IpsecSelector selector; ///<Traffic selector
371  IpsecDfPolicy dfPolicy; ///<DF flag policy
372  uint32_t spi; ///<Security parameter index
373 #if (ESP_SUPPORT == ENABLED)
374  CipherMode cipherMode; ///<Cipher mode of operation
375  const CipherAlgo *cipherAlgo; ///<Cipher algorithm
376  CipherContext cipherContext; ///<Cipher context
377  uint8_t encKey[IPSEC_MAX_ENC_KEY_LEN]; ///<Encryption key
378  size_t encKeyLen; ///<Length of the encryption key, in bytes
379  size_t saltLen; ///<Length of the salt, in bytes
380  uint8_t iv[16]; ///<Initialization vector
381  size_t ivLen; ///<Length of the initialization vector, in bytes
382 #endif
383  const HashAlgo *authHashAlgo; ///<Hash algorithm for HMAC-based integrity calculations
384  const CipherAlgo *authCipherAlgo; ///<Cipher algorithm for CMAC-based integrity calculations
385  uint8_t authKey[IPSEC_MAX_AUTH_KEY_LEN]; ///<Integrity protection key
386  size_t authKeyLen; ///<Length of the integrity protection key, in bytes
387  size_t icvLen; ///<Length of the ICV tag, in bytes
388  bool_t esn; ///<Extended sequence numbers
389  uint64_t seqNum; ///<Sequence number counter
390  systime_t lifetimeStart; ///<Timestamp
391 #if (IPSEC_ANTI_REPLAY_SUPPORT == ENABLED)
392  bool_t antiReplayEnabled; ///<Anti-replay mechanism enabled
393  uint32_t antiReplayWindow[(IPSEC_ANTI_REPLAY_WINDOW_SIZE + 31) / 32]; ///<Anti-replay window
394 #endif
395  IpAddr tunnelDestIpAddr; ///<Tunnel header IP destination address
396 };
397 
398 
399 /**
400  * @brief Peer Authorization Database (PAD) entry
401  **/
402 
403 typedef struct
404 {
405  IpsecAuthMethod authMethod; ///<Authentication method (IKEv1, IKEv2, KINK)
406  IpsecIdType idType; ///<ID type
407  IpsecId id; ///<ID
408  size_t idLen; ///<Length of the ID, in bytes
409  uint8_t psk[IPSEC_MAX_PSK_LEN]; ///<Pre-shared key
410  size_t pskLen; ///<Length of the pre-shared key, in bytes
411  const char_t *trustedCaList; ///Trusted CA list (PEM format)
412  size_t trustedCaListLen; ///<Total length of the trusted CA list
413 } IpsecPadEntry;
414 
415 
416 /**
417  * @brief IPsec settings
418  **/
419 
420 typedef struct
421 {
422  NetContext *netContext; ///<TCP/IP stack context
423  const PrngAlgo *prngAlgo; ///<Pseudo-random number generator to be used
424  void *prngContext; ///<Pseudo-random number generator context
425  IpsecSpdEntry *spdEntries; ///<Security Policy Database (SPD)
426  uint_t numSpdEntries; ///<Number of entries in the SPD database
427  IpsecSadEntry *sadEntries; ///<Security Association Database (SAD)
428  uint_t numSadEntries; ///<Number of entries in the SAD database
429  IpsecPadEntry *padEntries; ///<Peer Authorization Database (PAD)
430  uint_t numPadEntries; ///<Number of entries in the PAD database
431 } IpsecSettings;
432 
433 
434 /**
435  * @brief IPsec context
436  **/
437 
439 {
440  NetContext *netContext; ///<TCP/IP stack context
441  const PrngAlgo *prngAlgo; ///<Pseudo-random number generator to be used
442  void *prngContext; ///<Pseudo-random number generator context
443  IpsecSpdEntry *spd; ///<Security Policy Database (SPD)
444  uint_t numSpdEntries; ///<Number of entries in the SPD database
445  IpsecSadEntry *sad; ///<Security Association Database (SAD)
446  uint_t numSadEntries; ///<Number of entries in the SAD database
447  IpsecPadEntry *pad; ///<Peer Authorization Database (PAD)
448  uint_t numPadEntries; ///<Number of entries in the PAD database
449 #if (AH_CMAC_SUPPORT == ENABLED || ESP_CMAC_SUPPORT == ENABLED)
450  CmacContext cmacContext; ///<CMAC context
451 #endif
452 #if (ESP_GMAC_SUPPORT == ENABLED)
453  GmacContext gmacContext; ///<GMAC context
454 #endif
455 #if (AH_HMAC_SUPPORT == ENABLED || ESP_HMAC_SUPPORT == ENABLED)
456  HmacContext hmacContext; ///<HMAC context
457 #endif
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:448
IpsecAddrRange ipAddr
IPv4 or IPv6 address range.
Definition: ipsec.h:339
@ IPSEC_ID_TYPE_KEY_ID
Key ID.
Definition: ipsec.h:224
#define NetContext
Definition: net.h:36
@ IPSEC_DIR_INVALID
Definition: ipsec.h:170
const PrngAlgo * prngAlgo
Pseudo-random number generator to be used.
Definition: ipsec.h:441
IpsecMode
IPsec protocol modes.
Definition: ipsec.h:206
int bool_t
Definition: compiler_port.h:63
HMAC algorithm context.
Definition: hmac.h:59
uint_t numSadEntries
Number of entries in the SAD database.
Definition: ipsec.h:428
size_t icvLen
Length of the ICV tag, in bytes.
Definition: ipsec.h:387
uint16_t end
Definition: ipsec.h:297
@ IPSEC_SA_STATE_CLOSED
Definition: ipsec.h:273
@ IPSEC_ID_TYPE_IPV4_ADDR
IPv4 address.
Definition: ipsec.h:219
uint_t numSadEntries
Number of entries in the SAD database.
Definition: ipsec.h:446
@ IPSEC_DIR_INBOUND
Definition: ipsec.h:171
@ IPSEC_PROTOCOL_AH
Definition: ipsec.h:196
@ IPSEC_AUTH_METHOD_KINK
Definition: ipsec.h:185
uint32_t spi
Security parameter index.
Definition: ipsec.h:372
IPsec selector.
Definition: ipsec.h:306
IP network address.
Definition: ip.h:90
#define PrngAlgo
Definition: crypto.h:1035
IpsecSelector selector
Traffic selector.
Definition: ipsec.h:370
void * prngContext
Pseudo-random number generator context.
Definition: ipsec.h:424
IpsecDirection
Direction.
Definition: ipsec.h:169
const CipherAlgo * authCipherAlgo
Cipher algorithm for CMAC-based integrity calculations.
Definition: ipsec.h:384
IpsecSpdEntry * spd
Security Policy Database (SPD)
Definition: ipsec.h:443
IpsecIdType
ID types.
Definition: ipsec.h:218
Collection of AEAD algorithms.
IpAddr remoteIpAddr
Remote IP address.
Definition: ipsec.h:322
Generic cipher algorithm context.
bool_t antiReplayEnabled
Anti-replay mechanism enabled.
Definition: ipsec.h:392
IpAddr end
Definition: ipsec.h:286
size_t pskLen
Length of the pre-shared key, in bytes.
Definition: ipsec.h:410
@ IPSEC_PFP_FLAG_REMOTE_ADDR
Definition: ipsec.h:248
#define IPSEC_MAX_ENC_KEY_LEN
Definition: ipsec.h:129
IpsecId id
ID.
Definition: ipsec.h:407
#define IPSEC_ANTI_REPLAY_WINDOW_SIZE
Definition: ipsec.h:108
systime_t lifetimeStart
Timestamp.
Definition: ipsec.h:390
#define ESP_BUFFER_SIZE
Definition: esp.h:284
@ IPSEC_PFP_FLAG_LOCAL_ADDR
Definition: ipsec.h:247
uint8_t authKey[IPSEC_MAX_AUTH_KEY_LEN]
Integrity protection key.
Definition: ipsec.h:385
@ IPSEC_MODE_TUNNEL
Definition: ipsec.h:208
IPsec context.
Definition: ipsec.h:439
#define IPSEC_MAX_AUTH_KEY_LEN
Definition: ipsec.h:136
@ IPSEC_POLICY_ACTION_PROTECT
Definition: ipsec.h:237
@ IPSEC_ID_TYPE_RFC822_ADDR
RFC 822 email address.
Definition: ipsec.h:221
@ IPSEC_PROTOCOL_ESP
Definition: ipsec.h:197
void * prngContext
Pseudo-random number generator context.
Definition: ipsec.h:442
@ IPSEC_DIR_OUTBOUND
Definition: ipsec.h:172
Peer Authorization Database (PAD) entry.
Definition: ipsec.h:404
uint16_t remotePort
Remote port.
Definition: ipsec.h:325
bool_t esn
Extended sequence numbers.
Definition: ipsec.h:388
ESP (IP Encapsulating Security Payload)
uint64_t seqNum
Sequence number counter.
Definition: ipsec.h:389
IpsecSadEntry * sadEntries
Security Association Database (SAD)
Definition: ipsec.h:427
IpAddr localTunnelAddr
Local tunnel IP address.
Definition: ipsec.h:355
GmacContext gmacContext
GMAC context.
Definition: ipsec.h:453
ICMP (Internet Control Message Protocol)
IpsecAuthMethod authMethod
Authentication method (IKEv1, IKEv2, KINK)
Definition: ipsec.h:405
uint8_t nextProtocol
Next layer protocol.
Definition: ipsec.h:323
uint8_t nextProtocol
Next layer protocol.
Definition: ipsec.h:309
uint16_t localPort
Local port.
Definition: ipsec.h:324
@ IPSEC_MODE_TRANSPORT
Definition: ipsec.h:209
@ IPSEC_DF_POLICY_COPY
Definition: ipsec.h:263
error_t
Error codes.
Definition: error.h:43
@ IPSEC_ID_TYPE_FQDN
Fully-qualified domain name.
Definition: ipsec.h:220
IpsecPolicyAction
Policy action.
Definition: ipsec.h:233
uint8_t encKey[IPSEC_MAX_ENC_KEY_LEN]
Encryption key.
Definition: ipsec.h:377
IpsecPolicyAction policyAction
Processing choice (DISCARD, BYPASS or PROTECT)
Definition: ipsec.h:349
@ IPSEC_PFP_FLAG_REMOTE_PORT
Definition: ipsec.h:251
IpsecPortRange remotePort
Remote port range.
Definition: ipsec.h:311
HmacContext hmacContext
HMAC context.
Definition: ipsec.h:456
@ IPSEC_POLICY_ACTION_DISCARD
Definition: ipsec.h:235
IpsecProtocol protocol
Security protocol (AH or ESP)
Definition: ipsec.h:353
@ IPSEC_AUTH_METHOD_IKEV1
Definition: ipsec.h:183
Security Association Database (SAD) entry.
Definition: ipsec.h:365
IpsecSadEntry * sad
Security Association Database (SAD)
Definition: ipsec.h:445
@ IPSEC_ID_TYPE_IPV6_ADDR
IPv6 address.
Definition: ipsec.h:222
size_t saltLen
Length of the salt, in bytes.
Definition: ipsec.h:379
General definitions for cryptographic algorithms.
IpAddr tunnelDestIpAddr
Tunnel header IP destination address.
Definition: ipsec.h:395
void ipsecDeinit(IpsecContext *context)
Release IPsec context.
Definition: ipsec.c:395
uint32_t antiReplayWindow[(IPSEC_ANTI_REPLAY_WINDOW_SIZE+31)/32]
Anti-replay window.
Definition: ipsec.h:393
CmacContext cmacContext
CMAC context.
Definition: ipsec.h:450
@ IPSEC_AUTH_METHOD_IKEV2
Definition: ipsec.h:184
IpsecPadEntry * padEntries
Peer Authorization Database (PAD)
Definition: ipsec.h:429
Block cipher modes of operation.
const CipherAlgo * cipherAlgo
Cipher algorithm.
Definition: ipsec.h:375
IpsecSaState state
SAD entry state.
Definition: ipsec.h:366
IpsecDfPolicy
DF flag policy.
Definition: ipsec.h:260
size_t trustedCaListLen
Trusted CA list (PEM format)
Definition: ipsec.h:412
IpsecMode mode
IPsec mode (tunnel or transport)
Definition: ipsec.h:352
const HashAlgo * authHashAlgo
Hash algorithm for HMAC-based integrity calculations.
Definition: ipsec.h:383
IpsecDirection direction
Direction.
Definition: ipsec.h:367
@ IPSEC_DF_POLICY_SET
Definition: ipsec.h:262
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:350
CipherMode
Cipher operation modes.
Definition: crypto.h:1059
IpsecIdType idType
ID type.
Definition: ipsec.h:406
AH (IP Authentication Header)
CMAC algorithm context.
Definition: cmac.h:54
IpsecProtocol
Security protocols.
Definition: ipsec.h:194
IpAddr start
Definition: ipsec.h:285
const PrngAlgo * prngAlgo
Pseudo-random number generator to be used.
Definition: ipsec.h:423
#define IpsecSadEntry
Definition: ipsec.h:36
const char_t * trustedCaList
Definition: ipsec.h:411
uint16_t start
Definition: ipsec.h:296
Collection of hash algorithms.
NetContext * netContext
TCP/IP stack context.
Definition: ipsec.h:440
uint32_t systime_t
System time.
IPsec ID.
Definition: ipsec.h:334
error_t ipsecClearPadEntry(IpsecContext *context, uint_t index)
Clear entry at specified index in PAD database.
Definition: ipsec.c:372
bool_t esn
Extended sequence numbers.
Definition: ipsec.h:354
@ IPSEC_DF_POLICY_CLEAR
Definition: ipsec.h:261
char char_t
Definition: compiler_port.h:55
size_t idLen
Length of the ID, in bytes.
Definition: ipsec.h:408
size_t authKeyLen
Length of the integrity protection key, in bytes.
Definition: ipsec.h:386
IpsecPfpFlags
PFP flags.
Definition: ipsec.h:246
IpsecPadEntry * pad
Peer Authorization Database (PAD)
Definition: ipsec.h:447
Port range.
Definition: ipsec.h:295
#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:430
uint8_t iv[16]
Initialization vector.
Definition: ipsec.h:380
IP packet information.
Definition: ipsec.h:320
uint_t numSpdEntries
Number of entries in the SPD database.
Definition: ipsec.h:426
IpsecAddrRange localIpAddr
Local IP address range.
Definition: ipsec.h:307
@ IPSEC_POLICY_ACTION_INVALID
Definition: ipsec.h:234
IpAddr localIpAddr
Local IP address.
Definition: ipsec.h:321
@ IPSEC_PFP_FLAG_NEXT_PROTOCOL
Definition: ipsec.h:249
uint_t numSpdEntries
Number of entries in the SPD database.
Definition: ipsec.h:444
UDP (User Datagram Protocol)
@ IPSEC_ID_TYPE_DN
X.500 distinguished name.
Definition: ipsec.h:223
CipherMode cipherMode
Cipher mode of operation.
Definition: ipsec.h:374
IpAddr remoteTunnelAddr
Remote tunnel IP address.
Definition: ipsec.h:356
@ IPSEC_PFP_FLAG_LOCAL_PORT
Definition: ipsec.h:250
#define IpsecContext
Definition: ipsec.h:40
Common interface for encryption algorithms.
Definition: crypto.h:1191
GMAC algorithm context.
Definition: gmac.h:70
@ IPSEC_POLICY_ACTION_BYPASS
Definition: ipsec.h:236
#define IPSEC_MAX_PSK_LEN
Definition: ipsec.h:122
Collection of MAC algorithms.
@ IPSEC_MODE_INVALID
Definition: ipsec.h:207
@ IPSEC_AUTH_METHOD_INVALID
Definition: ipsec.h:182
void ipsecGetDefaultSettings(IpsecSettings *settings)
Initialize settings with default values.
Definition: ipsec.c:48
IpsecProtocol protocol
Security protocol (AH or ESP)
Definition: ipsec.h:369
IpsecSaState
IPsec SAD entry state.
Definition: ipsec.h:272
Common interface for hash algorithms.
Definition: crypto.h:1151
IP address range.
Definition: ipsec.h:284
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:346
IpsecAuthMethod
Authentication methods.
Definition: ipsec.h:181
Security Policy Database (SPD) entry.
Definition: ipsec.h:348
unsigned int uint_t
Definition: compiler_port.h:57
size_t ivLen
Length of the initialization vector, in bytes.
Definition: ipsec.h:381
TCP/IP stack core.
IpsecSelector selector
Traffic selector.
Definition: ipsec.h:351
NetContext * netContext
TCP/IP stack context.
Definition: ipsec.h:422
CipherContext cipherContext
Cipher context.
Definition: ipsec.h:376
@ IPSEC_SA_STATE_RESERVED
Definition: ipsec.h:274
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:371
@ IPSEC_SA_STATE_OPEN
Definition: ipsec.h:275
error_t ipsecClearSadEntry(IpsecContext *context, uint_t index)
Clear entry at specified index in SAD database.
Definition: ipsec.c:285
@ IPSEC_PROTOCOL_INVALID
Definition: ipsec.h:195
IpsecPortRange localPort
Local port range.
Definition: ipsec.h:310
size_t encKeyLen
Length of the encryption key, in bytes.
Definition: ipsec.h:378
IpsecAddrRange remoteIpAddr
Remote IP address range.
Definition: ipsec.h:308
IpsecMode mode
IPsec mode (tunnel or transport)
Definition: ipsec.h:368
IpsecSpdEntry * spdEntries
Security Policy Database (SPD)
Definition: ipsec.h:425
error_t ipsecSetSadEntry(IpsecContext *context, uint_t index, IpsecSadEntry *params)
Set entry at specified index in SAD database.
Definition: ipsec.c:202
IPsec settings.
Definition: ipsec.h:421