ike_kdf.c
Go to the documentation of this file.
1 /**
2  * @file ike_kdf.c
3  * @brief IKEv2 key derivation functions
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO 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 CRYPTO_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "kdf/ike_kdf.h"
37 
38 //Check crypto library configuration
39 #if (IKE_KDF_SUPPORT == ENABLED)
40 
41 
42 /**
43  * @brief Pseudorandom function (prf function)
44  * @param[in] macAlgo PRF algorithm (CMAC, HMAC, KMAC or XCBC-MAC)
45  * @param[in] hashAlgo Underlying hash function (for HMAC)
46  * @param[in] cipherAlgo Underlying cipher algorithm (for CMAC and XCBC-MAC)
47  * @param[in] key Pointer to the key
48  * @param[in] keyLen Length of the key, in bytes
49  * @param[in] data Pointer to the data
50  * @param[in] dataLen Length of the data, in bytes
51  * @param[in] output Pseudorandom output
52  * @return Error code
53  **/
54 
55 error_t ikePrf(MacAlgo macAlgo, const HashAlgo *hashAlgo,
56  const CipherAlgo *cipherAlgo, const uint8_t *key, size_t keyLen,
57  const uint8_t *data, size_t dataLen, uint8_t *output)
58 {
59  error_t error;
60  DataFrag dataFrags[1];
61 
62  //Check parameters
63  if(data == NULL && dataLen != 0)
65 
66  //The data fits in a single fragment
67  dataFrags[0].buffer = data;
68  dataFrags[0].length = dataLen;
69 
70  //Perform PRF calculation
71  error = ikePrfEx(macAlgo, hashAlgo, cipherAlgo, key, keyLen, dataFrags,
72  arraysize(dataFrags), output);
73 
74  //Return status code
75  return error;
76 }
77 
78 
79 /**
80  * @brief Pseudorandom function (prf function)
81  * @param[in] macAlgo PRF algorithm (CMAC, HMAC, KMAC or XCBC-MAC)
82  * @param[in] hashAlgo Underlying hash function (for HMAC)
83  * @param[in] cipherAlgo Underlying cipher algorithm (for CMAC and XCBC-MAC)
84  * @param[in] key Pointer to the key
85  * @param[in] keyLen Length of the key, in bytes
86  * @param[in] dataFrags Array of fragments representing the data
87  * @param[in] dataNumFrags Number of fragments representing the data
88  * @param[in] output Pseudorandom output
89  * @return Error code
90  **/
91 
92 error_t ikePrfEx(MacAlgo macAlgo, const HashAlgo *hashAlgo,
93  const CipherAlgo *cipherAlgo, const uint8_t *key, size_t keyLen,
94  const DataFrag *dataFrags, uint_t dataNumFrags, uint8_t *output)
95 {
96  error_t error;
97  uint_t i;
98 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
99  IkePrfContext *context;
100 #else
101  IkePrfContext context[1];
102 #endif
103 
104 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
105  //Allocate a memory buffer to hold the IKE PRF context
106  context = cryptoAllocMem(sizeof(IkePrfContext));
107  //Failed to allocate memory?
108  if(context == NULL)
109  return ERROR_OUT_OF_MEMORY;
110 #endif
111 
112  //Initialize PRF calculation
113  error = ikePrfInit(context, macAlgo, hashAlgo, cipherAlgo, key, keyLen);
114 
115  //Check status code
116  if(!error)
117  {
118  //Process the data
119  for(i = 0; i < dataNumFrags; i++)
120  {
121  ikePrfUpdate(context, dataFrags[i].buffer, dataFrags[i].length);
122  }
123 
124  //Finalize PRF calculation
125  error = ikePrfFinal(context, output, context->outputLen);
126  }
127 
128 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
129  //Free previously allocated memory
130  cryptoFreeMem(context);
131 #endif
132 
133  //Return status code
134  return error;
135 }
136 
137 
138 /**
139  * @brief Function that outputs a pseudorandom stream (prf+ function)
140  * @param[in] macAlgo PRF algorithm (CMAC, HMAC, KMAC or XCBC-MAC)
141  * @param[in] hashAlgo Underlying hash function (for HMAC)
142  * @param[in] cipherAlgo Underlying cipher algorithm (for CMAC and XCBC-MAC)
143  * @param[in] key Pointer to the key
144  * @param[in] keyLen Length of the key, in bytes
145  * @param[in] data Pointer to the data
146  * @param[in] dataLen Length of the data, in bytes
147  * @param[out] output Pseudorandom output stream
148  * @param[in] outputLen Desired length of the pseudorandom output stream
149  * @return Error code
150  **/
151 
152 error_t ikePrfPlus(MacAlgo macAlgo, const HashAlgo *hashAlgo,
153  const CipherAlgo *cipherAlgo, const uint8_t *key, size_t keyLen,
154  const uint8_t *data, size_t dataLen, uint8_t *output,
155  size_t outputLen)
156 {
157  error_t error;
158  DataFrag dataFrags[1];
159 
160  //Check parameters
161  if(data == NULL && dataLen != 0)
163 
164  //The data fits in a single fragment
165  dataFrags[0].buffer = data;
166  dataFrags[0].length = dataLen;
167 
168  //Perform PRF calculation
169  error = ikePrfPlusEx(macAlgo, hashAlgo, cipherAlgo, key, keyLen, dataFrags,
170  arraysize(dataFrags), output, outputLen);
171 
172  //Return status code
173  return error;
174 }
175 
176 
177 /**
178  * @brief Function that outputs a pseudorandom stream (prf+ function)
179  * @param[in] macAlgo PRF algorithm (CMAC, HMAC, KMAC or XCBC-MAC)
180  * @param[in] hashAlgo Underlying hash function (for HMAC)
181  * @param[in] cipherAlgo Underlying cipher algorithm (for CMAC and XCBC-MAC)
182  * @param[in] key Pointer to the key
183  * @param[in] keyLen Length of the key, in bytes
184  * @param[in] dataFrags Array of fragments representing the data
185  * @param[in] dataNumFrags Number of fragments representing the data
186  * @param[out] output Pseudorandom output stream
187  * @param[in] outputLen Desired length of the pseudorandom output stream
188  * @return Error code
189  **/
190 
191 error_t ikePrfPlusEx(MacAlgo macAlgo, const HashAlgo *hashAlgo,
192  const CipherAlgo *cipherAlgo, const uint8_t *key, size_t keyLen,
193  const DataFrag *dataFrags, uint_t dataNumFrags, uint8_t *output,
194  size_t outputLen)
195 {
196  error_t error;
197  uint_t i;
198  size_t n;
199  uint8_t c;
200  uint8_t t[MAX_HASH_DIGEST_SIZE];
201 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
202  IkePrfContext *context;
203 #else
204  IkePrfContext context[1];
205 #endif
206 
207 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
208  //Allocate a memory buffer to hold the IKE PRF context
209  context = cryptoAllocMem(sizeof(IkePrfContext));
210  //Failed to allocate memory?
211  if(context == NULL)
212  return ERROR_OUT_OF_MEMORY;
213 #endif
214 
215  //Initialize counter value
216  c = 1;
217 
218  //Variable-length output PRF?
219  if(macAlgo == MAC_ALGO_KMAC128 || macAlgo == MAC_ALGO_KMAC256)
220  {
221  //A single call to the PRF can produce as many pseudorandom bits as
222  //needed
223  error = ikePrfInit(context, macAlgo, NULL, NULL, key, keyLen);
224 
225  //Check status code
226  if(!error)
227  {
228  //Compute prf+ (K,S) = prf (K, S | 0x01)
229  for(i = 0; i < dataNumFrags; i++)
230  {
231  ikePrfUpdate(context, dataFrags[i].buffer, dataFrags[i].length);
232  }
233 
234  ikePrfUpdate(context, &c, sizeof(uint8_t));
235 
236  //Finalize PRF calculation
237  error = ikePrfFinal(context, output, outputLen);
238  }
239  }
240  else
241  {
242  //Initialize status code
243  error = NO_ERROR;
244 
245  //Since the amount of keying material needed may be greater than the size
246  //of the output of the PRF, the PRF is used iteratively
247  while(outputLen > 0)
248  {
249  //The prf+ function is not defined beyond 255 times the size of the
250  //prf function output (refer to RFC 7296, section 2.13)
251  if(c == 0)
252  return ERROR_INVALID_LENGTH;
253 
254  //Initialize PRF calculation
255  error = ikePrfInit(context, macAlgo, hashAlgo, cipherAlgo, key,
256  keyLen);
257  //Any error to report?
258  if(error)
259  break;
260 
261  //Compute T(n) = prf(K, T(n-1) | S | c)
262  if(c > 1)
263  {
264  ikePrfUpdate(context, t, context->outputLen);
265  }
266 
267  for(i = 0; i < dataNumFrags; i++)
268  {
269  ikePrfUpdate(context, dataFrags[i].buffer, dataFrags[i].length);
270  }
271 
272  ikePrfUpdate(context, &c, sizeof(uint8_t));
273 
274  //Finalize PRF calculation
275  error = ikePrfFinal(context, t, context->outputLen);
276  //Any error to report?
277  if(error)
278  break;
279 
280  //Calculate the number of bytes to copy
281  n = MIN(outputLen, context->outputLen);
282  //Copy the output of the PRF
283  osMemcpy(output, t, n);
284 
285  //This process is repeated until enough key material is available
286  output += n;
287  outputLen -= n;
288 
289  //Increment counter value
290  c++;
291  }
292  }
293 
294 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
295  //Free previously allocated memory
296  cryptoFreeMem(context);
297 #endif
298 
299  //Return status code
300  return error;
301 }
302 
303 
304 /**
305  * @brief Initialize PRF calculation
306  * @param[in] context Pointer to the IKE PRF context
307  * @param[in] macAlgo PRF algorithm (CMAC, HMAC, KMAC or XCBC-MAC)
308  * @param[in] hashAlgo Underlying hash function (for HMAC)
309  * @param[in] cipherAlgo Underlying cipher algorithm (for CMAC and XCBC-MAC)
310  * @param[in] key Pointer to the key
311  * @param[in] keyLen Length of the key, in bytes
312  * @return Error code
313  **/
314 
316  const HashAlgo *hashAlgo, const CipherAlgo *cipherAlgo, const uint8_t *key,
317  size_t keyLen)
318 {
319  error_t error;
320 
321  //Initialize status code
322  error = NO_ERROR;
323 
324 #if (CMAC_SUPPORT == ENABLED)
325  //CMAC PRF algorithm?
326  if(macAlgo == MAC_ALGO_CMAC && cipherAlgo != NULL &&
327  cipherAlgo->blockSize == 16)
328  {
329  uint8_t k[16];
330  CmacContext *cmacContext;
331 
332  //Save PRF algorithm
333  context->macAlgo = MAC_ALGO_CMAC;
334  context->outputLen = 16;
335 
336  //Point to the CMAC context
337  cmacContext = &context->macContext.cmacContext;
338 
339  //Derive the 128-bit key K from the variable-length key VK
340  if(keyLen == 16)
341  {
342  //If the key VK is exactly 128 bits, then we use it as-is
343  osMemcpy(k, key, keyLen);
344  }
345  else
346  {
347  //If the key VK is longer or shorter than 128 bits, then we derive the
348  //key K by applying the AES-CMAC algorithm using the 128-bit all-zero
349  //string as the key and VK as the input message (refer to RFC 4615,
350  //section 3)
351  osMemset(k, 0, 16);
352 
353  //Initialize CMAC calculation
354  error = cmacInit(cmacContext, cipherAlgo, k, 16);
355 
356  //Check status code
357  if(!error)
358  {
359  //Compute K = AES-CMAC(0^128, VK, VKlen)
360  cmacUpdate(cmacContext, key, keyLen);
361 
362  //Derive the 128-bit key K
363  error = cmacFinal(cmacContext, k, 16);
364  }
365  }
366 
367  //Check status code
368  if(!error)
369  {
370  //We apply the AES-CMAC algorithm using K as the key
371  error = cmacInit(cmacContext, cipherAlgo, k, 16);
372  }
373  }
374  else
375 #endif
376 #if (HMAC_SUPPORT == ENABLED)
377  //HMAC PRF algorithm?
378  if(macAlgo == MAC_ALGO_HMAC && hashAlgo != NULL)
379  {
380  //Save PRF algorithm
381  context->macAlgo = MAC_ALGO_HMAC;
382  context->outputLen = hashAlgo->digestSize;
383 
384  //Initialize HMAC calculation
385  error = hmacInit(&context->macContext.hmacContext, hashAlgo, key, keyLen);
386  }
387  else
388 #endif
389 #if (KMAC_SUPPORT == ENABLED)
390  //KMAC PRF algorithm?
391  if(macAlgo == MAC_ALGO_KMAC128 || macAlgo == MAC_ALGO_KMAC256)
392  {
393  uint_t strength;
394 
395  //Save PRF algorithm
396  context->macAlgo = macAlgo;
397 
398  //The security strength depends on the KMAC variant
399  if(macAlgo == MAC_ALGO_KMAC128)
400  {
401  strength = 128;
402  context->outputLen = 32;
403  }
404  else
405  {
406  strength = 256;
407  context->outputLen = 64;
408  }
409 
410  //KMAC's customization string C is always empty
411  error = kmacInit(&context->macContext.kmacContext, strength, key, keyLen,
412  NULL, 0);
413  }
414  else
415 #endif
416 #if (XCBC_MAC_SUPPORT == ENABLED)
417  //XCBC-MAC PRF algorithm?
418  if(macAlgo == MAC_ALGO_XCBC_MAC && cipherAlgo != NULL &&
419  cipherAlgo->blockSize == 16)
420  {
421  uint8_t k[16];
422  XcbcMacContext *xcbcMacContext;
423 
424  //Save PRF algorithm
425  context->macAlgo = MAC_ALGO_XCBC_MAC;
426  context->outputLen = 16;
427 
428  //Point to the XCBC-MAC context
429  xcbcMacContext = &context->macContext.xcbcMacContext;
430 
431  //Derive the 128-bit key K from the variable-length key VK
432  if(keyLen == 16)
433  {
434  //If the key is exactly 128 bits long, use it as-is
435  osMemcpy(k, key, keyLen);
436  }
437  else if(keyLen < 16)
438  {
439  //If the key has fewer than 128 bits, lengthen it to exactly 128 bits
440  //by padding it on the right with zero bits
441  osMemcpy(k, key, keyLen);
442  osMemset(k + keyLen, 0, 16 - keyLen);
443  }
444  else
445  {
446  //If the key is 129 bits or longer, shorten it to exactly 128 bits
447  //by performing the steps in AES-XCBC-PRF-128 (refer to RFC 4434,
448  //section 2)
449  osMemset(k, 0, 16);
450 
451  //The key is 128 zero bits
452  error = xcbcMacInit(xcbcMacContext, cipherAlgo, k, 16);
453 
454  //Check status code
455  if(!error)
456  {
457  //The message is the too-long current key
458  xcbcMacUpdate(xcbcMacContext, key, keyLen);
459 
460  //Derive the 128-bit key K
461  error = xcbcMacFinal(xcbcMacContext, k, 16);
462  }
463  }
464 
465  //Check status code
466  if(!error)
467  {
468  //We apply the XCBC-MAC algorithm using K as the key
469  error = xcbcMacInit(xcbcMacContext, cipherAlgo, k, 16);
470  }
471  }
472  else
473 #endif
474  //Unknown PRF algorithm?
475  {
476  //Report an error
477  error = ERROR_FAILURE;
478  }
479 
480  //Return status code
481  return error;
482 }
483 
484 
485 /**
486  * @brief Update PRF calculation
487  * @param[in] context Pointer to the IKE PRF context
488  * @param[in] data Pointer to the data
489  * @param[in] dataLen Length of the data, in bytes
490  **/
491 
492 void ikePrfUpdate(IkePrfContext *context, const uint8_t *data, size_t dataLen)
493 {
494 #if (CMAC_SUPPORT == ENABLED)
495  //CMAC PRF algorithm?
496  if(context->macAlgo == MAC_ALGO_CMAC)
497  {
498  //Update CMAC calculation
500  }
501  else
502 #endif
503 #if (HMAC_SUPPORT == ENABLED)
504  //HMAC PRF algorithm?
505  if(context->macAlgo == MAC_ALGO_HMAC)
506  {
507  //Update HMAC calculation
509  }
510  else
511 #endif
512 #if (KMAC_SUPPORT == ENABLED)
513  //KMAC PRF algorithm?
514  if(context->macAlgo == MAC_ALGO_KMAC128 ||
515  context->macAlgo == MAC_ALGO_KMAC256)
516  {
517  //Update KMAC calculation
519  }
520  else
521 #endif
522 #if (XCBC_MAC_SUPPORT == ENABLED)
523  //XCBC-MAC PRF algorithm?
524  if(context->macAlgo == MAC_ALGO_XCBC_MAC)
525  {
526  //Update XCBC-MAC calculation
528  }
529  else
530 #endif
531  //Unknown PRF algorithm?
532  {
533  //Just for sanity
534  }
535 }
536 
537 
538 /**
539  * @brief Finalize PRF calculation
540  * @param[in] context Pointer to the IKE PRF context
541  * @param[out] output Pseudorandom output
542  * @param[in] outputLen Desired length of the pseudorandom output stream
543  * @return Error code
544  **/
545 
546 error_t ikePrfFinal(IkePrfContext *context, uint8_t *output, size_t outputLen)
547 {
548  error_t error;
549 
550  //Initialize status code
551  error = NO_ERROR;
552 
553 #if (CMAC_SUPPORT == ENABLED)
554  //CMAC PRF algorithm?
555  if(context->macAlgo == MAC_ALGO_CMAC)
556  {
557  //Finalize CMAC calculation
558  error = cmacFinal(&context->macContext.cmacContext, output, outputLen);
559  }
560  else
561 #endif
562 #if (HMAC_SUPPORT == ENABLED)
563  //HMAC PRF algorithm?
564  if(context->macAlgo == MAC_ALGO_HMAC)
565  {
566  //Finalize HMAC calculation
567  hmacFinal(&context->macContext.hmacContext, output);
568  }
569  else
570 #endif
571 #if (KMAC_SUPPORT == ENABLED)
572  //KMAC PRF algorithm?
573  if(context->macAlgo == MAC_ALGO_KMAC128 ||
574  context->macAlgo == MAC_ALGO_KMAC256)
575  {
576  //Finalize KMAC calculation
577  error = kmacFinal(&context->macContext.kmacContext, output, outputLen);
578  }
579  else
580 #endif
581 #if (XCBC_MAC_SUPPORT == ENABLED)
582  //XCBC-MAC PRF algorithm?
583  if(context->macAlgo == MAC_ALGO_XCBC_MAC)
584  {
585  //Finalize XCBC-MAC calculation
586  error = xcbcMacFinal(&context->macContext.xcbcMacContext, output,
587  outputLen);
588  }
589  else
590 #endif
591  //Unknown PRF algorithm?
592  {
593  //Report an error
594  error = ERROR_FAILURE;
595  }
596 
597  //Return status code
598  return error;
599 }
600 
601 #endif
@ MAC_ALGO_CMAC
const void * buffer
Definition: crypto.h:1165
error_t ikePrf(MacAlgo macAlgo, const HashAlgo *hashAlgo, const CipherAlgo *cipherAlgo, const uint8_t *key, size_t keyLen, const uint8_t *data, size_t dataLen, uint8_t *output)
Pseudorandom function (prf function)
Definition: ike_kdf.c:55
XCBC-MAC algorithm context.
Definition: xcbc_mac.h:54
error_t ikePrfPlus(MacAlgo macAlgo, const HashAlgo *hashAlgo, const CipherAlgo *cipherAlgo, const uint8_t *key, size_t keyLen, const uint8_t *data, size_t dataLen, uint8_t *output, size_t outputLen)
Function that outputs a pseudorandom stream (prf+ function)
Definition: ike_kdf.c:152
error_t ikePrfInit(IkePrfContext *context, MacAlgo macAlgo, const HashAlgo *hashAlgo, const CipherAlgo *cipherAlgo, const uint8_t *key, size_t keyLen)
Initialize PRF calculation.
Definition: ike_kdf.c:315
size_t outputLen
Definition: ike_kdf.h:52
IKE PRF algorithm context.
Definition: ike_kdf.h:49
error_t kmacInit(KmacContext *context, uint_t strength, const void *key, size_t keyLen, const char_t *custom, size_t customLen)
Initialize KMAC calculation.
Definition: kmac.c:125
uint8_t t
Definition: lldp_ext_med.h:212
MacAlgo macAlgo
Definition: ike_kdf.h:50
uint8_t data[]
Definition: ethernet.h:224
size_t digestSize
Definition: crypto.h:1249
size_t blockSize
Definition: crypto.h:1289
HmacContext hmacContext
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
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 ikePrfPlusEx(MacAlgo macAlgo, const HashAlgo *hashAlgo, const CipherAlgo *cipherAlgo, const uint8_t *key, size_t keyLen, const DataFrag *dataFrags, uint_t dataNumFrags, uint8_t *output, size_t outputLen)
Function that outputs a pseudorandom stream (prf+ function)
Definition: ike_kdf.c:191
#define MAX_HASH_DIGEST_SIZE
MacContext macContext
Definition: ike_kdf.h:51
error_t ikePrfEx(MacAlgo macAlgo, const HashAlgo *hashAlgo, const CipherAlgo *cipherAlgo, const uint8_t *key, size_t keyLen, const DataFrag *dataFrags, uint_t dataNumFrags, uint8_t *output)
Pseudorandom function (prf function)
Definition: ike_kdf.c:92
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
#define osMemcpy(dest, src, length)
Definition: os_port.h:147
error_t
Error codes.
Definition: error.h:43
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
Data fragment descriptor.
Definition: crypto.h:1164
@ ERROR_INVALID_LENGTH
Definition: error.h:111
General definitions for cryptographic algorithms.
@ MAC_ALGO_KMAC128
size_t length
Definition: crypto.h:1166
@ MAC_ALGO_KMAC256
uint8_t length
Definition: tcp.h:375
#define MIN(a, b)
Definition: os_port.h:63
IKEv2 key derivation functions.
uint32_t dataLen
Definition: sftp_common.h:229
CMAC algorithm context.
Definition: cmac.h:54
void ikePrfUpdate(IkePrfContext *context, const uint8_t *data, size_t dataLen)
Update PRF calculation.
Definition: ike_kdf.c:492
__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
error_t xcbcMacInit(XcbcMacContext *context, const CipherAlgo *cipher, const void *key, size_t keyLen)
Initialize XCBC-MAC calculation.
Definition: xcbc_mac.c:107
XcbcMacContext xcbcMacContext
void kmacUpdate(KmacContext *context, const void *data, size_t dataLen)
Update the KMAC context with a portion of the message being hashed.
Definition: kmac.c:188
KmacContext kmacContext
uint8_t n
__weak_func void hmacFinal(HmacContext *context, uint8_t *digest)
Finish the HMAC calculation.
Definition: hmac.c:218
error_t ikePrfFinal(IkePrfContext *context, uint8_t *output, size_t outputLen)
Finalize PRF calculation.
Definition: ike_kdf.c:546
#define cryptoFreeMem(p)
Definition: crypto.h:966
Common interface for encryption algorithms.
Definition: crypto.h:1285
@ MAC_ALGO_HMAC
error_t cmacInit(CmacContext *context, const CipherAlgo *cipher, const void *key, size_t keyLen)
Initialize CMAC calculation.
Definition: cmac.c:107
#define cryptoAllocMem(size)
Definition: crypto.h:961
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 kmacFinal(KmacContext *context, uint8_t *mac, size_t macLen)
Finish the KMAC calculation.
Definition: kmac.c:203
error_t xcbcMacFinal(XcbcMacContext *context, uint8_t *mac, size_t macLen)
Finish the XCBC-MAC calculation.
Definition: xcbc_mac.c:229
Common interface for hash algorithms.
Definition: crypto.h:1243
unsigned int uint_t
Definition: compiler_port.h:57
#define osMemset(p, value, length)
Definition: os_port.h:141
MacAlgo
MAC algorithms.
__weak_func error_t hmacInit(HmacContext *context, const HashAlgo *hash, const void *key, size_t keyLen)
Initialize HMAC calculation.
Definition: hmac.c:140
CmacContext cmacContext
error_t cmacFinal(CmacContext *context, uint8_t *mac, size_t macLen)
Finish the CMAC calculation.
Definition: cmac.c:237
@ NO_ERROR
Success.
Definition: error.h:44
uint8_t c
Definition: ndp.h:514
@ MAC_ALGO_XCBC_MAC
#define arraysize(a)
Definition: os_port.h:71