ike_message_encrypt.c
Go to the documentation of this file.
1 /**
2  * @file ike_message_encrypt.c
3  * @brief IKE message encryption
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2022-2024 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.4.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL IKE_TRACE_LEVEL
33 
34 //Dependencies
35 #include "ike/ike.h"
37 #include "ike/ike_debug.h"
40 #include "aead/aead_algorithms.h"
41 #include "debug.h"
42 
43 //Check IKEv2 library configuration
44 #if (IKE_SUPPORT == ENABLED)
45 
46 
47 /**
48  * @brief Encrypt an outgoing IKE message
49  * @param[in] sa Pointer to the IKE SA
50  * @param[in,out] message IKE message to be encrypted
51  * @param[in,out] messageLen Actual length of the IKE message
52  * @return Error code
53  **/
54 
55 error_t ikeEncryptMessage(IkeSaEntry *sa, uint8_t *message, size_t *messageLen)
56 {
57  error_t error;
58  size_t n;
59  size_t length;
60  uint8_t *p;
61  uint8_t *data;
62  uint8_t *icv;
63  IkeContext *context;
64  IkeHeader *ikeHeader;
65  IkeEncryptedPayload *encryptedPayload;
66  const uint8_t *encKey;
67  const CipherAlgo *cipherAlgo;
68 
69  //Malformed IKE message?
70  if(*messageLen < sizeof(IkeHeader))
71  return ERROR_INVALID_MESSAGE;
72 
73  //Debug message
74  TRACE_DEBUG("IKE message to be encrypted (%" PRIuSIZE " bytes):\r\n", *messageLen);
75  //Dump IKE message for debugging purpose
76  ikeDumpMessage(message, *messageLen);
77 
78  //Point to the IKE header
79  ikeHeader = (IkeHeader *) message;
80 
81  //Point to the IKE payloads
82  p = message + sizeof(IkeHeader);
83  //Get the length of the IKE payloads, in bytes
84  length = *messageLen - sizeof(IkeHeader);
85 
86  //Point to the IKE context
87  context = sa->context;
88  //Cipher algorithm used to encrypt the packet
89  cipherAlgo = sa->cipherAlgo;
90 
91  //The encryption key is obtained from the SK_ei or SK_er key, whichever
92  //is appropriate
93  if(sa->originalInitiator)
94  {
95  encKey = sa->skei;
96  }
97  else
98  {
99  encKey = sa->sker;
100  }
101 
102  //Make room for the Encrypted payload header and initialization vector
103  osMemmove(p + sizeof(IkeEncryptedPayload) + sa->ivLen, p, length);
104 
105  //Point to the Encrypted payload header
106  encryptedPayload = (IkeEncryptedPayload *) p;
107  //Point to the plaintext
108  data = encryptedPayload->iv + sa->ivLen;
109  //Append Padding and Pad Length fields
111  //Point to the Integrity Checksum Value (ICV)
112  icv = data + length;
113 
114  //The Payload Length field of the Encrypted payload header includes the
115  //lengths of the header, initialization vector (IV), encrypted IKE
116  //payloads, Padding, Pad Length, and Integrity Checksum Value (ICV)
117  n = sizeof(IkeEncryptedPayload) + sa->ivLen + length + sa->icvLen;
118 
119  //Format Encrypted payload header
120  encryptedPayload->header.nextPayload = ikeHeader->nextPayload;
121  encryptedPayload->header.critical = FALSE;
122  encryptedPayload->header.reserved = 0;
123  encryptedPayload->header.payloadLength = htons(n);
124 
125  //Consider the length of the IKE header
126  n += sizeof(IkeHeader);
127 
128  //Fix the Next Payload and Length fields of the IKE header
129  ikeHeader->nextPayload = IKE_PAYLOAD_TYPE_SK;
130  ikeHeader->length = htonl(n);
131 
132 #if (IKE_CBC_SUPPORT == ENABLED)
133  //CBC cipher mode?
134  if(sa->cipherMode == CIPHER_MODE_CBC)
135  {
136  uint8_t iv[MAX_CIPHER_BLOCK_SIZE];
137 
138  //Senders must select a new unpredictable IV for every message (refer
139  //to RFC 7296, section 3.14)
140  error = context->prngAlgo->read(context->prngContext, iv, sa->ivLen);
141  //Any error to report?
142  if(error)
143  return error;
144 
145  //For CBC mode ciphers, the length of the initialization vector (IV) is
146  //equal to the block length of the underlying encryption algorithm
147  osMemcpy(encryptedPayload->iv, iv, sa->ivLen);
148 
149  //Initialize cipher context
150  error = cipherAlgo->init(&sa->cipherContext, encKey, sa->encKeyLen);
151  //Any error to report?
152  if(error)
153  return error;
154 
155  //Perform CBC encryption
156  error = cbcEncrypt(cipherAlgo, &sa->cipherContext, iv, data, data,
157  length);
158  //Any error to report?
159  if(error)
160  return error;
161 
162  //The checksum must be computed over the encrypted message. Its length
163  //is determined by the integrity algorithm negotiated
164  error = ikeComputeChecksum(sa, message, n - sa->icvLen, icv);
165  //Any error to report?
166  if(error)
167  return error;
168  }
169  else
170 #endif
171 #if (IKE_CTR_SUPPORT == ENABLED)
172  //CTR cipher mode?
173  if(sa->cipherMode == CIPHER_MODE_CTR)
174  {
175  uint8_t counter[16];
176 
177  //The IV must be chosen by the encryptor in a manner that ensures that
178  //the same IV value is used only once for a given key (refer to RFC 3686,
179  //section 3.1)
180  ikeGenerateIv(sa->iv);
181 
182  //The IV field must be 8 octets when the AES-CTR algorithm is used for
183  //IKEv2 encryption
184  osMemcpy(encryptedPayload->iv, sa->iv, 8);
185 
186  //The counter block is 128 bits, including a 4-octet nonce, 8-octet IV,
187  //and 4-octet block counter, in that order (refer to RFC 5930, section 2)
188  osMemcpy(counter, encKey + sa->encKeyLen, 4);
189  osMemcpy(counter + 4, sa->iv, 8);
190 
191  //The block counter begins with the value of one and increments by one
192  //to generate the next portion of the key stream
193  STORE32BE(1, counter + 12);
194 
195  //Initialize cipher context
196  error = cipherAlgo->init(&sa->cipherContext, encKey, sa->encKeyLen);
197  //Any error to report?
198  if(error)
199  return error;
200 
201  //Perform CTR encryption
202  error = ctrEncrypt(cipherAlgo, &sa->cipherContext,
203  cipherAlgo->blockSize * 8, counter, data, data, length);
204  //Any error to report?
205  if(error)
206  return error;
207 
208  //The checksum must be computed over the encrypted message. Its length
209  //is determined by the integrity algorithm negotiated
210  error = ikeComputeChecksum(sa, message, n - sa->icvLen, icv);
211  //Any error to report?
212  if(error)
213  return error;
214  }
215  else
216 #endif
217 #if (IKE_CCM_8_SUPPORT == ENABLED || IKE_CCM_12_SUPPORT == ENABLED || \
218  IKE_CCM_16_SUPPORT == ENABLED)
219  //CCM AEAD cipher?
220  if(sa->cipherMode == CIPHER_MODE_CCM)
221  {
222  size_t aadLen;
223  uint8_t *aad;
224  uint8_t nonce[11];
225 
226  //The IV must be chosen by the encryptor in a manner that ensures that
227  //the same IV value is used only once for a given key (refer to RFC 5282,
228  //section 3.1)
229  ikeGenerateIv(sa->iv);
230 
231  //The Initialization Vector (IV) must be eight octets
232  osMemcpy(encryptedPayload->iv, sa->iv, 8);
233 
234  //Construct the nonce by concatenating the salt with the IV, in that
235  //order (refer to RFC 5282, section 4)
236  osMemcpy(nonce, encKey + sa->encKeyLen, 3);
237  osMemcpy(nonce + 3, sa->iv, 8);
238 
239  //The associated data must consist of the partial contents of the IKEv2
240  //message, starting from the first octet of the fixed IKE header through
241  //the last octet of the Encrypted payload header (refer to RFC 5282,
242  //section 5.1)
243  aad = message;
244  aadLen = encryptedPayload->iv - message;
245 
246  //Initialize cipher context
247  error = cipherAlgo->init(&sa->cipherContext, encKey, sa->encKeyLen);
248  //Any error to report?
249  if(error)
250  return error;
251 
252  //Authenticated encryption using CCM
253  error = ccmEncrypt(sa->cipherAlgo, &sa->cipherContext, nonce, 11, aad,
254  aadLen, data, data, length, icv, sa->icvLen);
255  //Any error to report?
256  if(error)
257  return error;
258  }
259  else
260 #endif
261 #if (IKE_GCM_8_SUPPORT == ENABLED || IKE_GCM_12_SUPPORT == ENABLED || \
262  IKE_GCM_16_SUPPORT == ENABLED)
263  //GCM AEAD cipher?
264  if(sa->cipherMode == CIPHER_MODE_GCM)
265  {
266  size_t aadLen;
267  uint8_t *aad;
268  uint8_t nonce[12];
269  GcmContext gcmContext;
270 
271  //The IV must be chosen by the encryptor in a manner that ensures that
272  //the same IV value is used only once for a given key (refer to RFC 5282,
273  //section 3.1)
274  ikeGenerateIv(sa->iv);
275 
276  //The Initialization Vector (IV) must be eight octets
277  osMemcpy(encryptedPayload->iv, sa->iv, 8);
278 
279  //Construct the nonce by concatenating the salt with the IV, in that
280  //order (refer to RFC 5282, section 4)
281  osMemcpy(nonce, encKey + sa->encKeyLen, 4);
282  osMemcpy(nonce + 4, sa->iv, 8);
283 
284  //The associated data must consist of the partial contents of the IKEv2
285  //message, starting from the first octet of the fixed IKE header through
286  //the last octet of the Encrypted payload header (refer to RFC 5282,
287  //section 5.1)
288  aad = message;
289  aadLen = encryptedPayload->iv - message;
290 
291  //Initialize cipher context
292  error = cipherAlgo->init(&sa->cipherContext, encKey, sa->encKeyLen);
293  //Any error to report?
294  if(error)
295  return error;
296 
297  //Initialize GCM context
298  error = gcmInit(&gcmContext, sa->cipherAlgo, &sa->cipherContext);
299  //Any error to report?
300  if(error)
301  return error;
302 
303  //Authenticated encryption using GCM
304  error = gcmEncrypt(&gcmContext, nonce, 12, aad, aadLen, data, data,
305  length, icv, sa->icvLen);
306  //Any error to report?
307  if(error)
308  return error;
309  }
310  else
311 #endif
312 #if (IKE_CHACHA20_POLY1305_SUPPORT == ENABLED)
313  //ChaCha20Poly1305 AEAD cipher?
314  if(sa->cipherMode == CIPHER_MODE_CHACHA20_POLY1305)
315  {
316  size_t aadLen;
317  uint8_t *aad;
318  uint8_t nonce[12];
319 
320  //The IV must be unique for each invocation for a particular security
321  //association (SA) but does not need to be unpredictable (refer to
322  //RFC 7634, section 2)
323  ikeGenerateIv(sa->iv);
324 
325  //The IV is 64 bits, and is included explicitly in the Encrypted payload
326  osMemcpy(encryptedPayload->iv, sa->iv, 8);
327 
328  //The 96-bit nonce is formed from a concatenation of the 32-bit salt and
329  //the 64-bit IV (refer to RFC 7634, section 2)
330  osMemcpy(nonce, encKey + sa->encKeyLen, 4);
331  osMemcpy(nonce + 4, sa->iv, 8);
332 
333  //The associated data must consist of the partial contents of the IKEv2
334  //message, starting from the first octet of the fixed IKE header through
335  //the last octet of the Encrypted payload header (refer to RFC 5282,
336  //section 5.1)
337  aad = message;
338  aadLen = encryptedPayload->iv - message;
339 
340  //Authenticated encryption using ChaCha20Poly1305
341  error = chacha20Poly1305Encrypt(encKey, sa->encKeyLen, nonce, 12, aad,
342  aadLen, data, data, length, icv, sa->icvLen);
343  //Any error to report?
344  if(error)
345  return error;
346  }
347  else
348 #endif
349  //Invalid cipher mode?
350  {
351  //The specified cipher mode is not supported
353  }
354 
355  //Total length of the resulting IKE message
356  *messageLen = n;
357 
358  //Successful processing
359  return NO_ERROR;
360 }
361 
362 
363 /**
364  * @brief Compute ICV checksum
365  * @param[in] sa Pointer to the IKE SA
366  * @param[in] message Pointer to the message
367  * @param[in] length Length of the message, in bytes
368  * @param[out] icv Integrity Checksum Value (ICV)
369  * @return Error code
370  **/
371 
373  size_t length, uint8_t *icv)
374 {
375  error_t error;
376  const uint8_t *authKey;
377 
378  //The integrity protection key key is obtained from the SK_ai or SK_ar
379  //key, whichever is appropriate
380  if(sa->originalInitiator)
381  {
382  authKey = sa->skai;
383  }
384  else
385  {
386  authKey = sa->skar;
387  }
388 
389 #if (IKE_HMAC_AUTH_SUPPORT == ENABLED)
390  //HMAC integrity algorithm?
391  if(sa->authHashAlgo != NULL)
392  {
393  HmacContext *hmacContext;
394 
395  //Point to the HMAC context
396  hmacContext = &sa->context->hmacContext;
397 
398  //Initialize HMAC calculation
399  error = hmacInit(hmacContext, sa->authHashAlgo, authKey, sa->authKeyLen);
400 
401  //Check status code
402  if(!error)
403  {
404  //The checksum must be computed over the encrypted message. Its length
405  //is determined by the integrity algorithm negotiated
406  hmacUpdate(hmacContext, message, length);
407  hmacFinal(hmacContext, NULL);
408 
409  //Copy the resulting checksum value
410  osMemcpy(icv, hmacContext->digest, sa->icvLen);
411  }
412  }
413  else
414 #endif
415 #if (IKE_CMAC_AUTH_SUPPORT == ENABLED)
416  //CMAC integrity algorithm?
417  if(sa->authAlgoId == IKE_TRANSFORM_ID_AUTH_AES_CMAC_96 &&
418  sa->authCipherAlgo != NULL)
419  {
420  CmacContext *cmacContext;
421 
422  //Point to the CMAC context
423  cmacContext = &sa->context->cmacContext;
424 
425  //Initialize CMAC calculation
426  error = cmacInit(cmacContext, sa->authCipherAlgo, authKey,
427  sa->authKeyLen);
428 
429  //Check status code
430  if(!error)
431  {
432  //The checksum must be computed over the encrypted message. Its length
433  //is determined by the integrity algorithm negotiated
434  cmacUpdate(cmacContext, message, length);
435  cmacFinal(cmacContext, icv, sa->icvLen);
436  }
437  }
438  else
439 #endif
440 #if (IKE_XCBC_MAC_AUTH_SUPPORT == ENABLED)
441  //XCBC-MAC integrity algorithm?
442  if(sa->authAlgoId == IKE_TRANSFORM_ID_AUTH_AES_XCBC_96 &&
443  sa->authCipherAlgo != NULL)
444  {
445  XcbcMacContext *xcbcMacContext;
446 
447  //Point to the XCBC-MAC context
448  xcbcMacContext = &sa->context->xcbcMacContext;
449 
450  //Initialize XCBC-MAC calculation
451  error = xcbcMacInit(xcbcMacContext, sa->authCipherAlgo, authKey,
452  sa->authKeyLen);
453 
454  //Check status code
455  if(!error)
456  {
457  //The checksum must be computed over the encrypted message. Its length
458  //is determined by the integrity algorithm negotiated
459  xcbcMacUpdate(xcbcMacContext, message, length);
460  xcbcMacFinal(xcbcMacContext, icv, sa->icvLen);
461  }
462  }
463  else
464 #endif
465  //Unknown integrity algorithm?
466  {
467  //Report an error
468  error = ERROR_FAILURE;
469  }
470 
471  //Return status code
472  return error;
473 }
474 
475 
476 /**
477  * @brief Append Padding and Pad Length fields
478  * @param[in] sa Pointer to the IKE SA
479  * @param[in] data Pointer to the payload
480  * @param[in] length Length of the payload, in bytes
481  * @return Length of the resulting padded payload
482  **/
483 
484 size_t ikePadPayload(IkeSaEntry *sa, uint8_t *data, size_t length)
485 {
486 #if (IKE_CBC_SUPPORT == ENABLED)
487  //CBC cipher mode?
488  if(sa->cipherMode == CIPHER_MODE_CBC)
489  {
490  size_t i;
491  size_t n;
492 
493  //The sender should set the Pad Length to the minimum value that makes
494  //the combination of the payloads, the Padding, and the Pad Length a
495  //multiple of the block size (refer to RFC 7296, section 3.14)
496  n = (length + 1) % sa->cipherAlgo->blockSize;
497 
498  //Check whether any padding is required
499  if(n != 0)
500  {
501  //Calculate the length of the Padding field
502  n = sa->cipherAlgo->blockSize - n;
503 
504  //Padding may contain any value chosen by the sender
505  for(i = 1; i <= n; i++)
506  {
507  data[length++] = (uint8_t) i;
508  }
509  }
510 
511  //The Pad Length field is the length of the Padding field
512  data[length++] = (uint8_t) n;
513  }
514  else
515 #endif
516  //AEAD cipher mode?
517  {
518  //There are no alignment requirements on the length of the Padding
519  //field (refer to RFC 5282, section 3)
520  data[length++] = 0;
521  }
522 
523  //Return the length of the resulting padded payload
524  return length;
525 }
526 
527 
528 /**
529  * @brief IV generation
530  * @param[in,out] iv Pointer to the 8-octet initialization vector
531  **/
532 
533 void ikeGenerateIv(uint8_t *iv)
534 {
535  uint16_t temp;
536 
537  //The encryptor may generate the IV in any manner that ensures uniqueness.
538  //Common approaches to IV generation include incrementing a counter for each
539  //packet and linear feedback shift registers (refer to RFC 5282, section 3.1)
540  temp = iv[7] + 1;
541  iv[7] = temp & 0xFF;
542  temp = (temp >> 8) + iv[6];
543  iv[6] = temp & 0xFF;
544  temp = (temp >> 8) + iv[5];
545  iv[5] = temp & 0xFF;
546  temp = (temp >> 8) + iv[4];
547  iv[4] = temp & 0xFF;
548  temp = (temp >> 8) + iv[3];
549  iv[3] = temp & 0xFF;
550  temp = (temp >> 8) + iv[2];
551  iv[2] = temp & 0xFF;
552  temp = (temp >> 8) + iv[1];
553  iv[1] = temp & 0xFF;
554  temp = (temp >> 8) + iv[0];
555  iv[0] = temp & 0xFF;
556 }
557 
558 #endif
uint8_t icv[]
Definition: ah.h:145
__weak_func error_t cbcEncrypt(const CipherAlgo *cipher, void *context, uint8_t *iv, const uint8_t *p, uint8_t *c, size_t length)
CBC encryption.
Definition: cbc.c:61
__weak_func error_t ccmEncrypt(const CipherAlgo *cipher, void *context, const uint8_t *n, size_t nLen, const uint8_t *a, size_t aLen, const uint8_t *p, uint8_t *c, size_t length, uint8_t *t, size_t tLen)
Authenticated encryption using CCM.
Definition: ccm.c:67
error_t chacha20Poly1305Encrypt(const uint8_t *k, size_t kLen, const uint8_t *n, size_t nLen, const uint8_t *a, size_t aLen, const uint8_t *p, uint8_t *c, size_t length, uint8_t *t, size_t tLen)
Authenticated encryption using ChaCha20Poly1305.
uint8_t message[]
Definition: chap.h:154
Collection of AEAD algorithms.
#define MAX_CIPHER_BLOCK_SIZE
Block cipher modes of operation.
error_t cmacFinal(CmacContext *context, uint8_t *mac, size_t macLen)
Finish the CMAC calculation.
Definition: cmac.c:237
void cmacUpdate(CmacContext *context, const void *data, size_t dataLen)
Update the CMAC context with a portion of the message being hashed.
Definition: cmac.c:191
error_t cmacInit(CmacContext *context, const CipherAlgo *cipher, const void *key, size_t keyLen)
Initialize CMAC calculation.
Definition: cmac.c:107
#define PRIuSIZE
#define htonl(value)
Definition: cpu_endian.h:414
#define htons(value)
Definition: cpu_endian.h:413
#define STORE32BE(a, p)
Definition: cpu_endian.h:286
@ CIPHER_MODE_CHACHA20_POLY1305
Definition: crypto.h:951
@ CIPHER_MODE_CCM
Definition: crypto.h:949
@ CIPHER_MODE_CBC
Definition: crypto.h:945
@ CIPHER_MODE_CTR
Definition: crypto.h:948
@ CIPHER_MODE_GCM
Definition: crypto.h:950
__weak_func error_t ctrEncrypt(const CipherAlgo *cipher, void *context, uint_t m, uint8_t *t, const uint8_t *p, uint8_t *c, size_t length)
CTR encryption.
Definition: ctr.c:62
Debugging facilities.
#define TRACE_DEBUG(...)
Definition: debug.h:107
uint8_t n
error_t
Error codes.
Definition: error.h:43
@ ERROR_INVALID_MESSAGE
Definition: error.h:105
@ NO_ERROR
Success.
Definition: error.h:44
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
@ ERROR_UNSUPPORTED_CIPHER_MODE
Definition: error.h:128
uint8_t data[]
Definition: ethernet.h:222
__weak_func error_t gcmInit(GcmContext *context, const CipherAlgo *cipherAlgo, void *cipherContext)
Initialize GCM context.
Definition: gcm.c:99
__weak_func error_t gcmEncrypt(GcmContext *context, const uint8_t *iv, size_t ivLen, const uint8_t *a, size_t aLen, const uint8_t *p, uint8_t *c, size_t length, uint8_t *t, size_t tLen)
Authenticated encryption using GCM.
Definition: gcm.c:214
__weak_func error_t hmacInit(HmacContext *context, const HashAlgo *hash, const void *key, size_t keyLen)
Initialize HMAC calculation.
Definition: hmac.c:140
__weak_func void hmacFinal(HmacContext *context, uint8_t *digest)
Finish the HMAC calculation.
Definition: hmac.c:218
__weak_func void hmacUpdate(HmacContext *context, const void *data, size_t length)
Update the HMAC context with a portion of the message being hashed.
Definition: hmac.c:201
IKEv2 (Internet Key Exchange Protocol)
uint8_t iv[]
Definition: ike.h:1502
@ IKE_TRANSFORM_ID_AUTH_AES_CMAC_96
Definition: ike.h:863
@ IKE_TRANSFORM_ID_AUTH_AES_XCBC_96
Definition: ike.h:860
#define IkeContext
Definition: ike.h:678
IkeEncryptedPayload
Definition: ike.h:1503
@ IKE_PAYLOAD_TYPE_SK
Encrypted and Authenticated.
Definition: ike.h:741
#define IkeSaEntry
Definition: ike.h:682
IkeHeader
Definition: ike.h:1266
void ikeDumpMessage(const uint8_t *message, size_t length)
Dump IKE message.
Definition: ike_debug.c:379
Data logging functions for debugging purpose (IKEv2)
void ikeGenerateIv(uint8_t *iv)
IV generation.
error_t ikeEncryptMessage(IkeSaEntry *sa, uint8_t *message, size_t *messageLen)
Encrypt an outgoing IKE message.
error_t ikeComputeChecksum(IkeSaEntry *sa, const uint8_t *message, size_t length, uint8_t *icv)
Compute ICV checksum.
size_t ikePadPayload(IkeSaEntry *sa, uint8_t *data, size_t length)
Append Padding and Pad Length fields.
IKE message encryption.
uint8_t p
Definition: ndp.h:300
#define osMemmove(dest, src, length)
Definition: os_port.h:147
#define osMemcpy(dest, src, length)
Definition: os_port.h:141
#define FALSE
Definition: os_port.h:46
Common interface for encryption algorithms.
Definition: crypto.h:1036
size_t blockSize
Definition: crypto.h:1040
CipherAlgoInit init
Definition: crypto.h:1041
CMAC algorithm context.
Definition: cmac.h:54
GCM context.
Definition: gcm.h:64
const CipherAlgo * cipherAlgo
Cipher algorithm.
Definition: gcm.h:65
HMAC algorithm context.
Definition: hmac.h:59
uint8_t digest[MAX_HASH_DIGEST_SIZE]
Definition: hmac.h:63
XCBC-MAC algorithm context.
Definition: xcbc_mac.h:54
uint8_t length
Definition: tcp.h:368
error_t xcbcMacFinal(XcbcMacContext *context, uint8_t *mac, size_t macLen)
Finish the XCBC-MAC calculation.
Definition: xcbc_mac.c:229
void xcbcMacUpdate(XcbcMacContext *context, const void *data, size_t dataLen)
Update the XCBC-MAC context with a portion of the message being hashed.
Definition: xcbc_mac.c:183
error_t xcbcMacInit(XcbcMacContext *context, const CipherAlgo *cipher, const void *key, size_t keyLen)
Initialize XCBC-MAC calculation.
Definition: xcbc_mac.c:107