esp_packet_decrypt.c
Go to the documentation of this file.
1 /**
2  * @file esp_packet_decrypt.c
3  * @brief ESP packet decryption
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_inbound.h"
37 #include "esp/esp.h"
38 #include "esp/esp_packet_decrypt.h"
41 #include "aead/aead_algorithms.h"
42 #include "debug.h"
43 
44 //Check IPsec library configuration
45 #if (ESP_SUPPORT == ENABLED)
46 
47 
48 /**
49  * @brief Decrypt an incoming ESP packet
50  * @param[in] context Pointer to the IPsec context
51  * @param[in] sa Pointer to the SAD entry
52  * @param[in] espHeader Pointer to the ESP header
53  * @param[in,out] payload Payload data to be decrypted
54  * @param[in,out] payloadLen Actual length of the payload data
55  * @param[out] nextHeader Value of the next header field
56  * @return Error code
57  **/
58 
60  const EspHeader *espHeader, uint8_t *payload, size_t *payloadLen,
61  uint8_t *nextHeader)
62 {
63  error_t error;
64  size_t i;
65  uint8_t *data;
66  uint8_t *icv;
67  size_t length;
68  const CipherAlgo *cipherAlgo;
69  EspTrailer *espTrailer;
70  uint8_t iv[MAX_CIPHER_BLOCK_SIZE];
71 
72  //Check the length of the payload data
73  if(*payloadLen < (sa->ivLen + sizeof(EspTrailer) + sa->icvLen))
74  return ERROR_INVALID_PACKET;
75 
76  //Determine the length of the ciphertext
77  length = *payloadLen - sa->ivLen - sa->icvLen;
78 
79  //If the algorithm used to encrypt the payload requires an Initialization
80  //Vector (IV), then this data is carried explicitly in the payload field
81  osMemcpy(iv, payload, sa->ivLen);
82 
83  //Point to the ciphertext
84  data = payload + sa->ivLen;
85  //Point to the Integrity Checksum Value (ICV)
86  icv = data + length;
87 
88  //The SAD entry specifies the algorithms and keys to be employed for
89  //decryption (refer to RFC 4303, section 3.4.2)
90  cipherAlgo = sa->cipherAlgo;
91 
92 #if (ESP_NULL_SUPPORT == ENABLED)
93  //Integrity-only ESP?
94  if(sa->cipherMode == CIPHER_MODE_NULL)
95  {
96  //No confidentiality is offered by using the NULL encryption algorithm
97  error = espVerifyChecksum(context, sa, espHeader, context->buffer, length,
98  icv);
99  //Any error to report?
100  if(error)
101  return error;
102  }
103  else
104 #endif
105 #if (ESP_CBC_SUPPORT == ENABLED)
106  //CBC cipher mode?
107  if(sa->cipherMode == CIPHER_MODE_CBC)
108  {
109  //The length of the ciphertext must be a multiple of the block size
110  if((length % cipherAlgo->blockSize) != 0)
111  return ERROR_INVALID_PACKET;
112 
113  //If a separate integrity algorithm is employed, then the receiver
114  //proceeds to integrity verification (refer to RFC 4303, section 3.4.3)
115  error = espVerifyChecksum(context, sa, espHeader, context->buffer,
116  sa->ivLen + length, icv);
117  //Any error to report?
118  if(error)
119  return error;
120 
121  //Initialize cipher context
122  error = cipherAlgo->init(&sa->cipherContext, sa->encKey, sa->encKeyLen);
123  //Any error to report?
124  if(error)
125  return error;
126 
127  //Perform CBC decryption
128  error = cbcDecrypt(cipherAlgo, &sa->cipherContext, iv, data, payload,
129  length);
130  //Any error to report?
131  if(error)
132  return error;
133  }
134  else
135 #endif
136 #if (ESP_CTR_SUPPORT == ENABLED)
137  //CTR cipher mode?
138  if(sa->cipherMode == CIPHER_MODE_CTR)
139  {
140  uint8_t counter[16];
141 
142  //The counter block is 128 bits, including a 4-octet nonce, 8-octet IV,
143  //and 4-octet block counter, in that order (refer to RFC 3686, section 4)
144  osMemcpy(counter, sa->encKey + sa->encKeyLen, 4);
145  osMemcpy(counter + 4, iv, 8);
146 
147  //The block counter begins with the value of one and increments by one
148  //to generate the next portion of the key stream
149  STORE32BE(1, counter + 12);
150 
151  //If a separate integrity algorithm is employed, then the receiver
152  //proceeds to integrity verification (refer to RFC 4303, section 3.4.3)
153  error = espVerifyChecksum(context, sa, espHeader, context->buffer,
154  sa->ivLen + length, icv);
155  //Any error to report?
156  if(error)
157  return error;
158 
159  //Initialize cipher context
160  error = cipherAlgo->init(&sa->cipherContext, sa->encKey, sa->encKeyLen);
161  //Any error to report?
162  if(error)
163  return error;
164 
165  //Perform CTR decryption
166  error = ctrDecrypt(cipherAlgo, &sa->cipherContext,
167  cipherAlgo->blockSize * 8, counter, data, payload, length);
168  //Any error to report?
169  if(error)
170  return error;
171  }
172  else
173 #endif
174 #if (ESP_CCM_8_SUPPORT == ENABLED || ESP_CCM_12_SUPPORT == ENABLED || \
175  ESP_CCM_16_SUPPORT == ENABLED)
176  //CCM AEAD cipher?
177  if(sa->cipherMode == CIPHER_MODE_CCM)
178  {
179  size_t aadLen;
180  uint8_t aad[12];
181  uint8_t nonce[11];
182 
183  //The components of the nonce are the salt with the IV (refer to RFC 4309,
184  //section 4)
185  osMemcpy(nonce, sa->encKey + sa->encKeyLen, 3);
186  osMemcpy(nonce + 3, iv, 8);
187 
188  //Two formats of the AAD are defined (refer to RFC 4309, section 5)
189  if(sa->esn)
190  {
191  //Reconstruct the 64-bit sequence number
192  uint64_t seq = ipsecGetSeqNum(sa, ntohl(espHeader->seqNum));
193 
194  //AAD Format with 64-bit sequence number
195  osMemcpy(aad, (uint8_t *) &espHeader->spi, 4);
196  STORE64BE(seq, aad + 4);
197  aadLen = 12;
198  }
199  else
200  {
201  //AAD Format with 32-bit sequence number
202  osMemcpy(aad, espHeader, 8);
203  aadLen = 8;
204  }
205 
206  //Initialize cipher context
207  error = cipherAlgo->init(&sa->cipherContext, sa->encKey, sa->encKeyLen);
208  //Any error to report?
209  if(error)
210  return error;
211 
212  //Authenticated decryption using CCM
213  error = ccmDecrypt(sa->cipherAlgo, &sa->cipherContext, nonce, 11, aad,
214  aadLen, data, payload, length, icv, sa->icvLen);
215  //Any error to report?
216  if(error)
217  return error;
218  }
219  else
220 #endif
221 #if (ESP_GCM_8_SUPPORT == ENABLED || ESP_GCM_12_SUPPORT == ENABLED || \
222  ESP_GCM_16_SUPPORT == ENABLED)
223  //GCM AEAD cipher?
224  if(sa->cipherMode == CIPHER_MODE_GCM)
225  {
226  size_t aadLen;
227  uint8_t aad[12];
228  uint8_t nonce[12];
229  GcmContext gcmContext;
230 
231  //The components of the nonce are the salt with the IV (refer to RFC 4106,
232  //section 4)
233  osMemcpy(nonce, sa->encKey + sa->encKeyLen, 4);
234  osMemcpy(nonce + 4, iv, 8);
235 
236  //Two formats of the AAD are defined (refer to RFC 4106, section 5)
237  if(sa->esn)
238  {
239  //Reconstruct the 64-bit sequence number
240  uint64_t seq = ipsecGetSeqNum(sa, ntohl(espHeader->seqNum));
241 
242  //AAD Format with 64-bit sequence number
243  osMemcpy(aad, (uint8_t *) &espHeader->spi, 4);
244  STORE64BE(seq, aad + 4);
245  aadLen = 12;
246  }
247  else
248  {
249  //AAD Format with 32-bit sequence number
250  osMemcpy(aad, espHeader, 8);
251  aadLen = 8;
252  }
253 
254  //Initialize cipher context
255  error = cipherAlgo->init(&sa->cipherContext, sa->encKey, sa->encKeyLen);
256  //Any error to report?
257  if(error)
258  return error;
259 
260  //Initialize GCM context
261  error = gcmInit(&gcmContext, sa->cipherAlgo, &sa->cipherContext);
262  //Any error to report?
263  if(error)
264  return error;
265 
266  //Authenticated decryption using GCM
267  error = gcmDecrypt(&gcmContext, nonce, 12, aad, aadLen, data, payload,
268  length, icv, sa->icvLen);
269  //Any error to report?
270  if(error)
271  return error;
272  }
273  else
274 #endif
275 #if (ESP_CHACHA20_POLY1305_SUPPORT == ENABLED)
276  //ChaCha20Poly1305 AEAD cipher?
277  if(sa->cipherMode == CIPHER_MODE_CHACHA20_POLY1305)
278  {
279  size_t aadLen;
280  uint8_t aad[12];
281  uint8_t nonce[12];
282 
283  //The 96-bit nonce is formed from a concatenation of the 32-bit salt and
284  //the 64-bit IV (refer to RFC 7634, section 2)
285  osMemcpy(nonce, sa->encKey + sa->encKeyLen, 4);
286  osMemcpy(nonce + 4, iv, 8);
287 
288  //Extended sequence numbers?
289  if(sa->esn)
290  {
291  //Reconstruct the 64-bit sequence number
292  uint64_t seq = ipsecGetSeqNum(sa, ntohl(espHeader->seqNum));
293 
294  //For SAs with ESN, the AAD is 12 octets: a 4-octet SPI followed by an
295  //8-octet sequence number as a 64-bit integer in big-endian byte order
296  //(refer to RFC 7634, section 2.1)
297  osMemcpy(aad, (uint8_t *) &espHeader->spi, 4);
298  STORE64BE(seq, aad + 4);
299  aadLen = 12;
300  }
301  else
302  {
303  //For SAs with 32-bit sequence numbers, the AAD is 8 octets: a 4-octet
304  //SPI followed by a 4-octet sequence number ordered exactly as it is in
305  //the packet
306  osMemcpy(aad, espHeader, 8);
307  aadLen = 8;
308  }
309 
310  //Authenticated decryption using ChaCha20Poly1305
311  error = chacha20Poly1305Decrypt(sa->encKey, sa->encKeyLen, nonce, 12,
312  aad, aadLen, data, payload, length, icv, sa->icvLen);
313  }
314  else
315 #endif
316 #if (ESP_NULL_SUPPORT == ENABLED && ESP_GMAC_SUPPORT == ENABLED)
317  //GMAC authentication algorithm?
318  if(sa->cipherMode == CIPHER_MODE_GMAC)
319  {
320  size_t i;
321  uint8_t mask;
322  uint8_t temp[16];
323  uint8_t nonce[12];
324  GmacContext gmacContext;
325 
326  //The components of the nonce are the salt with the IV (refer to RFC 4543,
327  //section 3.2)
328  osMemcpy(nonce, sa->encKey + sa->encKeyLen, 4);
329  osMemcpy(nonce + 4, iv, 8);
330 
331  //Initialize GMAC context
332  error = gmacInit(&gmacContext, sa->cipherAlgo, sa->encKey, sa->encKeyLen);
333  //Any error to report?
334  if(error)
335  return error;
336 
337  //The nonce is passed to the AES-GMAC authentication algorithm
338  error = gmacReset(&gmacContext, nonce, 12);
339  //Any error to report?
340  if(error)
341  return error;
342 
343  //Two formats of the AAD are defined (refer to RFC 4543, section 3.3)
344  if(sa->esn)
345  {
346  //Reconstruct the 64-bit sequence number
347  uint64_t seq = ipsecGetSeqNum(sa, ntohl(espHeader->seqNum));
348 
349  //Convert the 64-bit sequence number to network byte order
350  STORE64BE(seq, temp);
351 
352  //The AAD consists of the SPI, 64-bit sequence number, and ESP payload
353  gmacUpdate(&gmacContext, (uint8_t *) &espHeader->spi, 4);
354  gmacUpdate(&gmacContext, temp, 8);
355  gmacUpdate(&gmacContext, iv, 8);
356  gmacUpdate(&gmacContext, data, length);
357  }
358  else
359  {
360  //The AAD consists of the SPI, 32-bit sequence number, and ESP payload
361  gmacUpdate(&gmacContext, espHeader, sizeof(EspHeader));
362  gmacUpdate(&gmacContext, iv, 8);
363  gmacUpdate(&gmacContext, data, length);
364  }
365 
366  //Finalize GMAC computation
367  error = gmacFinal(&gmacContext, temp, sa->icvLen);
368  //Any error to report?
369  if(error)
370  return error;
371 
372  //The computed ICV is bitwise compared to the received ICV
373  for(mask = 0, i = 0; i < sa->icvLen; i++)
374  {
375  mask |= temp[i] ^ icv[i];
376  }
377 
378  //If the computed and received ICVs match, then the datagram is valid,
379  //and it is accepted (refer to RFC 4303, section 3.4.4.1)
380  if(mask != 0)
382 
383  //Copy payload data
385  }
386  else
387 #endif
388  //Invalid cipher mode?
389  {
390  //The specified cipher mode is not supported
392  }
393 
394  //Point to the ESP trailer
395  length -= sizeof(EspTrailer);
396  espTrailer = (EspTrailer *) (payload + length);
397 
398  //The Pad Length field is the length of the Padding field
399  if(espTrailer->padLength > length)
401 
402  //The receiver should inspect the Padding field (refer to RFC 4303,
403  //section 2.4)
404  for(i = 0; i < espTrailer->padLength; i++)
405  {
406  //Padding bytes make up a monotonically increasing sequence
407  if(payload[length - espTrailer->padLength + i] != (i + 1))
409  }
410 
411  //Remove the padding prior to passing the decrypted data to the next layer
412  *payloadLen = length - espTrailer->padLength;
413 
414  //The Next Header field identifies the type of data contained in the
415  //payload data (refer to RFC 4303, section 2.6)
416  *nextHeader = espTrailer->nextHeader;
417 
418  //Successful processing
419  return NO_ERROR;
420 }
421 
422 
423 /**
424  * @brief Verify ICV checksum
425  * @param[in] context Pointer to the IPsec context
426  * @param[in] sa Pointer to the SAD entry
427  * @param[in] espHeader Pointer to the ESP header
428  * @param[in] payload Pointer to the payload data
429  * @param[in] length Length of the payload data, in bytes
430  * @param[in] icv Integrity Checksum Value (ICV)
431  * @return Error code
432  **/
433 
435  const EspHeader *espHeader, const uint8_t *payload, size_t length,
436  const uint8_t *icv)
437 {
438  error_t error;
439  size_t i;
440  uint8_t mask;
441  uint8_t checksum[ESP_MAX_DIGEST_SIZE];
442 
443 #if (ESP_CMAC_SUPPORT == ENABLED)
444  //CMAC integrity algorithm?
445  if(sa->authMacAlgo == MAC_ALGO_CMAC)
446  {
447  CmacContext *cmacContext;
448 
449  //Point to the CMAC context
450  cmacContext = &context->macContext.cmacContext;
451 
452  //The SAD entry specifies the algorithms and keys to be employed for
453  //decryption and ICV computation (refer to RFC 4303, section 3.4.2)
454  error = cmacInit(cmacContext, sa->authCipherAlgo, sa->authKey,
455  sa->authKeyLen);
456 
457  //Check status code
458  if(!error)
459  {
460  //The receiver computes the ICV over the ESP packet minus the ICV,
461  //using the specified integrity algorithm
462  cmacUpdate(cmacContext, espHeader, sizeof(EspHeader));
463  cmacUpdate(cmacContext, payload, length);
464 
465  //Extended sequence number?
466  if(sa->esn)
467  {
468  //Determine the higher-order bits of the sequence number
469  uint32_t seqh = ipsecGetSeqNum(sa, ntohl(espHeader->seqNum)) >> 32;
470 
471  //Convert the 32-bit value to network byte order
472  seqh = htonl(seqh);
473 
474  //The high-order 32 bits are maintained as part of the sequence
475  //number counter by both transmitter and receiver and are included
476  //in the computation of the ICV (refer to RFC 4303, section 2.2.1)
477  cmacUpdate(cmacContext, (uint8_t *) &seqh, 4);
478  }
479 
480  //Finalize CMAC computation
481  cmacFinal(cmacContext, checksum, sa->icvLen);
482  }
483  }
484  else
485 #endif
486 #if (ESP_HMAC_SUPPORT == ENABLED)
487  //HMAC integrity algorithm?
488  if(sa->authMacAlgo == MAC_ALGO_HMAC)
489  {
490  HmacContext *hmacContext;
491 
492  //Point to the HMAC context
493  hmacContext = &context->macContext.hmacContext;
494 
495  //The SAD entry specifies the algorithms and keys to be employed for
496  //decryption and ICV computation (refer to RFC 4303, section 3.4.2)
497  error = hmacInit(hmacContext, sa->authHashAlgo, sa->authKey,
498  sa->authKeyLen);
499 
500  //Check status code
501  if(!error)
502  {
503  //The receiver computes the ICV over the ESP packet minus the ICV,
504  //using the specified integrity algorithm
505  hmacUpdate(hmacContext, espHeader, sizeof(EspHeader));
506  hmacUpdate(hmacContext, payload, length);
507 
508  //Extended sequence number?
509  if(sa->esn)
510  {
511  //Determine the higher-order bits of the sequence number
512  uint32_t seqh = ipsecGetSeqNum(sa, ntohl(espHeader->seqNum)) >> 32;
513 
514  //Convert the 32-bit value to network byte order
515  seqh = htonl(seqh);
516 
517  //The high-order 32 bits are maintained as part of the sequence
518  //number counter by both transmitter and receiver and are included
519  //in the computation of the ICV (refer to RFC 4303, section 2.2.1)
520  hmacUpdate(hmacContext, (uint8_t *) &seqh, 4);
521  }
522 
523  //Finalize HMAC computation
524  hmacFinal(hmacContext, checksum);
525  }
526  }
527  else
528 #endif
529  //Unknown integrity algorithm?
530  {
531  //Report an error
532  error = ERROR_DECRYPTION_FAILED;
533  }
534 
535  //Check status code
536  if(!error)
537  {
538  //The computed ICV is bitwise compared to the received ICV
539  for(mask = 0, i = 0; i < sa->icvLen; i++)
540  {
541  mask |= checksum[i] ^ icv[i];
542  }
543 
544  //If the computed and received ICVs match, then the datagram is valid,
545  //and it is accepted (refer to RFC 4303, section 3.4.4.1)
546  error = (mask == 0) ? NO_ERROR : ERROR_DECRYPTION_FAILED;
547  }
548 
549  //Return status code
550  return error;
551 }
552 
553 #endif
@ MAC_ALGO_CMAC
@ CIPHER_MODE_CBC
Definition: cipher_modes.h:82
__weak_func error_t ccmDecrypt(const CipherAlgo *cipher, void *context, const uint8_t *n, size_t nLen, const uint8_t *a, size_t aLen, const uint8_t *c, uint8_t *p, size_t length, const uint8_t *t, size_t tLen)
Authenticated decryption using CCM.
Definition: ccm.c:208
uint8_t icv[]
Definition: ah.h:177
HMAC algorithm context.
Definition: hmac.h:59
@ ERROR_DECRYPTION_FAILED
Definition: error.h:243
uint16_t checksum
Definition: tcp.h:362
Collection of cipher algorithms.
error_t espVerifyChecksum(IpsecContext *context, IpsecSadEntry *sa, const EspHeader *espHeader, const uint8_t *payload, size_t length, const uint8_t *icv)
Verify ICV checksum.
uint8_t data[]
Definition: ethernet.h:224
ESP packet decryption.
@ CIPHER_MODE_CTR
Definition: cipher_modes.h:85
size_t blockSize
Definition: crypto.h:1289
error_t ctrDecrypt(const CipherAlgo *cipher, void *context, uint_t m, uint8_t *t, const uint8_t *c, uint8_t *p, size_t length)
CTR decryption.
Definition: ctr.c:126
@ CIPHER_MODE_NULL
Definition: cipher_modes.h:79
__weak_func error_t gcmInit(GcmContext *context, const CipherAlgo *cipherAlgo, void *cipherContext)
Initialize GCM context.
Definition: gcm.c:99
error_t gmacInit(GmacContext *context, const CipherAlgo *cipher, const void *key, size_t keyLen)
Initialize GMAC calculation.
Definition: gmac.c:160
uint64_t ipsecGetSeqNum(IpsecSadEntry *sa, uint32_t seql)
Determine the higher-order bits of the sequence number.
#define MAX_CIPHER_BLOCK_SIZE
CipherAlgoInit init
Definition: crypto.h:1290
ESP (IP Encapsulating Security Payload)
#define ESP_MAX_DIGEST_SIZE
Definition: esp.h:284
@ ERROR_UNSUPPORTED_CIPHER_MODE
Definition: error.h:128
@ CIPHER_MODE_GMAC
Definition: cipher_modes.h:88
@ CIPHER_MODE_CHACHA20_POLY1305
Definition: cipher_modes.h:91
#define htonl(value)
Definition: cpu_endian.h:414
#define osMemcpy(dest, src, length)
Definition: os_port.h:147
error_t
Error codes.
Definition: error.h:43
@ CIPHER_MODE_GCM
Definition: cipher_modes.h:87
@ ERROR_INVALID_PACKET
Definition: error.h:141
EspTrailer
Definition: esp.h:327
uint8_t nextHeader
Definition: ipv6.h:304
uint8_t mask
Definition: web_socket.h:319
uint8_t iv[]
Definition: ike.h:1695
Block cipher modes of operation.
const CipherAlgo * cipherAlgo
Cipher algorithm.
Definition: gcm.h:65
uint8_t length
Definition: tcp.h:375
IPsec processing of inbound IP traffic.
CMAC algorithm context.
Definition: cmac.h:54
#define IpsecSadEntry
Definition: ipsec.h:36
EspHeader
Definition: esp.h:315
__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
Collection of AEAD algorithms.
GCM context.
Definition: gcm.h:64
#define STORE64BE(a, p)
Definition: cpu_endian.h:322
@ CIPHER_MODE_CCM
Definition: cipher_modes.h:86
IPsec (IP security)
uint8_t payload[]
Definition: ipv6.h:308
__weak_func void hmacFinal(HmacContext *context, uint8_t *digest)
Finish the HMAC calculation.
Definition: hmac.c:218
__weak_func error_t cbcDecrypt(const CipherAlgo *cipher, void *context, uint8_t *iv, const uint8_t *c, uint8_t *p, size_t length)
CBC decryption.
Definition: cbc.c:108
error_t espDecryptPacket(IpsecContext *context, IpsecSadEntry *sa, const EspHeader *espHeader, uint8_t *payload, size_t *payloadLen, uint8_t *nextHeader)
Decrypt an incoming ESP packet.
void gmacUpdate(GmacContext *context, const void *data, size_t dataLen)
Update the GMAC context with a portion of the message being hashed.
Definition: gmac.c:361
#define IpsecContext
Definition: ipsec.h:40
Common interface for encryption algorithms.
Definition: crypto.h:1285
@ MAC_ALGO_HMAC
GMAC algorithm context.
Definition: gmac.h:70
error_t cmacInit(CmacContext *context, const CipherAlgo *cipher, const void *key, size_t keyLen)
Initialize CMAC calculation.
Definition: cmac.c:107
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 gmacReset(GmacContext *context, const uint8_t *iv, size_t ivLen)
Reset GMAC context.
Definition: gmac.c:284
uint16_t payloadLen
Definition: ipv6.h:303
error_t chacha20Poly1305Decrypt(const uint8_t *k, size_t kLen, const uint8_t *n, size_t nLen, const uint8_t *a, size_t aLen, const uint8_t *c, uint8_t *p, size_t length, const uint8_t *t, size_t tLen)
Authenticated decryption using ChaCha20Poly1305.
error_t gmacFinal(GmacContext *context, uint8_t *mac, size_t macLen)
Finish the GMAC calculation.
Definition: gmac.c:404
__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 error_t gcmDecrypt(GcmContext *context, const uint8_t *iv, size_t ivLen, const uint8_t *a, size_t aLen, const uint8_t *c, uint8_t *p, size_t length, const uint8_t *t, size_t tLen)
Authenticated decryption using GCM.
Definition: gcm.c:356
error_t cmacFinal(CmacContext *context, uint8_t *mac, size_t macLen)
Finish the CMAC calculation.
Definition: cmac.c:237
#define STORE32BE(a, p)
Definition: cpu_endian.h:286
#define ntohl(value)
Definition: cpu_endian.h:422
uint8_t nonce[]
Definition: ntp_common.h:239
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.