esp_algorithms.c
Go to the documentation of this file.
1 /**
2  * @file esp_algorithms.c
3  * @brief ESP algorithm negotiation
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 //Switch to the appropriate trace level
32 #define TRACE_LEVEL ESP_TRACE_LEVEL
33 
34 //Dependencies
35 #include "ipsec/ipsec.h"
36 #include "ipsec/ipsec_misc.h"
37 #include "esp/esp.h"
38 #include "esp/esp_algorithms.h"
39 #include "ike/ike_algorithms.h"
40 #include "hash/hash_algorithms.h"
41 #include "debug.h"
42 
43 //Check IPsec library configuration
44 #if (ESP_SUPPORT == ENABLED)
45 
46 
47 /**
48  * @brief List of supported encryption algorithms
49  **/
50 
51 static const IkeEncAlgo espSupportedEncAlgos[] =
52 {
53 #if (ESP_CHACHA20_POLY1305_SUPPORT == ENABLED)
55 #endif
56 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_GCM_16_SUPPORT == ENABLED)
58 #endif
59 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_GCM_16_SUPPORT == ENABLED)
61 #endif
62 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_GCM_16_SUPPORT == ENABLED)
64 #endif
65 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_GCM_12_SUPPORT == ENABLED)
67 #endif
68 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_GCM_12_SUPPORT == ENABLED)
70 #endif
71 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_GCM_12_SUPPORT == ENABLED)
73 #endif
74 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_GCM_8_SUPPORT == ENABLED)
76 #endif
77 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_GCM_8_SUPPORT == ENABLED)
79 #endif
80 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_GCM_8_SUPPORT == ENABLED)
82 #endif
83 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_CCM_16_SUPPORT == ENABLED)
85 #endif
86 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_CCM_16_SUPPORT == ENABLED)
88 #endif
89 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_CCM_16_SUPPORT == ENABLED)
91 #endif
92 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_CCM_12_SUPPORT == ENABLED)
94 #endif
95 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_CCM_12_SUPPORT == ENABLED)
97 #endif
98 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_CCM_12_SUPPORT == ENABLED)
100 #endif
101 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_CCM_8_SUPPORT == ENABLED)
103 #endif
104 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_CCM_8_SUPPORT == ENABLED)
106 #endif
107 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_CCM_8_SUPPORT == ENABLED)
109 #endif
110 #if (ESP_CAMELLIA_128_SUPPORT == ENABLED && ESP_CCM_16_SUPPORT == ENABLED)
112 #endif
113 #if (ESP_CAMELLIA_192_SUPPORT == ENABLED && ESP_CCM_16_SUPPORT == ENABLED)
115 #endif
116 #if (ESP_CAMELLIA_256_SUPPORT == ENABLED && ESP_CCM_16_SUPPORT == ENABLED)
118 #endif
119 #if (ESP_CAMELLIA_128_SUPPORT == ENABLED && ESP_CCM_12_SUPPORT == ENABLED)
121 #endif
122 #if (ESP_CAMELLIA_192_SUPPORT == ENABLED && ESP_CCM_12_SUPPORT == ENABLED)
124 #endif
125 #if (ESP_CAMELLIA_256_SUPPORT == ENABLED && ESP_CCM_12_SUPPORT == ENABLED)
127 #endif
128 #if (ESP_CAMELLIA_128_SUPPORT == ENABLED && ESP_CCM_8_SUPPORT == ENABLED)
130 #endif
131 #if (ESP_CAMELLIA_192_SUPPORT == ENABLED && ESP_CCM_8_SUPPORT == ENABLED)
133 #endif
134 #if (ESP_CAMELLIA_256_SUPPORT == ENABLED && ESP_CCM_8_SUPPORT == ENABLED)
136 #endif
137 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_CTR_SUPPORT == ENABLED)
139 #endif
140 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_CTR_SUPPORT == ENABLED)
142 #endif
143 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_CTR_SUPPORT == ENABLED)
145 #endif
146 #if (ESP_CAMELLIA_128_SUPPORT == ENABLED && ESP_CTR_SUPPORT == ENABLED)
148 #endif
149 #if (ESP_CAMELLIA_192_SUPPORT == ENABLED && ESP_CTR_SUPPORT == ENABLED)
151 #endif
152 #if (ESP_CAMELLIA_256_SUPPORT == ENABLED && ESP_CTR_SUPPORT == ENABLED)
154 #endif
155 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
157 #endif
158 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
160 #endif
161 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
163 #endif
164 #if (ESP_CAMELLIA_128_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
166 #endif
167 #if (ESP_CAMELLIA_192_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
169 #endif
170 #if (ESP_CAMELLIA_256_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
172 #endif
173 #if (ESP_3DES_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
175 #endif
176 #if (ESP_DES_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
178 #endif
179 #if (ESP_IDEA_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
181 #endif
182 #if (ESP_NULL_SUPPORT == ENABLED && ESP_GMAC_SUPPORT == ENABLED && \
183  ESP_AES_128_SUPPORT == ENABLED)
185 #endif
186 #if (ESP_NULL_SUPPORT == ENABLED && ESP_GMAC_SUPPORT == ENABLED && \
187  ESP_AES_192_SUPPORT == ENABLED)
189 #endif
190 #if (ESP_NULL_SUPPORT == ENABLED && ESP_GMAC_SUPPORT == ENABLED && \
191  ESP_AES_256_SUPPORT == ENABLED)
193 #endif
194 #if (ESP_NULL_SUPPORT == ENABLED)
196 #endif
197 };
198 
199 
200 /**
201  * @brief List of supported integrity algorithms
202  **/
203 
204 static const uint16_t espSupportedAuthAlgos[] =
205 {
206 #if (ESP_HMAC_SUPPORT == ENABLED && ESP_SHA256_SUPPORT == ENABLED)
208 #endif
209 #if (ESP_HMAC_SUPPORT == ENABLED && ESP_SHA384_SUPPORT == ENABLED)
211 #endif
212 #if (ESP_HMAC_SUPPORT == ENABLED && ESP_SHA512_SUPPORT == ENABLED)
214 #endif
215 #if (ESP_CMAC_SUPPORT == ENABLED && ESP_AES_128_SUPPORT == ENABLED)
217 #endif
218 #if (ESP_HMAC_SUPPORT == ENABLED && ESP_SHA1_SUPPORT == ENABLED)
220 #endif
221 #if (ESP_HMAC_SUPPORT == ENABLED && ESP_MD5_SUPPORT == ENABLED)
223 #endif
224  0
225 };
226 
227 
228 /**
229  * @brief List of supported ESN transforms
230  **/
231 
232 static const uint16_t espSupportedEsnTranforms[] =
233 {
234 #if (ESP_ESN_SUPPORT == ENABLED)
236 #endif
238 };
239 
240 
241 /**
242  * @brief Select the relevant encryption algorithm
243  * @param[in] childSa Pointer to the Child SA
244  * @param[in] encAlgoId Encryption algorithm identifier
245  * @param[in] encKeyLen Length of the encryption key, in bytes
246  * @return Error code
247  **/
248 
249 error_t espSelectEncAlgo(IkeChildSaEntry *childSa, uint16_t encAlgoId,
250  size_t encKeyLen)
251 {
252  error_t error;
253 
254  //Initialize status code
255  error = NO_ERROR;
256 
257 #if (ESP_NULL_SUPPORT == ENABLED)
258  //NULL encryption algorithm?
259  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_NULL)
260  {
261  childSa->cipherMode = CIPHER_MODE_NULL;
262  childSa->cipherAlgo = NULL;
263  childSa->encKeyLen = 0;
264  childSa->ivLen = 0;
265  }
266  else
267 #endif
268 #if (ESP_IDEA_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
269  //IDEA-CBC encryption algorithm?
270  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_IDEA)
271  {
272  childSa->cipherMode = CIPHER_MODE_CBC;
273  childSa->cipherAlgo = IDEA_CIPHER_ALGO;
274  childSa->encKeyLen = 16;
275  childSa->ivLen = IDEA_BLOCK_SIZE;
276  }
277  else
278 #endif
279 #if (ESP_DES_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
280  //DES-CBC encryption algorithm?
281  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_DES)
282  {
283  childSa->cipherMode = CIPHER_MODE_CBC;
284  childSa->cipherAlgo = DES_CIPHER_ALGO;
285  childSa->encKeyLen = 8;
286  childSa->ivLen = DES_BLOCK_SIZE;
287  }
288  else
289 #endif
290 #if (ESP_3DES_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
291  //3DES-CBC encryption algorithm?
292  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_3DES)
293  {
294  childSa->cipherMode = CIPHER_MODE_CBC;
295  childSa->cipherAlgo = DES3_CIPHER_ALGO;
296  childSa->encKeyLen = 24;
297  childSa->ivLen = DES3_BLOCK_SIZE;
298  }
299  else
300 #endif
301 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
302  //AES-CBC with 128-bit key encryption algorithm?
303  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_CBC && encKeyLen == 16)
304  {
305  childSa->cipherMode = CIPHER_MODE_CBC;
306  childSa->cipherAlgo = AES_CIPHER_ALGO;
307  childSa->encKeyLen = 16;
308  childSa->ivLen = AES_BLOCK_SIZE;
309  }
310  else
311 #endif
312 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
313  //AES-CBC with 192-bit key encryption algorithm?
314  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_CBC && encKeyLen == 24)
315  {
316  childSa->cipherMode = CIPHER_MODE_CBC;
317  childSa->cipherAlgo = AES_CIPHER_ALGO;
318  childSa->encKeyLen = 24;
319  childSa->ivLen = AES_BLOCK_SIZE;
320  }
321  else
322 #endif
323 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
324  //AES-CBC with 256-bit key encryption algorithm?
325  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_CBC && encKeyLen == 32)
326  {
327  childSa->cipherMode = CIPHER_MODE_CBC;
328  childSa->cipherAlgo = AES_CIPHER_ALGO;
329  childSa->encKeyLen = 32;
330  childSa->ivLen = AES_BLOCK_SIZE;
331  }
332  else
333 #endif
334 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_CTR_SUPPORT == ENABLED)
335  //AES-CTR with 128-bit key encryption algorithm?
336  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_CTR && encKeyLen == 16)
337  {
338  childSa->cipherMode = CIPHER_MODE_CTR;
339  childSa->cipherAlgo = AES_CIPHER_ALGO;
340  childSa->encKeyLen = 16;
341  childSa->saltLen = 4;
342  childSa->ivLen = 8;
343  }
344  else
345 #endif
346 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_CTR_SUPPORT == ENABLED)
347  //AES-CTR with 192-bit key encryption algorithm?
348  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_CTR && encKeyLen == 24)
349  {
350  childSa->cipherMode = CIPHER_MODE_CTR;
351  childSa->cipherAlgo = AES_CIPHER_ALGO;
352  childSa->encKeyLen = 24;
353  childSa->saltLen = 4;
354  childSa->ivLen = 8;
355  }
356  else
357 #endif
358 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_CTR_SUPPORT == ENABLED)
359  //AES-CTR with 256-bit key encryption algorithm?
360  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_CTR && encKeyLen == 32)
361  {
362  childSa->cipherMode = CIPHER_MODE_CTR;
363  childSa->cipherAlgo = AES_CIPHER_ALGO;
364  childSa->encKeyLen = 32;
365  childSa->saltLen = 4;
366  childSa->ivLen = 8;
367  }
368  else
369 #endif
370 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_CCM_8_SUPPORT == ENABLED)
371  //AES-CCM with 128-bit key and 8-octet ICV encryption algorithm?
372  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_CCM_8 && encKeyLen == 16)
373  {
374  childSa->cipherMode = CIPHER_MODE_CCM;
375  childSa->cipherAlgo = AES_CIPHER_ALGO;
376  childSa->encKeyLen = 16;
377  childSa->authKeyLen = 0;
378  childSa->saltLen = 3;
379  childSa->ivLen = 8;
380  childSa->icvLen = 8;
381  }
382  else
383 #endif
384 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_CCM_8_SUPPORT == ENABLED)
385  //AES-CCM with 192-bit key and 8-octet ICV encryption algorithm?
386  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_CCM_8 && encKeyLen == 24)
387  {
388  childSa->cipherMode = CIPHER_MODE_CCM;
389  childSa->cipherAlgo = AES_CIPHER_ALGO;
390  childSa->encKeyLen = 24;
391  childSa->authKeyLen = 0;
392  childSa->saltLen = 3;
393  childSa->ivLen = 8;
394  childSa->icvLen = 8;
395  }
396  else
397 #endif
398 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_CCM_8_SUPPORT == ENABLED)
399  //AES-CCM with 256-bit key and 8-octet ICV encryption algorithm?
400  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_CCM_8 && encKeyLen == 32)
401  {
402  childSa->cipherMode = CIPHER_MODE_CCM;
403  childSa->cipherAlgo = AES_CIPHER_ALGO;
404  childSa->encKeyLen = 32;
405  childSa->authKeyLen = 0;
406  childSa->saltLen = 3;
407  childSa->ivLen = 8;
408  childSa->icvLen = 8;
409  }
410  else
411 #endif
412 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_CCM_12_SUPPORT == ENABLED)
413  //AES-CCM with 128-bit key and 12-octet ICV encryption algorithm?
414  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_CCM_12 && encKeyLen == 16)
415  {
416  childSa->cipherMode = CIPHER_MODE_CCM;
417  childSa->cipherAlgo = AES_CIPHER_ALGO;
418  childSa->encKeyLen = 16;
419  childSa->authKeyLen = 0;
420  childSa->saltLen = 3;
421  childSa->ivLen = 8;
422  childSa->icvLen = 12;
423  }
424  else
425 #endif
426 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_CCM_12_SUPPORT == ENABLED)
427  //AES-CCM with 192-bit key and 12-octet ICV encryption algorithm?
428  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_CCM_12 && encKeyLen == 24)
429  {
430  childSa->cipherMode = CIPHER_MODE_CCM;
431  childSa->cipherAlgo = AES_CIPHER_ALGO;
432  childSa->encKeyLen = 24;
433  childSa->authKeyLen = 0;
434  childSa->saltLen = 3;
435  childSa->ivLen = 8;
436  childSa->icvLen = 12;
437  }
438  else
439 #endif
440 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_CCM_12_SUPPORT == ENABLED)
441  //AES-CCM with 256-bit key and 12-octet ICV encryption algorithm?
442  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_CCM_12 && encKeyLen == 32)
443  {
444  childSa->cipherMode = CIPHER_MODE_CCM;
445  childSa->cipherAlgo = AES_CIPHER_ALGO;
446  childSa->encKeyLen = 32;
447  childSa->authKeyLen = 0;
448  childSa->saltLen = 3;
449  childSa->ivLen = 8;
450  childSa->icvLen = 12;
451  }
452  else
453 #endif
454 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_CCM_16_SUPPORT == ENABLED)
455  //AES-CCM with 128-bit key and 16-octet ICV encryption algorithm?
456  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_CCM_16 && encKeyLen == 16)
457  {
458  childSa->cipherMode = CIPHER_MODE_CCM;
459  childSa->cipherAlgo = AES_CIPHER_ALGO;
460  childSa->encKeyLen = 16;
461  childSa->authKeyLen = 0;
462  childSa->saltLen = 3;
463  childSa->ivLen = 8;
464  childSa->icvLen = 16;
465  }
466  else
467 #endif
468 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_CCM_16_SUPPORT == ENABLED)
469  //AES-CCM with 192-bit key and 16-octet ICV encryption algorithm?
470  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_CCM_16 && encKeyLen == 24)
471  {
472  childSa->cipherMode = CIPHER_MODE_CCM;
473  childSa->cipherAlgo = AES_CIPHER_ALGO;
474  childSa->encKeyLen = 24;
475  childSa->authKeyLen = 0;
476  childSa->saltLen = 3;
477  childSa->ivLen = 8;
478  childSa->icvLen = 16;
479  }
480  else
481 #endif
482 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_CCM_16_SUPPORT == ENABLED)
483  //AES-CCM with 256-bit key and 16-octet ICV encryption algorithm?
484  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_CCM_16 && encKeyLen == 32)
485  {
486  childSa->cipherMode = CIPHER_MODE_CCM;
487  childSa->cipherAlgo = AES_CIPHER_ALGO;
488  childSa->encKeyLen = 32;
489  childSa->authKeyLen = 0;
490  childSa->saltLen = 3;
491  childSa->ivLen = 8;
492  childSa->icvLen = 16;
493  }
494  else
495 #endif
496 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_GCM_8_SUPPORT == ENABLED)
497  //AES-GCM with 128-bit key and 8-octet ICV encryption algorithm?
498  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_GCM_8 && encKeyLen == 16)
499  {
500  childSa->cipherMode = CIPHER_MODE_GCM;
501  childSa->cipherAlgo = AES_CIPHER_ALGO;
502  childSa->encKeyLen = 16;
503  childSa->authKeyLen = 0;
504  childSa->saltLen = 4;
505  childSa->ivLen = 8;
506  childSa->icvLen = 8;
507  }
508  else
509 #endif
510 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_GCM_8_SUPPORT == ENABLED)
511  //AES-GCM with 192-bit key and 8-octet ICV encryption algorithm?
512  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_GCM_8 && encKeyLen == 24)
513  {
514  childSa->cipherMode = CIPHER_MODE_GCM;
515  childSa->cipherAlgo = AES_CIPHER_ALGO;
516  childSa->encKeyLen = 24;
517  childSa->authKeyLen = 0;
518  childSa->saltLen = 4;
519  childSa->ivLen = 8;
520  childSa->icvLen = 8;
521  }
522  else
523 #endif
524 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_GCM_8_SUPPORT == ENABLED)
525  //AES-GCM with 256-bit key and 8-octet ICV encryption algorithm?
526  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_GCM_8 && encKeyLen == 32)
527  {
528  childSa->cipherMode = CIPHER_MODE_GCM;
529  childSa->cipherAlgo = AES_CIPHER_ALGO;
530  childSa->encKeyLen = 32;
531  childSa->authKeyLen = 0;
532  childSa->saltLen = 4;
533  childSa->ivLen = 8;
534  childSa->icvLen = 8;
535  }
536  else
537 #endif
538 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_GCM_12_SUPPORT == ENABLED)
539  //AES-GCM with 128-bit key and 12-octet ICV encryption algorithm?
540  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_GCM_12 && encKeyLen == 16)
541  {
542  childSa->cipherMode = CIPHER_MODE_GCM;
543  childSa->cipherAlgo = AES_CIPHER_ALGO;
544  childSa->encKeyLen = 16;
545  childSa->authKeyLen = 0;
546  childSa->saltLen = 4;
547  childSa->ivLen = 8;
548  childSa->icvLen = 12;
549  }
550  else
551 #endif
552 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_GCM_12_SUPPORT == ENABLED)
553  //AES-GCM with 192-bit key and 12-octet ICV encryption algorithm?
554  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_GCM_12 && encKeyLen == 24)
555  {
556  childSa->cipherMode = CIPHER_MODE_GCM;
557  childSa->cipherAlgo = AES_CIPHER_ALGO;
558  childSa->encKeyLen = 24;
559  childSa->authKeyLen = 0;
560  childSa->saltLen = 4;
561  childSa->ivLen = 8;
562  childSa->icvLen = 12;
563  }
564  else
565 #endif
566 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_GCM_12_SUPPORT == ENABLED)
567  //AES-GCM with 256-bit key and 12-octet ICV encryption algorithm?
568  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_GCM_12 && encKeyLen == 32)
569  {
570  childSa->cipherMode = CIPHER_MODE_GCM;
571  childSa->cipherAlgo = AES_CIPHER_ALGO;
572  childSa->encKeyLen = 32;
573  childSa->authKeyLen = 0;
574  childSa->saltLen = 4;
575  childSa->ivLen = 8;
576  childSa->icvLen = 12;
577  }
578  else
579 #endif
580 #if (ESP_AES_128_SUPPORT == ENABLED && ESP_GCM_16_SUPPORT == ENABLED)
581  //AES-GCM with 128-bit key and 16-octet ICV encryption algorithm?
582  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_GCM_16 && encKeyLen == 16)
583  {
584  childSa->cipherMode = CIPHER_MODE_GCM;
585  childSa->cipherAlgo = AES_CIPHER_ALGO;
586  childSa->encKeyLen = 16;
587  childSa->authKeyLen = 0;
588  childSa->saltLen = 4;
589  childSa->ivLen = 8;
590  childSa->icvLen = 16;
591  }
592  else
593 #endif
594 #if (ESP_AES_192_SUPPORT == ENABLED && ESP_GCM_16_SUPPORT == ENABLED)
595  //AES-GCM with 192-bit key and 16-octet ICV encryption algorithm?
596  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_GCM_16 && encKeyLen == 24)
597  {
598  childSa->cipherMode = CIPHER_MODE_GCM;
599  childSa->cipherAlgo = AES_CIPHER_ALGO;
600  childSa->encKeyLen = 24;
601  childSa->authKeyLen = 0;
602  childSa->saltLen = 4;
603  childSa->ivLen = 8;
604  childSa->icvLen = 16;
605  }
606  else
607 #endif
608 #if (ESP_AES_256_SUPPORT == ENABLED && ESP_GCM_16_SUPPORT == ENABLED)
609  //AES-GCM with 256-bit key and 16-octet ICV encryption algorithm?
610  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_AES_GCM_16 && encKeyLen == 32)
611  {
612  childSa->cipherMode = CIPHER_MODE_GCM;
613  childSa->cipherAlgo = AES_CIPHER_ALGO;
614  childSa->encKeyLen = 32;
615  childSa->authKeyLen = 0;
616  childSa->saltLen = 4;
617  childSa->ivLen = 8;
618  childSa->icvLen = 16;
619  }
620  else
621 #endif
622 #if (ESP_CAMELLIA_128_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
623  //Camellia-CBC with 128-bit key encryption algorithm?
624  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_CAMELLIA_CBC && encKeyLen == 16)
625  {
626  childSa->cipherMode = CIPHER_MODE_CBC;
627  childSa->cipherAlgo = CAMELLIA_CIPHER_ALGO;
628  childSa->encKeyLen = 16;
629  childSa->ivLen = CAMELLIA_BLOCK_SIZE;
630  }
631  else
632 #endif
633 #if (ESP_CAMELLIA_192_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
634  //Camellia-CBC with 192-bit key encryption algorithm?
635  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_CAMELLIA_CBC && encKeyLen == 24)
636  {
637  childSa->cipherMode = CIPHER_MODE_CBC;
638  childSa->cipherAlgo = CAMELLIA_CIPHER_ALGO;
639  childSa->encKeyLen = 24;
640  childSa->ivLen = CAMELLIA_BLOCK_SIZE;
641  }
642  else
643 #endif
644 #if (ESP_CAMELLIA_256_SUPPORT == ENABLED && ESP_CBC_SUPPORT == ENABLED)
645  //Camellia-CBC with 256-bit key encryption algorithm?
646  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_CAMELLIA_CBC && encKeyLen == 32)
647  {
648  childSa->cipherMode = CIPHER_MODE_CBC;
649  childSa->cipherAlgo = CAMELLIA_CIPHER_ALGO;
650  childSa->encKeyLen = 32;
651  childSa->ivLen = CAMELLIA_BLOCK_SIZE;
652  }
653  else
654 #endif
655 #if (ESP_CAMELLIA_128_SUPPORT == ENABLED && ESP_CTR_SUPPORT == ENABLED)
656  //Camellia-CTR with 128-bit key encryption algorithm?
657  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_CAMELLIA_CTR && encKeyLen == 16)
658  {
659  childSa->cipherMode = CIPHER_MODE_CTR;
660  childSa->cipherAlgo = CAMELLIA_CIPHER_ALGO;
661  childSa->encKeyLen = 16;
662  childSa->saltLen = 4;
663  childSa->ivLen = 8;
664  }
665  else
666 #endif
667 #if (ESP_CAMELLIA_192_SUPPORT == ENABLED && ESP_CTR_SUPPORT == ENABLED)
668  //Camellia-CTR with 192-bit key encryption algorithm?
669  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_CAMELLIA_CTR && encKeyLen == 24)
670  {
671  childSa->cipherMode = CIPHER_MODE_CTR;
672  childSa->cipherAlgo = CAMELLIA_CIPHER_ALGO;
673  childSa->encKeyLen = 24;
674  childSa->saltLen = 4;
675  childSa->ivLen = 8;
676  }
677  else
678 #endif
679 #if (ESP_CAMELLIA_256_SUPPORT == ENABLED && ESP_CTR_SUPPORT == ENABLED)
680  //Camellia-CTR with 256-bit key encryption algorithm?
681  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_CAMELLIA_CTR && encKeyLen == 32)
682  {
683  childSa->cipherMode = CIPHER_MODE_CTR;
684  childSa->cipherAlgo = CAMELLIA_CIPHER_ALGO;
685  childSa->encKeyLen = 32;
686  childSa->saltLen = 4;
687  childSa->ivLen = 8;
688  }
689  else
690 #endif
691 #if (ESP_CAMELLIA_128_SUPPORT == ENABLED && ESP_CCM_8_SUPPORT == ENABLED)
692  //Camellia-CCM with 128-bit key and 8-octet ICV encryption algorithm?
693  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_CAMELLIA_CCM_8 && encKeyLen == 16)
694  {
695  childSa->cipherMode = CIPHER_MODE_CCM;
696  childSa->cipherAlgo = CAMELLIA_CIPHER_ALGO;
697  childSa->encKeyLen = 16;
698  childSa->authKeyLen = 0;
699  childSa->saltLen = 3;
700  childSa->ivLen = 8;
701  childSa->icvLen = 8;
702  }
703  else
704 #endif
705 #if (ESP_CAMELLIA_192_SUPPORT == ENABLED && ESP_CCM_8_SUPPORT == ENABLED)
706  //Camellia-CCM with 192-bit key and 8-octet ICV encryption algorithm?
707  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_CAMELLIA_CCM_8 && encKeyLen == 24)
708  {
709  childSa->cipherMode = CIPHER_MODE_CCM;
710  childSa->cipherAlgo = CAMELLIA_CIPHER_ALGO;
711  childSa->encKeyLen = 24;
712  childSa->authKeyLen = 0;
713  childSa->saltLen = 3;
714  childSa->ivLen = 8;
715  childSa->icvLen = 8;
716  }
717  else
718 #endif
719 #if (ESP_CAMELLIA_256_SUPPORT == ENABLED && ESP_CCM_8_SUPPORT == ENABLED)
720  //Camellia-CCM with 256-bit key and 8-octet ICV encryption algorithm?
721  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_CAMELLIA_CCM_8 && encKeyLen == 32)
722  {
723  childSa->cipherMode = CIPHER_MODE_CCM;
724  childSa->cipherAlgo = CAMELLIA_CIPHER_ALGO;
725  childSa->encKeyLen = 32;
726  childSa->authKeyLen = 0;
727  childSa->saltLen = 3;
728  childSa->ivLen = 8;
729  childSa->icvLen = 8;
730  }
731  else
732 #endif
733 #if (ESP_CAMELLIA_128_SUPPORT == ENABLED && ESP_CCM_12_SUPPORT == ENABLED)
734  //Camellia-CCM with 128-bit key and 12-octet ICV encryption algorithm?
735  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_CAMELLIA_CCM_12 && encKeyLen == 16)
736  {
737  childSa->cipherMode = CIPHER_MODE_CCM;
738  childSa->cipherAlgo = CAMELLIA_CIPHER_ALGO;
739  childSa->encKeyLen = 16;
740  childSa->authKeyLen = 0;
741  childSa->saltLen = 3;
742  childSa->ivLen = 8;
743  childSa->icvLen = 12;
744  }
745  else
746 #endif
747 #if (ESP_CAMELLIA_192_SUPPORT == ENABLED && ESP_CCM_12_SUPPORT == ENABLED)
748  //Camellia-CCM with 192-bit key and 12-octet ICV encryption algorithm?
749  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_CAMELLIA_CCM_12 && encKeyLen == 24)
750  {
751  childSa->cipherMode = CIPHER_MODE_CCM;
752  childSa->cipherAlgo = CAMELLIA_CIPHER_ALGO;
753  childSa->encKeyLen = 24;
754  childSa->authKeyLen = 0;
755  childSa->saltLen = 3;
756  childSa->ivLen = 8;
757  childSa->icvLen = 12;
758  }
759  else
760 #endif
761 #if (ESP_CAMELLIA_256_SUPPORT == ENABLED && ESP_CCM_12_SUPPORT == ENABLED)
762  //Camellia-CCM with 256-bit key and 12-octet ICV encryption algorithm?
763  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_CAMELLIA_CCM_12 && encKeyLen == 32)
764  {
765  childSa->cipherMode = CIPHER_MODE_CCM;
766  childSa->cipherAlgo = CAMELLIA_CIPHER_ALGO;
767  childSa->encKeyLen = 32;
768  childSa->authKeyLen = 0;
769  childSa->saltLen = 3;
770  childSa->ivLen = 8;
771  childSa->icvLen = 12;
772  }
773  else
774 #endif
775 #if (ESP_CAMELLIA_128_SUPPORT == ENABLED && ESP_CCM_16_SUPPORT == ENABLED)
776  //Camellia-CCM with 128-bit key and 16-octet ICV encryption algorithm?
777  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_CAMELLIA_CCM_16 && encKeyLen == 16)
778  {
779  childSa->cipherMode = CIPHER_MODE_CCM;
780  childSa->cipherAlgo = CAMELLIA_CIPHER_ALGO;
781  childSa->encKeyLen = 16;
782  childSa->authKeyLen = 0;
783  childSa->saltLen = 3;
784  childSa->ivLen = 8;
785  childSa->icvLen = 16;
786  }
787  else
788 #endif
789 #if (ESP_CAMELLIA_192_SUPPORT == ENABLED && ESP_CCM_16_SUPPORT == ENABLED)
790  //Camellia-CCM with 192-bit key and 16-octet ICV encryption algorithm?
791  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_CAMELLIA_CCM_16 && encKeyLen == 24)
792  {
793  childSa->cipherMode = CIPHER_MODE_CCM;
794  childSa->cipherAlgo = CAMELLIA_CIPHER_ALGO;
795  childSa->encKeyLen = 24;
796  childSa->authKeyLen = 0;
797  childSa->saltLen = 3;
798  childSa->ivLen = 8;
799  childSa->icvLen = 16;
800  }
801  else
802 #endif
803 #if (ESP_CAMELLIA_256_SUPPORT == ENABLED && ESP_CCM_16_SUPPORT == ENABLED)
804  //Camellia-CCM with 256-bit key and 16-octet ICV encryption algorithm?
805  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_CAMELLIA_CCM_16 && encKeyLen == 32)
806  {
807  childSa->cipherMode = CIPHER_MODE_CCM;
808  childSa->cipherAlgo = CAMELLIA_CIPHER_ALGO;
809  childSa->encKeyLen = 32;
810  childSa->authKeyLen = 0;
811  childSa->saltLen = 3;
812  childSa->ivLen = 8;
813  childSa->icvLen = 16;
814  }
815  else
816 #endif
817 #if (ESP_CHACHA20_POLY1305_SUPPORT == ENABLED)
818  //ChaCha20Poly1305 encryption algorithm?
820  {
821  childSa->cipherMode = CIPHER_MODE_CHACHA20_POLY1305;
822  childSa->cipherAlgo = NULL;
823  childSa->encKeyLen = 32;
824  childSa->authKeyLen = 0;
825  childSa->saltLen = 4;
826  childSa->ivLen = 8;
827  childSa->icvLen = 16;
828  }
829  else
830 #endif
831 #if (ESP_NULL_SUPPORT == ENABLED && ESP_GMAC_SUPPORT == ENABLED && \
832  ESP_AES_128_SUPPORT == ENABLED)
833  //AES-GMAC with 128-bit key authentication algorithm?
834  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_NULL_AUTH_AES_GMAC && encKeyLen == 16)
835  {
836  childSa->cipherMode = CIPHER_MODE_GMAC;
837  childSa->cipherAlgo = AES_CIPHER_ALGO;
838  childSa->encKeyLen = 16;
839  childSa->authKeyLen = 0;
840  childSa->saltLen = 4;
841  childSa->ivLen = 8;
842  childSa->icvLen = 16;
843 
844  }
845  else
846 #endif
847 #if (ESP_NULL_SUPPORT == ENABLED && ESP_GMAC_SUPPORT == ENABLED && \
848  ESP_AES_192_SUPPORT == ENABLED)
849  //AES-GMAC with 192-bit key authentication algorithm?
850  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_NULL_AUTH_AES_GMAC && encKeyLen == 24)
851  {
852  childSa->cipherMode = CIPHER_MODE_GMAC;
853  childSa->cipherAlgo = AES_CIPHER_ALGO;
854  childSa->encKeyLen = 24;
855  childSa->authKeyLen = 0;
856  childSa->saltLen = 4;
857  childSa->ivLen = 8;
858  childSa->icvLen = 16;
859  }
860  else
861 #endif
862 #if (ESP_NULL_SUPPORT == ENABLED && ESP_GMAC_SUPPORT == ENABLED && \
863  ESP_AES_256_SUPPORT == ENABLED)
864  //AES-GMAC with 256-bit key authentication algorithm?
865  if(encAlgoId == IKE_TRANSFORM_ID_ENCR_NULL_AUTH_AES_GMAC && encKeyLen == 32)
866  {
867  childSa->cipherMode = CIPHER_MODE_GMAC;
868  childSa->cipherAlgo = AES_CIPHER_ALGO;
869  childSa->encKeyLen = 32;
870  childSa->authKeyLen = 0;
871  childSa->saltLen = 4;
872  childSa->ivLen = 8;
873  childSa->icvLen = 16;
874  }
875  else
876 #endif
877  //Unknown encryption algorithm?
878  {
879  //Report an error
880  error = ERROR_UNSUPPORTED_ALGO;
881  }
882 
883  //Return status code
884  return error;
885 }
886 
887 
888 /**
889  * @brief Select the relevant MAC algorithm
890  * @param[in] childSa Pointer to the Child SA
891  * @param[in] authAlgoId Authentication algorithm identifier
892  * @return Error code
893  **/
894 
895 error_t espSelectAuthAlgo(IkeChildSaEntry *childSa, uint16_t authAlgoId)
896 {
897  error_t error;
898 
899  //Initialize status code
900  error = NO_ERROR;
901 
902 #if (ESP_CMAC_SUPPORT == ENABLED && ESP_AES_128_SUPPORT == ENABLED)
903  //AES-CMAC-96 authentication algorithm?
904  if(authAlgoId == IKE_TRANSFORM_ID_AUTH_AES_CMAC_96)
905  {
906  childSa->authMacAlgo = MAC_ALGO_CMAC;
907  childSa->authHashAlgo = NULL;
908  childSa->authCipherAlgo = AES_CIPHER_ALGO;
909  childSa->authKeyLen = 16;
910  childSa->icvLen = 12;
911  }
912  else
913 #endif
914 #if (ESP_HMAC_SUPPORT == ENABLED && ESP_MD5_SUPPORT == ENABLED)
915  //HMAC-MD5-96 authentication algorithm?
916  if(authAlgoId == IKE_TRANSFORM_ID_AUTH_HMAC_MD5_96)
917  {
918  childSa->authMacAlgo = MAC_ALGO_HMAC;
919  childSa->authHashAlgo = MD5_HASH_ALGO;
920  childSa->authCipherAlgo = NULL;
921  childSa->authKeyLen = MD5_DIGEST_SIZE;
922  childSa->icvLen = 12;
923  }
924  else
925 #endif
926 #if (ESP_HMAC_SUPPORT == ENABLED && ESP_SHA1_SUPPORT == ENABLED)
927  //HMAC-SHA1-96 authentication algorithm?
928  if(authAlgoId == IKE_TRANSFORM_ID_AUTH_HMAC_SHA1_96)
929  {
930  childSa->authMacAlgo = MAC_ALGO_HMAC;
931  childSa->authHashAlgo = SHA1_HASH_ALGO;
932  childSa->authCipherAlgo = NULL;
933  childSa->authKeyLen = SHA1_DIGEST_SIZE;
934  childSa->icvLen = 12;
935  }
936  else
937 #endif
938 #if (ESP_HMAC_SUPPORT == ENABLED && ESP_SHA256_SUPPORT == ENABLED)
939  //HMAC-SHA256-128 authentication algorithm?
941  {
942  childSa->authMacAlgo = MAC_ALGO_HMAC;
943  childSa->authHashAlgo = SHA256_HASH_ALGO;
944  childSa->authCipherAlgo = NULL;
945  childSa->authKeyLen = SHA256_DIGEST_SIZE;
946  childSa->icvLen = 16;
947  }
948  else
949 #endif
950 #if (ESP_HMAC_SUPPORT == ENABLED && ESP_SHA384_SUPPORT == ENABLED)
951  //HMAC-SHA384-192 authentication algorithm?
953  {
954  childSa->authMacAlgo = MAC_ALGO_HMAC;
955  childSa->authHashAlgo = SHA384_HASH_ALGO;
956  childSa->authCipherAlgo = NULL;
957  childSa->authKeyLen = SHA384_DIGEST_SIZE;
958  childSa->icvLen = 24;
959  }
960  else
961 #endif
962 #if (ESP_HMAC_SUPPORT == ENABLED && ESP_SHA512_SUPPORT == ENABLED)
963  //HMAC-SHA512-256 authentication algorithm?
965  {
966  childSa->authMacAlgo = MAC_ALGO_HMAC;
967  childSa->authHashAlgo = SHA512_HASH_ALGO;
968  childSa->authCipherAlgo = NULL;
969  childSa->authKeyLen = SHA512_DIGEST_SIZE;
970  childSa->icvLen = 32;
971  }
972  else
973 #endif
974  //Unknown authentication algorithm?
975  {
976  //Report an error
977  error = ERROR_UNSUPPORTED_ALGO;
978  }
979 
980  //Return status code
981  return error;
982 }
983 
984 
985 /**
986  * @brief Add the supported ESP transforms to the proposal
987  * @param[in] childSa Pointer to the Child SA
988  * @param[in,out] proposal Pointer to the Proposal substructure
989  * @param[in,out] lastSubstruc Pointer to the Last Substruc field
990  * @return Error code
991  **/
992 
994  IkeProposal *proposal, uint8_t **lastSubstruc)
995 {
996  error_t error;
997 
998  //Add supported encryption transforms
999  error = espAddSupportedEncTransforms(childSa, proposal, lastSubstruc);
1000 
1001  //Check status code
1002  if(!error)
1003  {
1004  //Add supported integrity transforms
1005  error = espAddSupportedAuthTransforms(childSa, proposal, lastSubstruc);
1006  }
1007 
1008 #if (IKE_CHILD_SA_PFS_SUPPORT == ENABLED)
1009  //Check status code
1010  if(!error)
1011  {
1012  //Although ESP does not directly include a Diffie-Hellman exchange, a
1013  //Diffie-Hellman group may be negotiated for the Child SA. This allows
1014  //the peers to employ Diffie-Hellman in the CREATE_CHILD_SA exchange,
1015  //providing perfect forward secrecy for the generated Child SA keys
1016  //(refer to RFC 7296, section 3.3.2)
1017  if(childSa->pfs)
1018  {
1019  //Add supported key exchange transforms
1020  error = ikeAddSupportedKeTransforms(childSa->context, proposal,
1021  lastSubstruc);
1022  }
1023  }
1024 #endif
1025 
1026  //Check status code
1027  if(!error)
1028  {
1029  //An initiator who supports ESNs will usually include two ESN transforms,
1030  //with values "0" and "1", in its proposals (refer to RFC 7296,
1031  //section 3.3.2)
1032  error = espAddSupportedEsnTransforms(childSa, proposal, lastSubstruc);
1033  }
1034 
1035  //Return status code
1036  return error;
1037 }
1038 
1039 
1040 /**
1041  * @brief Add the supported encryption transforms to the proposal
1042  * @param[in] childSa Pointer to the Child SA
1043  * @param[in,out] proposal Pointer to the Proposal substructure
1044  * @param[in,out] lastSubstruc Pointer to the Last Substruc field
1045  * @return Error code
1046  **/
1047 
1049  IkeProposal *proposal, uint8_t **lastSubstruc)
1050 {
1051  error_t error;
1052  uint_t i;
1053 
1054  //Initialize status code
1055  error = NO_ERROR;
1056 
1057  //Loop through the list of supported encryption transforms
1058  for(i = 0; i < arraysize(espSupportedEncAlgos) && !error; i++)
1059  {
1060  //Add a new transform to the proposal
1062  espSupportedEncAlgos[i].id, espSupportedEncAlgos[i].keyLen,
1063  proposal, lastSubstruc);
1064  }
1065 
1066  //Return status code
1067  return error;
1068 }
1069 
1070 
1071 /**
1072  * @brief Add the supported integrity transforms to the proposal
1073  * @param[in] childSa Pointer to the Child SA
1074  * @param[in,out] proposal Pointer to the Proposal substructure
1075  * @param[in,out] lastSubstruc Pointer to the Last Substruc field
1076  * @return Error code
1077  **/
1078 
1080  IkeProposal *proposal, uint8_t **lastSubstruc)
1081 {
1082  error_t error;
1083  uint_t i;
1084 
1085  //Initialize status code
1086  error = NO_ERROR;
1087 
1088  //Loop through the list of supported integrity transforms
1089  for(i = 0; i < (arraysize(espSupportedAuthAlgos) - 1) && !error; i++)
1090  {
1091  //Add a new transform to the proposal
1093  espSupportedAuthAlgos[i], 0, proposal, lastSubstruc);
1094  }
1095 
1096  //Return status code
1097  return error;
1098 }
1099 
1100 
1101 /**
1102  * @brief Add the supported ESN transforms to the proposal
1103  * @param[in] childSa Pointer to the Child SA
1104  * @param[in,out] proposal Pointer to the Proposal substructure
1105  * @param[in,out] lastSubstruc Pointer to the Last Substruc field
1106  * @return Error code
1107  **/
1108 
1110  IkeProposal *proposal, uint8_t **lastSubstruc)
1111 {
1112  error_t error;
1113  uint_t i;
1114 
1115  //Initialize status code
1116  error = NO_ERROR;
1117 
1118  //Loop through the list of supported ESN transforms
1119  for(i = 0; i < arraysize(espSupportedEsnTranforms) && !error; i++)
1120  {
1121  //Add a new transform to the proposal
1123  espSupportedEsnTranforms[i], 0, proposal, lastSubstruc);
1124  }
1125 
1126  //Return status code
1127  return error;
1128 }
1129 
1130 
1131 /**
1132  * @brief Encryption transform negotiation
1133  * @param[in] childSa Pointer to the Child SA
1134  * @param[in] proposal Pointer to the Proposal substructure
1135  * @param[in] proposalLen Length of the Proposal substructure, in bytes
1136  * @return Selected encryption transform, if any
1137  **/
1138 
1140  const IkeProposal *proposal, size_t proposalLen)
1141 {
1142  uint_t i;
1143  uint_t j;
1144  size_t n;
1145  size_t length;
1146  uint8_t *p;
1147  uint16_t transformId;
1148  const IkeEncAlgo *selectedAlgo;
1149  const IkeTransform *transform;
1150  const IkeTransformAttr *attr;
1151 
1152  //Chosen algorithm
1153  selectedAlgo = NULL;
1154 
1155  //Check the length of the Proposal substructure
1156  if(proposalLen >= sizeof(IkeProposal) &&
1157  proposalLen >= (sizeof(IkeProposal) + proposal->spiSize))
1158  {
1159  //Loop through the list of algorithms supported by the entity
1160  for(i = 0; i < arraysize(espSupportedEncAlgos) && selectedAlgo == NULL; i++)
1161  {
1162  //Get the length of the Proposal substructure
1163  length = proposalLen - sizeof(IkeProposal) - proposal->spiSize;
1164  //Point to the first Transform substructure
1165  p = (uint8_t *) proposal + sizeof(IkeProposal) + proposal->spiSize;
1166 
1167  //Loop through the list of algorithms supported by the peer
1168  for(j = 0; j < proposal->numTransforms && selectedAlgo == NULL; j++)
1169  {
1170  //Malformed substructure?
1171  if(length < sizeof(IkeTransform))
1172  break;
1173 
1174  //Point to the Transform substructure
1175  transform = (IkeTransform *) p;
1176 
1177  //The Transform Length field indicates the length of the Transform
1178  //substructure including header and attributes
1179  n = ntohs(transform->transformLength);
1180 
1181  //Check the length of the transform
1182  if(n < sizeof(IkeTransform) || n > length)
1183  break;
1184 
1185  //Check transform type
1186  if(transform->transformType == IKE_TRANSFORM_TYPE_ENCR)
1187  {
1188  //Convert the Transform ID field to host byte order
1189  transformId = ntohs(transform->transformId);
1190 
1191  //Variable-length key encryption algorithm?
1193  {
1194  //For algorithms that accept a variable-length key, a fixed
1195  //key size must be specified as part of the cryptographic
1196  //transform negotiated (refer to RFC 7296, section 2.13)
1197  if(n == (sizeof(IkeTransform) + sizeof(IkeTransformAttr)))
1198  {
1199  //Point to the transform attribute
1200  attr = (IkeTransformAttr *) transform->transformAttr;
1201 
1202  //Check attribute format and type
1203  if(ntohs(attr->type) == ((uint16_t) IKE_ATTR_FORMAT_TV |
1204  (uint16_t) IKE_TRANSFORM_ATTR_TYPE_KEY_LEN))
1205  {
1206  //Check transform identifier and key length
1207  if(transformId == espSupportedEncAlgos[i].id &&
1208  ntohs(attr->length) == (espSupportedEncAlgos[i].keyLen * 8))
1209  {
1210  selectedAlgo = &espSupportedEncAlgos[i];
1211  }
1212  }
1213  }
1214  }
1215  else
1216  {
1217  //The Key Length attribute must not be used with transforms
1218  //that use a fixed-length key (refer to RFC 7296, section 3.3.5)
1219  if(n == sizeof(IkeTransform))
1220  {
1221  //Check transform identifier
1222  if(transformId == espSupportedEncAlgos[i].id)
1223  {
1224  selectedAlgo = &espSupportedEncAlgos[i];
1225  }
1226  }
1227  }
1228  }
1229 
1230  //The Last Substruc field has a value of 0 if this was the last
1231  //Transform Substructure
1232  if(transform->lastSubstruc == IKE_LAST_SUBSTRUC_LAST)
1233  break;
1234 
1235  //Jump to the next Transform substructure
1236  p += n;
1237  length -= n;
1238  }
1239  }
1240  }
1241 
1242  //Return the chosen algorithm, if any
1243  return selectedAlgo;
1244 }
1245 
1246 
1247 /**
1248  * @brief Integrity transform negotiation
1249  * @param[in] childSa Pointer to the Child SA
1250  * @param[in] proposal Pointer to the Proposal substructure
1251  * @param[in] proposalLen Length of the Proposal substructure, in bytes
1252  * @return Selected integrity transform, if any
1253  **/
1254 
1256  const IkeProposal *proposal, size_t proposalLen)
1257 {
1258  //Select the integrity transform to use
1259  return ikeSelectTransform(IKE_TRANSFORM_TYPE_INTEG, espSupportedAuthAlgos,
1260  arraysize(espSupportedAuthAlgos) - 1, proposal, proposalLen);
1261 }
1262 
1263 
1264 /**
1265  * @brief ESN transform negotiation
1266  * @param[in] childSa Pointer to the Child SA
1267  * @param[in] proposal Pointer to the Proposal substructure
1268  * @param[in] proposalLen Length of the Proposal substructure, in bytes
1269  * @return Selected ESN transform, if any
1270  **/
1271 
1273  const IkeProposal *proposal, size_t proposalLen)
1274 {
1275  //Select the ESN transform to use
1276  return ikeSelectTransform(IKE_TRANSFORM_TYPE_ESN, espSupportedEsnTranforms,
1277  arraysize(espSupportedEsnTranforms), proposal, proposalLen);
1278 }
1279 
1280 
1281 /**
1282  * @brief Select a single proposal
1283  * @param[in] childSa Pointer to the Child SA
1284  * @param[in] payload Pointer to the Security Association payload
1285  * @return Error code
1286  **/
1287 
1289  const IkeSaPayload *payload)
1290 {
1291  error_t error;
1292  size_t n;
1293  size_t length;
1294  const uint8_t *p;
1295  const IkeProposal *proposal;
1296  const IkeEncAlgo *encAlgo;
1297 
1298  //Clear the set of parameters
1299  childSa->protocol = IPSEC_PROTOCOL_INVALID;
1300  childSa->encAlgoId = IKE_TRANSFORM_ID_INVALID;
1301  childSa->encKeyLen = 0;
1302  childSa->authAlgoId = IKE_TRANSFORM_ID_INVALID;
1303  childSa->esn = IKE_TRANSFORM_ID_INVALID;
1304 #if (IKE_CHILD_SA_PFS_SUPPORT == ENABLED)
1305  childSa->keContext.groupNum = IKE_TRANSFORM_ID_KE_NONE;
1306 #endif
1307 
1308  //Retrieve the length of the SA payload
1309  length = ntohs(payload->header.payloadLength);
1310 
1311  //Malformed payload?
1312  if(length < sizeof(IkeSaPayload))
1313  return ERROR_INVALID_MESSAGE;
1314 
1315  //Point to the first byte of the Proposals field
1316  p = payload->proposals;
1317  //Determine the length of the Proposals field
1318  length -= sizeof(IkeSaPayload);
1319 
1320  //Initialize status code
1321  error = ERROR_INVALID_PROPOSAL;
1322 
1323  //The Security Association payload contains one or more Proposal
1324  //substructures
1325  while(1)
1326  {
1327  //Malformed payload?
1328  if(length < sizeof(IkeProposal))
1329  {
1330  //Report an error
1331  error = ERROR_INVALID_MESSAGE;
1332  break;
1333  }
1334 
1335  //Point to the Proposal substructure
1336  proposal = (IkeProposal *) p;
1337 
1338  //The Proposal Length field indicates the length of this proposal,
1339  //including all transforms and attributes that follow
1340  n = ntohs(proposal->proposalLength);
1341 
1342  //Check the length of the proposal
1343  if(n < sizeof(IkeProposal) || n > length)
1344  {
1345  //Report an error
1346  error = ERROR_INVALID_MESSAGE;
1347  break;
1348  }
1349 
1350  //Check protocol identifier
1351  if(proposal->protocolId == IKE_PROTOCOL_ID_ESP)
1352  {
1353  //Valid SPI value?
1354  if(proposal->spiSize == IPSEC_SPI_SIZE &&
1355  osMemcmp(proposal->spi, IPSEC_INVALID_SPI, IPSEC_SPI_SIZE) != 0)
1356  {
1357  //Initialize status code
1358  error = NO_ERROR;
1359 
1360  //Encryption transform negotiation
1361  encAlgo = espSelectEncTransform(childSa, proposal, n);
1362 
1363  //Valid encryption transform?
1364  if(encAlgo != NULL)
1365  {
1366  childSa->encAlgoId = encAlgo->id;
1367  childSa->encKeyLen = encAlgo->keyLen;
1368  }
1369  else
1370  {
1371  childSa->encAlgoId = IKE_TRANSFORM_ID_INVALID;
1372  childSa->encKeyLen = 0;
1373  }
1374 
1375  //AEAD algorithm?
1376  if(ikeIsAeadEncAlgo(childSa->encAlgoId))
1377  {
1378  //When an authenticated encryption algorithm is selected as the
1379  //encryption algorithm for any SA, an integrity algorithm must
1380  //not be selected for that SA (refer to RFC 5282, section 8)
1381  childSa->authAlgoId = IKE_TRANSFORM_ID_AUTH_NONE;
1382  }
1383  else
1384  {
1385  //Integrity transform negotiation
1386  childSa->authAlgoId = espSelectAuthTransform(childSa, proposal,
1387  n);
1388  }
1389 
1390  //ESN transform negotiation
1391  childSa->esn = espSelectEsnTransform(childSa, proposal, n);
1392 
1393  //Unacceptable proposal?
1394  if(childSa->encAlgoId == IKE_TRANSFORM_ID_INVALID ||
1395  childSa->authAlgoId == IKE_TRANSFORM_ID_INVALID ||
1396  childSa->esn == IKE_TRANSFORM_ID_INVALID)
1397  {
1398  error = ERROR_INVALID_PROPOSAL;
1399  }
1400 
1401 #if (IKE_CHILD_SA_PFS_SUPPORT == ENABLED)
1402  //Although ESP does not directly include a Diffie-Hellman exchange,
1403  //a Diffie-Hellman group may be negotiated for the Child SA. This
1404  //allows the peers to employ Diffie-Hellman in the CREATE_CHILD_SA
1405  //exchange, providing perfect forward secrecy for the generated
1406  //Child SA keys (refer to RFC 7296, section 3.3.2)
1407  if(childSa->pfs)
1408  {
1409  //Key exchange transform negotiation
1410  childSa->keContext.groupNum = ikeSelectKeTransform(
1411  childSa->context, proposal, n);
1412 
1413  //Unacceptable proposal?
1414  if(childSa->keContext.groupNum == IKE_TRANSFORM_ID_KE_NONE)
1415  {
1416  error = ERROR_INVALID_PROPOSAL;
1417  }
1418  }
1419 #endif
1420  //Valid proposal?
1421  if(!error)
1422  {
1423  //Select ESP security protocol
1424  childSa->protocol = IPSEC_PROTOCOL_ESP;
1425  //Save the number of the proposal that was accepted
1426  childSa->acceptedProposalNum = proposal->proposalNum;
1427 
1428  //The initiator SPI is supplied in the SPI field of the SA
1429  //payload
1430  osMemcpy(childSa->remoteSpi, proposal->spi, proposal->spiSize);
1431 
1432  //Successful negotiation
1433  break;
1434  }
1435  }
1436  }
1437 
1438  //Jump to the next proposal
1439  p += n;
1440  length -= n;
1441  }
1442 
1443  //Return status code
1444  return error;
1445 }
1446 
1447 
1448 /**
1449  * @brief Check whether the selected proposal is acceptable
1450  * @param[in] childSa Pointer to the Child SA
1451  * @param[in] payload Pointer to the Security Association payload
1452  * @return Error code
1453  **/
1454 
1456  const IkeSaPayload *payload)
1457 {
1458  size_t n;
1459  size_t length;
1460  const uint8_t *p;
1461  const IkeProposal *proposal;
1462  const IkeEncAlgo *encAlgo;
1463 
1464  //Clear the set of parameters
1465  childSa->encAlgoId = IKE_TRANSFORM_ID_INVALID;
1466  childSa->encKeyLen = 0;
1467  childSa->authAlgoId = IKE_TRANSFORM_ID_INVALID;
1468  childSa->esn = IKE_TRANSFORM_ID_INVALID;
1469 
1470  //Retrieve the length of the SA payload
1471  length = ntohs(payload->header.payloadLength);
1472 
1473  //Malformed payload?
1474  if(length < sizeof(IkeSaPayload))
1475  return ERROR_INVALID_MESSAGE;
1476 
1477  //Point to the first byte of the Proposals field
1478  p = payload->proposals;
1479  //Determine the length of the Proposals field
1480  length -= sizeof(IkeSaPayload);
1481 
1482  //Malformed payload?
1483  if(length < sizeof(IkeProposal))
1484  return ERROR_INVALID_MESSAGE;
1485 
1486  //Point to the Proposal substructure
1487  proposal = (IkeProposal *) p;
1488 
1489  //The Proposal Length field indicates the length of this proposal,
1490  //including all transforms and attributes that follow
1491  n = ntohs(proposal->proposalLength);
1492 
1493  //The responder must accept a single proposal (refer to RFC 7296,
1494  //section 2.7)
1495  if(n != length)
1496  return ERROR_INVALID_MESSAGE;
1497 
1498  //Check protocol identifier
1499  if(proposal->protocolId != IKE_PROTOCOL_ID_ESP)
1500  return ERROR_INVALID_MESSAGE;
1501 
1502  //During subsequent negotiations, the SPI Size field is equal to the size,
1503  //in octets, of the SPI of the corresponding protocol (4 for ESP and AH)
1504  if(proposal->spiSize != IPSEC_SPI_SIZE)
1505  return ERROR_INVALID_MESSAGE;
1506 
1507  //The SPI value of zero is reserved and must not be sent on the wire (refer
1508  //to RFC 4303, section 2.1)
1509  if(osMemcmp(proposal->spi, IPSEC_INVALID_SPI, IPSEC_SPI_SIZE) == 0)
1510  return ERROR_INVALID_MESSAGE;
1511 
1512  //The responder SPI is supplied in the SPI field of the SA payload
1513  osMemcpy(childSa->remoteSpi, proposal->spi, proposal->spiSize);
1514 
1515  //The accepted cryptographic suite must contain exactly one transform of
1516  //each type included in the proposal (refer to RFC 7296, section 2.7)
1517  if(ikeGetNumTransforms(IKE_TRANSFORM_TYPE_ENCR, proposal, n) != 1 ||
1518  ikeGetNumTransforms(IKE_TRANSFORM_TYPE_ESN, proposal, n) != 1)
1519  {
1520  return ERROR_INVALID_PROPOSAL;
1521  }
1522 
1523  //Get the selected encryption transform
1524  encAlgo = espSelectEncTransform(childSa, proposal, n);
1525 
1526  //Valid encryption transform?
1527  if(encAlgo != NULL)
1528  {
1529  childSa->encAlgoId = encAlgo->id;
1530  childSa->encKeyLen = encAlgo->keyLen;
1531  }
1532 
1533  //AEAD algorithm?
1534  if(ikeIsAeadEncAlgo(childSa->encAlgoId))
1535  {
1536  //When an authenticated encryption algorithm is selected as the encryption
1537  //algorithm for any SA, an integrity algorithm must not be selected for
1538  //that SA (refer to RFC 5282, section 8)
1539  if(ikeGetNumTransforms(IKE_TRANSFORM_TYPE_INTEG, proposal, n) != 0)
1540  return ERROR_INVALID_PROPOSAL;
1541 
1542  //AEAD algorithms combine encryption and integrity into a single operation
1543  childSa->authAlgoId = IKE_TRANSFORM_ID_AUTH_NONE;
1544  }
1545  else
1546  {
1547  //Exactly one integrity transform must be included in the proposal
1548  if(ikeGetNumTransforms(IKE_TRANSFORM_TYPE_INTEG, proposal, n) != 1)
1549  return ERROR_INVALID_PROPOSAL;
1550 
1551  //Get the selected integrity transform
1552  childSa->authAlgoId = espSelectAuthTransform(childSa, proposal, n);
1553  }
1554 
1555  //Get the selected ESN transform
1556  childSa->esn = espSelectEsnTransform(childSa, proposal, n);
1557 
1558  //The initiator of an exchange must check that the accepted offer is
1559  //consistent with one of its proposals, and if not must terminate the
1560  //exchange (refer to RFC 7296, section 3.3.6)
1561  if(childSa->encAlgoId != IKE_TRANSFORM_ID_INVALID &&
1562  childSa->authAlgoId != IKE_TRANSFORM_ID_INVALID &&
1563  childSa->esn != IKE_TRANSFORM_ID_INVALID)
1564  {
1565  return NO_ERROR;
1566  }
1567  else
1568  {
1569  return ERROR_INVALID_PROPOSAL;
1570  }
1571 }
1572 
1573 #endif
@ IKE_TRANSFORM_ID_ENCR_AES_GCM_8
Definition: ike.h:984
@ IKE_TRANSFORM_ID_AUTH_AES_CMAC_96
Definition: ike.h:1037
@ MAC_ALGO_CMAC
@ CIPHER_MODE_CBC
Definition: cipher_modes.h:82
uint_t ikeGetNumTransforms(IkeTransformType transformType, const IkeProposal *proposal, size_t proposalLen)
Get the number of transforms that match a given transform type.
#define IPSEC_SPI_SIZE
Definition: ipsec.h:145
@ IKE_TRANSFORM_ID_AUTH_HMAC_SHA2_384_192
Definition: ike.h:1042
@ IKE_TRANSFORM_ID_AUTH_HMAC_SHA1_96
Definition: ike.h:1031
#define SHA256_HASH_ALGO
Definition: sha256.h:49
@ IKE_TRANSFORM_ID_ENCR_AES_CCM_16
Definition: ike.h:983
const IkeEncAlgo * espSelectEncTransform(IkeChildSaEntry *childSa, const IkeProposal *proposal, size_t proposalLen)
Encryption transform negotiation.
#define SHA1_HASH_ALGO
Definition: sha1.h:49
@ IKE_TRANSFORM_ID_ENCR_AES_CTR
Definition: ike.h:980
#define SHA512_HASH_ALGO
Definition: sha512.h:49
#define IDEA_BLOCK_SIZE
Definition: idea.h:38
@ IKE_TRANSFORM_ID_ENCR_CAMELLIA_CBC
Definition: ike.h:988
uint8_t p
Definition: ndp.h:300
@ IKE_TRANSFORM_ID_ENCR_IDEA
Definition: ike.h:973
@ IKE_TRANSFORM_ID_AUTH_HMAC_MD5_96
Definition: ike.h:1030
Encryption algorithm.
error_t ikeAddTransform(IkeTransformType transformType, uint16_t transformId, uint16_t keyLen, IkeProposal *proposal, uint8_t **lastSubstruc)
Add the supported transforms to the proposal.
uint8_t numTransforms
Definition: ike.h:1503
@ IKE_TRANSFORM_ID_ESN_NO
No Extended Sequence Numbers.
Definition: ike.h:1090
ESP algorithm negotiation.
@ CIPHER_MODE_CTR
Definition: cipher_modes.h:85
#define IDEA_CIPHER_ALGO
Definition: idea.h:40
@ IKE_TRANSFORM_ID_ENCR_CAMELLIA_CCM_8
Definition: ike.h:990
const uint8_t IPSEC_INVALID_SPI[4]
Definition: ipsec_misc.c:40
@ IKE_LAST_SUBSTRUC_LAST
Last proposal/transform substructure.
Definition: ike.h:918
#define osMemcmp(p1, p2, length)
Definition: os_port.h:159
@ IKE_TRANSFORM_ID_ENCR_CAMELLIA_CCM_16
Definition: ike.h:992
@ CIPHER_MODE_NULL
Definition: cipher_modes.h:79
@ ERROR_INVALID_MESSAGE
Definition: error.h:105
IkeTransform
Definition: ike.h:1521
uint16_t ikeSelectTransform(IkeTransformType transformType, const uint16_t *algoList, uint_t algoListLen, const IkeProposal *proposal, size_t proposalLen)
Transform negotiation.
@ IKE_TRANSFORM_ID_ENCR_CHACHA20_POLY1305
Definition: ike.h:993
@ IKE_ATTR_FORMAT_TV
shortened Type/Value format
Definition: ike.h:1102
error_t espSelectSaProposal(IkeChildSaEntry *childSa, const IkeSaPayload *payload)
Select a single proposal.
#define DES3_BLOCK_SIZE
Definition: des3.h:44
@ IPSEC_PROTOCOL_ESP
Definition: ipsec.h:200
@ IKE_TRANSFORM_TYPE_ESN
Extended Sequence Numbers.
Definition: ike.h:949
#define IKE_TRANSFORM_ID_INVALID
#define AES_BLOCK_SIZE
Definition: aes.h:43
@ IKE_TRANSFORM_ID_ENCR_AES_CBC
Definition: ike.h:979
@ IKE_TRANSFORM_ATTR_TYPE_KEY_LEN
Key Length (in bits)
Definition: ike.h:1112
ESP (IP Encapsulating Security Payload)
@ CIPHER_MODE_GMAC
Definition: cipher_modes.h:88
@ CIPHER_MODE_CHACHA20_POLY1305
Definition: cipher_modes.h:91
#define osMemcpy(dest, src, length)
Definition: os_port.h:147
@ ERROR_INVALID_PROPOSAL
Definition: error.h:301
error_t ikeAddSupportedKeTransforms(IkeContext *context, IkeProposal *proposal, uint8_t **lastSubstruc)
Add the supported key exchange transforms to the proposal.
error_t
Error codes.
Definition: error.h:43
@ IKE_TRANSFORM_ID_ENCR_NULL
Definition: ike.h:978
@ ERROR_UNSUPPORTED_ALGO
Definition: error.h:126
@ CIPHER_MODE_GCM
Definition: cipher_modes.h:87
Helper routines for IPsec.
@ IKE_PROTOCOL_ID_ESP
ESP.
Definition: ike.h:932
#define MD5_HASH_ALGO
Definition: md5.h:49
error_t espAddSupportedTransforms(IkeChildSaEntry *childSa, IkeProposal *proposal, uint8_t **lastSubstruc)
Add the supported ESP transforms to the proposal.
error_t espSelectEncAlgo(IkeChildSaEntry *childSa, uint16_t encAlgoId, size_t encKeyLen)
Select the relevant encryption algorithm.
@ IKE_TRANSFORM_ID_ENCR_AES_GCM_12
Definition: ike.h:985
#define CAMELLIA_CIPHER_ALGO
Definition: camellia.h:40
IkeTransformAttr
Definition: ike.h:1533
error_t espAddSupportedAuthTransforms(IkeChildSaEntry *childSa, IkeProposal *proposal, uint8_t **lastSubstruc)
Add the supported integrity transforms to the proposal.
uint16_t keyLen
#define DES_CIPHER_ALGO
Definition: des.h:45
error_t espCheckSaProposal(IkeChildSaEntry *childSa, const IkeSaPayload *payload)
Check whether the selected proposal is acceptable.
@ IKE_TRANSFORM_TYPE_ENCR
Encryption Algorithm.
Definition: ike.h:945
uint8_t length
Definition: tcp.h:375
bool_t ikeIsAeadEncAlgo(uint16_t encAlgoId)
Test if the transform ID identifies an AEAD encryption algorithm.
uint16_t espSelectEsnTransform(IkeChildSaEntry *childSa, const IkeProposal *proposal, size_t proposalLen)
ESN transform negotiation.
#define SHA384_DIGEST_SIZE
Definition: sha384.h:41
#define MD5_DIGEST_SIZE
Definition: md5.h:45
error_t espAddSupportedEsnTransforms(IkeChildSaEntry *childSa, IkeProposal *proposal, uint8_t **lastSubstruc)
Add the supported ESN transforms to the proposal.
@ IKE_TRANSFORM_ID_AUTH_HMAC_SHA2_256_128
Definition: ike.h:1041
@ IKE_TRANSFORM_ID_ENCR_DES
Definition: ike.h:970
Collection of hash algorithms.
#define ntohs(value)
Definition: cpu_endian.h:421
@ IKE_TRANSFORM_ID_KE_NONE
None.
Definition: ike.h:1053
#define SHA384_HASH_ALGO
Definition: sha384.h:45
@ IKE_TRANSFORM_ID_ENCR_NULL_AUTH_AES_GMAC
Definition: ike.h:987
IkeProposal
Definition: ike.h:1505
#define SHA1_DIGEST_SIZE
Definition: sha1.h:45
@ IKE_TRANSFORM_ID_ENCR_3DES
Definition: ike.h:971
@ IKE_TRANSFORM_ID_ENCR_AES_GCM_16
Definition: ike.h:986
@ CIPHER_MODE_CCM
Definition: cipher_modes.h:86
IPsec (IP security)
uint8_t n
uint8_t payload[]
Definition: ipv6.h:308
@ IKE_TRANSFORM_ID_ENCR_AES_CCM_12
Definition: ike.h:982
@ IKE_TRANSFORM_ID_ESN_YES
Extended Sequence Numbers.
Definition: ike.h:1091
#define DES_BLOCK_SIZE
Definition: des.h:43
@ IKE_TRANSFORM_ID_ENCR_CAMELLIA_CTR
Definition: ike.h:989
uint16_t transformId
Definition: ike.h:1519
@ MAC_ALGO_HMAC
#define CAMELLIA_BLOCK_SIZE
Definition: camellia.h:38
#define AES_CIPHER_ALGO
Definition: aes.h:45
bool_t ikeIsVariableLengthKeyEncAlgo(uint16_t encAlgoId)
Test if the transform ID identifies a variable-length key encryption algorithm.
error_t espSelectAuthAlgo(IkeChildSaEntry *childSa, uint16_t authAlgoId)
Select the relevant MAC algorithm.
#define DES3_CIPHER_ALGO
Definition: des3.h:46
@ IKE_TRANSFORM_ID_AUTH_HMAC_SHA2_512_256
Definition: ike.h:1043
unsigned int uint_t
Definition: compiler_port.h:57
@ IKE_TRANSFORM_ID_AUTH_NONE
Definition: ike.h:1029
#define SHA256_DIGEST_SIZE
Definition: sha256.h:45
uint16_t id
#define IkeChildSaEntry
Definition: ike.h:840
uint16_t espSelectAuthTransform(IkeChildSaEntry *childSa, const IkeProposal *proposal, size_t proposalLen)
Integrity transform negotiation.
@ IPSEC_PROTOCOL_INVALID
Definition: ipsec.h:198
#define SHA512_DIGEST_SIZE
Definition: sha512.h:45
IKEv2 algorithm negotiation.
uint16_t ikeSelectKeTransform(IkeContext *context, const IkeProposal *proposal, size_t proposalLen)
Key exchange transform negotiation.
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
IkeSaPayload
Definition: ike.h:1488
#define arraysize(a)
Definition: os_port.h:71
error_t espAddSupportedEncTransforms(IkeChildSaEntry *childSa, IkeProposal *proposal, uint8_t **lastSubstruc)
Add the supported encryption transforms to the proposal.
@ IKE_TRANSFORM_ID_ENCR_CAMELLIA_CCM_12
Definition: ike.h:991
@ IKE_TRANSFORM_ID_ENCR_AES_CCM_8
Definition: ike.h:981
@ IKE_TRANSFORM_TYPE_INTEG
Integrity Algorithm.
Definition: ike.h:947