gmac.c
Go to the documentation of this file.
1 /**
2  * @file gmac.c
3  * @brief GMAC (Galois Message Authentication Code)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 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  * @section Description
28  *
29  * GMAC is a message authentication code (MAC) based on GCM. Refer to
30  * SP 800-38D for more details
31  *
32  * @author Oryx Embedded SARL (www.oryx-embedded.com)
33  * @version 2.4.4
34  **/
35 
36 //Switch to the appropriate trace level
37 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
38 
39 //Dependencies
40 #include "core/crypto.h"
41 #include "mac/gmac.h"
42 
43 //Check crypto library configuration
44 #if (GMAC_SUPPORT == ENABLED)
45 
46 //Reduction table
47 static const uint32_t r[GMAC_TABLE_N] =
48 {
49 #if (GMAC_TABLE_W == 4)
50  0x00000000, 0x1C200000, 0x38400000, 0x24600000, 0x70800000, 0x6CA00000, 0x48C00000, 0x54E00000,
51  0xE1000000, 0xFD200000, 0xD9400000, 0xC5600000, 0x91800000, 0x8DA00000, 0xA9C00000, 0xB5E00000
52 #else
53  0x00000000, 0x01C20000, 0x03840000, 0x02460000, 0x07080000, 0x06CA0000, 0x048C0000, 0x054E0000,
54  0x0E100000, 0x0FD20000, 0x0D940000, 0x0C560000, 0x09180000, 0x08DA0000, 0x0A9C0000, 0x0B5E0000,
55  0x1C200000, 0x1DE20000, 0x1FA40000, 0x1E660000, 0x1B280000, 0x1AEA0000, 0x18AC0000, 0x196E0000,
56  0x12300000, 0x13F20000, 0x11B40000, 0x10760000, 0x15380000, 0x14FA0000, 0x16BC0000, 0x177E0000,
57  0x38400000, 0x39820000, 0x3BC40000, 0x3A060000, 0x3F480000, 0x3E8A0000, 0x3CCC0000, 0x3D0E0000,
58  0x36500000, 0x37920000, 0x35D40000, 0x34160000, 0x31580000, 0x309A0000, 0x32DC0000, 0x331E0000,
59  0x24600000, 0x25A20000, 0x27E40000, 0x26260000, 0x23680000, 0x22AA0000, 0x20EC0000, 0x212E0000,
60  0x2A700000, 0x2BB20000, 0x29F40000, 0x28360000, 0x2D780000, 0x2CBA0000, 0x2EFC0000, 0x2F3E0000,
61  0x70800000, 0x71420000, 0x73040000, 0x72C60000, 0x77880000, 0x764A0000, 0x740C0000, 0x75CE0000,
62  0x7E900000, 0x7F520000, 0x7D140000, 0x7CD60000, 0x79980000, 0x785A0000, 0x7A1C0000, 0x7BDE0000,
63  0x6CA00000, 0x6D620000, 0x6F240000, 0x6EE60000, 0x6BA80000, 0x6A6A0000, 0x682C0000, 0x69EE0000,
64  0x62B00000, 0x63720000, 0x61340000, 0x60F60000, 0x65B80000, 0x647A0000, 0x663C0000, 0x67FE0000,
65  0x48C00000, 0x49020000, 0x4B440000, 0x4A860000, 0x4FC80000, 0x4E0A0000, 0x4C4C0000, 0x4D8E0000,
66  0x46D00000, 0x47120000, 0x45540000, 0x44960000, 0x41D80000, 0x401A0000, 0x425C0000, 0x439E0000,
67  0x54E00000, 0x55220000, 0x57640000, 0x56A60000, 0x53E80000, 0x522A0000, 0x506C0000, 0x51AE0000,
68  0x5AF00000, 0x5B320000, 0x59740000, 0x58B60000, 0x5DF80000, 0x5C3A0000, 0x5E7C0000, 0x5FBE0000,
69  0xE1000000, 0xE0C20000, 0xE2840000, 0xE3460000, 0xE6080000, 0xE7CA0000, 0xE58C0000, 0xE44E0000,
70  0xEF100000, 0xEED20000, 0xEC940000, 0xED560000, 0xE8180000, 0xE9DA0000, 0xEB9C0000, 0xEA5E0000,
71  0xFD200000, 0xFCE20000, 0xFEA40000, 0xFF660000, 0xFA280000, 0xFBEA0000, 0xF9AC0000, 0xF86E0000,
72  0xF3300000, 0xF2F20000, 0xF0B40000, 0xF1760000, 0xF4380000, 0xF5FA0000, 0xF7BC0000, 0xF67E0000,
73  0xD9400000, 0xD8820000, 0xDAC40000, 0xDB060000, 0xDE480000, 0xDF8A0000, 0xDDCC0000, 0xDC0E0000,
74  0xD7500000, 0xD6920000, 0xD4D40000, 0xD5160000, 0xD0580000, 0xD19A0000, 0xD3DC0000, 0xD21E0000,
75  0xC5600000, 0xC4A20000, 0xC6E40000, 0xC7260000, 0xC2680000, 0xC3AA0000, 0xC1EC0000, 0xC02E0000,
76  0xCB700000, 0xCAB20000, 0xC8F40000, 0xC9360000, 0xCC780000, 0xCDBA0000, 0xCFFC0000, 0xCE3E0000,
77  0x91800000, 0x90420000, 0x92040000, 0x93C60000, 0x96880000, 0x974A0000, 0x950C0000, 0x94CE0000,
78  0x9F900000, 0x9E520000, 0x9C140000, 0x9DD60000, 0x98980000, 0x995A0000, 0x9B1C0000, 0x9ADE0000,
79  0x8DA00000, 0x8C620000, 0x8E240000, 0x8FE60000, 0x8AA80000, 0x8B6A0000, 0x892C0000, 0x88EE0000,
80  0x83B00000, 0x82720000, 0x80340000, 0x81F60000, 0x84B80000, 0x857A0000, 0x873C0000, 0x86FE0000,
81  0xA9C00000, 0xA8020000, 0xAA440000, 0xAB860000, 0xAEC80000, 0xAF0A0000, 0xAD4C0000, 0xAC8E0000,
82  0xA7D00000, 0xA6120000, 0xA4540000, 0xA5960000, 0xA0D80000, 0xA11A0000, 0xA35C0000, 0xA29E0000,
83  0xB5E00000, 0xB4220000, 0xB6640000, 0xB7A60000, 0xB2E80000, 0xB32A0000, 0xB16C0000, 0xB0AE0000,
84  0xBBF00000, 0xBA320000, 0xB8740000, 0xB9B60000, 0xBCF80000, 0xBD3A0000, 0xBF7C0000, 0xBEBE0000
85 #endif
86 };
87 
88 
89 /**
90  * @brief Compute GMAC using the specified cipher algorithm
91  * @param[in] cipher Cipher algorithm used to compute GMAC
92  * @param[in] key Pointer to the secret key
93  * @param[in] keyLen Length of the secret key
94  * @param[in] iv Initialization vector
95  * @param[in] ivLen Length of the initialization vector
96  * @param[in] data Pointer to the input message
97  * @param[in] dataLen Length of the input data
98  * @param[out] mac Calculated MAC value
99  * @param[in] macLen Expected length of the MAC
100  * @return Error code
101  **/
102 
103 error_t gmacCompute(const CipherAlgo *cipher, const void *key, size_t keyLen,
104  const uint8_t *iv, size_t ivLen, const void *data, size_t dataLen,
105  uint8_t *mac, size_t macLen)
106 {
107  error_t error;
108 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
109  GmacContext *context;
110 #else
111  GmacContext context[1];
112 #endif
113 
114 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
115  //Allocate a memory buffer to hold the GMAC context
116  context = cryptoAllocMem(sizeof(GmacContext));
117  //Failed to allocate memory?
118  if(context == NULL)
119  return ERROR_OUT_OF_MEMORY;
120 #endif
121 
122  //Initialize the GMAC context
123  error = gmacInit(context, cipher, key, keyLen);
124 
125  //Check status code
126  if(!error)
127  {
128  //Reset GMAC context
129  error = gmacReset(context, iv, ivLen);
130  }
131 
132  //Check status code
133  if(!error)
134  {
135  //Digest the message
136  gmacUpdate(context, data, dataLen);
137  //Finalize the GMAC computation
138  error = gmacFinal(context, mac, macLen);
139  }
140 
141 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
142  //Free previously allocated memory
143  cryptoFreeMem(context);
144 #endif
145 
146  //Return status code
147  return error;
148 }
149 
150 
151 /**
152  * @brief Initialize GMAC calculation
153  * @param[in] context Pointer to the GMAC context to initialize
154  * @param[in] cipher Cipher algorithm used to compute GMAC
155  * @param[in] key Pointer to the secret key
156  * @param[in] keyLen Length of the secret key
157  * @return Error code
158  **/
159 
160 error_t gmacInit(GmacContext *context, const CipherAlgo *cipher,
161  const void *key, size_t keyLen)
162 {
163  error_t error;
164  uint_t i;
165  uint_t j;
166  uint32_t c;
167  uint32_t h[4];
168 
169  //Check parameters
170  if(context == NULL || cipher == NULL)
172 
173  //GMAC supports only symmetric block ciphers whose block size is 128 bits
174  if(cipher->type != CIPHER_ALGO_TYPE_BLOCK || cipher->blockSize != 16)
176 
177  //Cipher algorithm used to compute GMAC
178  context->cipher = cipher;
179 
180  //Initialize cipher context
181  error = cipher->init(&context->cipherContext, key, keyLen);
182  //Any error to report?
183  if(error)
184  return error;
185 
186  //Let H = 0
187  h[0] = 0;
188  h[1] = 0;
189  h[2] = 0;
190  h[3] = 0;
191 
192  //Generate the hash subkey H
193  context->cipher->encryptBlock(&context->cipherContext, (uint8_t *) h,
194  (uint8_t *) h);
195 
196  //Pre-compute M(0) = H * 0
197  j = GMAC_REVERSE_BITS(0);
198  context->m[j][0] = 0;
199  context->m[j][1] = 0;
200  context->m[j][2] = 0;
201  context->m[j][3] = 0;
202 
203  //Pre-compute M(1) = H * 1
204  j = GMAC_REVERSE_BITS(1);
205  context->m[j][0] = betoh32(h[3]);
206  context->m[j][1] = betoh32(h[2]);
207  context->m[j][2] = betoh32(h[1]);
208  context->m[j][3] = betoh32(h[0]);
209 
210  //Pre-compute all multiples of H (Shoup's method)
211  for(i = 2; i < GMAC_TABLE_N; i++)
212  {
213  //Odd value?
214  if((i & 1) != 0)
215  {
216  //Compute M(i) = M(i - 1) + H
217  j = GMAC_REVERSE_BITS(i - 1);
218  h[0] = context->m[j][0];
219  h[1] = context->m[j][1];
220  h[2] = context->m[j][2];
221  h[3] = context->m[j][3];
222 
223  //An addition in GF(2^128) is identical to a bitwise exclusive-OR
224  //operation
225  j = GMAC_REVERSE_BITS(1);
226  h[0] ^= context->m[j][0];
227  h[1] ^= context->m[j][1];
228  h[2] ^= context->m[j][2];
229  h[3] ^= context->m[j][3];
230  }
231  else
232  {
233  //Compute M(i) = M(i / 2) * x
234  j = GMAC_REVERSE_BITS(i / 2);
235  h[0] = context->m[j][0];
236  h[1] = context->m[j][1];
237  h[2] = context->m[j][2];
238  h[3] = context->m[j][3];
239 
240  //The multiplication of a polynomial by x in GF(2^128) corresponds
241  //to a shift of indices
242  c = h[0] & 0x01;
243  h[0] = (h[0] >> 1) | (h[1] << 31);
244  h[1] = (h[1] >> 1) | (h[2] << 31);
245  h[2] = (h[2] >> 1) | (h[3] << 31);
246  h[3] >>= 1;
247 
248  //If the highest term of the result is equal to one, then perform
249  //reduction
250  h[3] ^= r[GMAC_REVERSE_BITS(1)] & ~(c - 1);
251  }
252 
253  //Save M(i)
254  j = GMAC_REVERSE_BITS(i);
255  context->m[j][0] = h[0];
256  context->m[j][1] = h[1];
257  context->m[j][2] = h[2];
258  context->m[j][3] = h[3];
259  }
260 
261  //Clear input buffer
262  osMemset(context->buffer, 0, context->cipher->blockSize);
263  //Number of bytes in the buffer
264  context->bufferLength = 0;
265  //Total number of bytes
266  context->totalLength = 0;
267 
268  //Initialize MAC value
269  osMemset(context->mac, 0, context->cipher->blockSize);
270 
271  //Successful initialization
272  return NO_ERROR;
273 }
274 
275 
276 /**
277  * @brief Reset GMAC context
278  * @param[in] context Pointer to the GMAC context
279  * @param[in] iv Initialization vector
280  * @param[in] ivLen Length of the initialization vector
281  * @return Error code
282  **/
283 
284 error_t gmacReset(GmacContext *context, const uint8_t *iv, size_t ivLen)
285 {
286  size_t k;
287  size_t n;
288  uint8_t b[16];
289  uint8_t j[16];
290 
291  //The length of the IV shall meet SP 800-38D requirements
292  if(ivLen < 1)
294 
295  //Check whether the length of the IV is 96 bits
296  if(ivLen == 12)
297  {
298  //When the length of the IV is 96 bits, the padding string is
299  //appended to the IV to form the pre-counter block
300  osMemcpy(j, iv, 12);
301  STORE32BE(1, j + 12);
302  }
303  else
304  {
305  //Initialize GHASH calculation
306  osMemset(j, 0, 16);
307 
308  //Length of the IV
309  n = ivLen;
310 
311  //Process the initialization vector
312  while(n > 0)
313  {
314  //The IV is processed in a block-by-block fashion
315  k = MIN(n, 16);
316 
317  //Apply GHASH function
318  gmacXorBlock(j, j, iv, k);
319  gmacMul(context, j);
320 
321  //Next block
322  iv += k;
323  n -= k;
324  }
325 
326  //The string is appended with 64 additional 0 bits, followed by the
327  //64-bit representation of the length of the IV
328  osMemset(b, 0, 8);
329  STORE64BE(ivLen * 8, b + 8);
330 
331  //The GHASH function is applied to the resulting string to form the
332  //pre-counter block
333  gmacXorBlock(j, j, b, 16);
334  gmacMul(context, j);
335  }
336 
337  //Compute MSB(CIPH(J(0)))
338  context->cipher->encryptBlock(&context->cipherContext, j, b);
339  osMemcpy(context->mac, b, 16);
340 
341  //Initialize GHASH calculation
342  osMemset(context->s, 0, 16);
343 
344  //Clear input buffer
345  osMemset(context->buffer, 0, context->cipher->blockSize);
346  //Number of bytes in the buffer
347  context->bufferLength = 0;
348 
349  //Successful processing
350  return NO_ERROR;
351 }
352 
353 
354 /**
355  * @brief Update the GMAC context with a portion of the message being hashed
356  * @param[in] context Pointer to the GMAC context
357  * @param[in] data Pointer to the input data
358  * @param[in] dataLen Length of the buffer
359  **/
360 
361 void gmacUpdate(GmacContext *context, const void *data, size_t dataLen)
362 {
363  size_t n;
364 
365  //Process the incoming data
366  while(dataLen > 0)
367  {
368  //The message is partitioned into complete blocks
369  n = MIN(dataLen, 16 - context->bufferLength);
370 
371  //Copy the data to the buffer
372  osMemcpy(context->buffer + context->bufferLength, data, n);
373  //Update the length of the buffer
374  context->bufferLength += n;
375  //Update the total number of bytes
376  context->totalLength += n;
377 
378  //Advance the data pointer
379  data = (uint8_t *) data + n;
380  //Remaining bytes to process
381  dataLen -= n;
382 
383  //Process message block by block
384  if(context->bufferLength == 16)
385  {
386  //Apply GHASH function
387  gmacXorBlock(context->s, context->s, context->buffer, 16);
388  gmacMul(context, context->s);
389 
390  //Empty the buffer
391  context->bufferLength = 0;
392  }
393  }
394 }
395 
396 
397 /**
398  * @brief Finish the GMAC calculation
399  * @param[in] context Pointer to the GMAC context
400  * @param[out] mac Calculated MAC value (optional parameter)
401  * @param[in] macLen Expected length of the MAC
402  **/
403 
404 error_t gmacFinal(GmacContext *context, uint8_t *mac, size_t macLen)
405 {
406  //Make sure the GMAC context is valid
407  if(context == NULL)
409 
410  //Check the length of the MAC
411  if(macLen < 4 || macLen > 16)
413 
414  //Process the last block of the message
415  if(context->bufferLength > 0)
416  {
417  //Apply GHASH function
418  gmacXorBlock(context->s, context->s, context->buffer, context->bufferLength);
419  gmacMul(context, context->s);
420  }
421 
422  //Append the 64-bit representation of the length of the message followed
423  //by 64 additional 0 bits
424  STORE64BE(context->totalLength * 8, context->buffer);
425  osMemset(context->buffer + 8, 0, 8);
426 
427  //The GHASH function is applied to the result to produce a single output block S
428  gmacXorBlock(context->s, context->s, context->buffer, 16);
429  gmacMul(context, context->s);
430 
431  //Let T = GCTR(J(0), S)
432  gmacXorBlock(context->mac, context->mac, context->s, 16);
433 
434  //Copy the resulting MAC value
435  if(mac != NULL)
436  {
437  //Output MSB(T)
438  osMemcpy(mac, context->mac, macLen);
439  }
440 
441  //Successful processing
442  return NO_ERROR;
443 }
444 
445 
446 /**
447  * @brief Release GMAC context
448  * @param[in] context Pointer to the GMAC context
449  **/
450 
451 void gmacDeinit(GmacContext *context)
452 {
453  //Make sure the GMAC context is valid
454  if(context != NULL)
455  {
456  //Release cipher context
457  context->cipher->deinit(&context->cipherContext);
458 
459  //Clear GMAC context
460  osMemset(context, 0, sizeof(GmacContext));
461  }
462 }
463 
464 
465 /**
466  * @brief Multiplication operation in GF(2^128)
467  * @param[in] context Pointer to the GMAC context
468  * @param[in, out] x 16-byte block to be multiplied by H
469  **/
470 
471 void gmacMul(GmacContext *context, uint8_t *x)
472 {
473  int_t i;
474  uint8_t b;
475  uint8_t c;
476  uint32_t z[4];
477 
478  //Let Z = 0
479  z[0] = 0;
480  z[1] = 0;
481  z[2] = 0;
482  z[3] = 0;
483 
484  //Fast table-driven implementation (Shoup's method)
485  for(i = 15; i >= 0; i--)
486  {
487 #if (GMAC_TABLE_W == 4)
488  //Get the lower nibble
489  b = x[i] & 0x0F;
490 
491  //Multiply 4 bits at a time
492  c = z[0] & 0x0F;
493  z[0] = (z[0] >> 4) | (z[1] << 28);
494  z[1] = (z[1] >> 4) | (z[2] << 28);
495  z[2] = (z[2] >> 4) | (z[3] << 28);
496  z[3] >>= 4;
497 
498  z[0] ^= context->m[b][0];
499  z[1] ^= context->m[b][1];
500  z[2] ^= context->m[b][2];
501  z[3] ^= context->m[b][3];
502 
503  //Perform reduction
504  z[3] ^= r[c];
505 
506  //Get the upper nibble
507  b = (x[i] >> 4) & 0x0F;
508 
509  //Multiply 4 bits at a time
510  c = z[0] & 0x0F;
511  z[0] = (z[0] >> 4) | (z[1] << 28);
512  z[1] = (z[1] >> 4) | (z[2] << 28);
513  z[2] = (z[2] >> 4) | (z[3] << 28);
514  z[3] >>= 4;
515 
516  z[0] ^= context->m[b][0];
517  z[1] ^= context->m[b][1];
518  z[2] ^= context->m[b][2];
519  z[3] ^= context->m[b][3];
520 
521  //Perform reduction
522  z[3] ^= r[c];
523 #else
524  //Get current byte
525  b = x[i];
526 
527  //Multiply 8 bits at a time
528  c = z[0] & 0xFF;
529  z[0] = (z[0] >> 8) | (z[1] << 24);
530  z[1] = (z[1] >> 8) | (z[2] << 24);
531  z[2] = (z[2] >> 8) | (z[3] << 24);
532  z[3] >>= 8;
533 
534  z[0] ^= context->m[b][0];
535  z[1] ^= context->m[b][1];
536  z[2] ^= context->m[b][2];
537  z[3] ^= context->m[b][3];
538 
539  //Perform reduction
540  z[3] ^= r[c];
541 #endif
542  }
543 
544  //Save the result
545  STORE32BE(z[3], x);
546  STORE32BE(z[2], x + 4);
547  STORE32BE(z[1], x + 8);
548  STORE32BE(z[0], x + 12);
549 }
550 
551 
552 /**
553  * @brief XOR operation
554  * @param[out] x Block resulting from the XOR operation
555  * @param[in] a First block
556  * @param[in] b Second block
557  * @param[in] n Size of the block
558  **/
559 
560 void gmacXorBlock(uint8_t *x, const uint8_t *a, const uint8_t *b, size_t n)
561 {
562  size_t i;
563 
564  //Perform XOR operation
565  for(i = 0; i < n; i++)
566  {
567  x[i] = a[i] ^ b[i];
568  }
569 }
570 
571 
572 /**
573  * @brief Increment counter block
574  * @param[in,out] ctr Pointer to the counter block
575  **/
576 
577 void gmacIncCounter(uint8_t *ctr)
578 {
579  uint16_t temp;
580 
581  //The function increments the right-most 32 bits of the block. The remaining
582  //left-most 96 bits remain unchanged
583  temp = ctr[15] + 1;
584  ctr[15] = temp & 0xFF;
585  temp = (temp >> 8) + ctr[14];
586  ctr[14] = temp & 0xFF;
587  temp = (temp >> 8) + ctr[13];
588  ctr[13] = temp & 0xFF;
589  temp = (temp >> 8) + ctr[12];
590  ctr[12] = temp & 0xFF;
591 }
592 
593 #endif
#define betoh32(value)
Definition: cpu_endian.h:454
uint8_t b
Definition: nbns_common.h:104
uint8_t a
Definition: ndp.h:411
signed int int_t
Definition: compiler_port.h:49
uint8_t x
Definition: lldp_ext_med.h:211
@ CIPHER_ALGO_TYPE_BLOCK
Definition: crypto.h:953
const CipherAlgo * cipher
Definition: gmac.h:71
uint8_t data[]
Definition: ethernet.h:222
size_t blockSize
Definition: crypto.h:1072
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
error_t gmacInit(GmacContext *context, const CipherAlgo *cipher, const void *key, size_t keyLen)
Initialize GMAC calculation.
Definition: gmac.c:160
CipherAlgoEncryptBlock encryptBlock
Definition: crypto.h:1076
uint8_t r
Definition: ndp.h:346
CipherAlgoInit init
Definition: crypto.h:1073
#define GMAC_TABLE_N
Definition: gmac.h:47
error_t gmacCompute(const CipherAlgo *cipher, const void *key, size_t keyLen, const uint8_t *iv, size_t ivLen, const void *data, size_t dataLen, uint8_t *mac, size_t macLen)
Compute GMAC using the specified cipher algorithm.
Definition: gmac.c:103
uint8_t h
Definition: ndp.h:302
void gmacMul(GmacContext *context, uint8_t *x)
Multiplication operation in GF(2^128)
Definition: gmac.c:471
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
#define osMemcpy(dest, src, length)
Definition: os_port.h:141
error_t
Error codes.
Definition: error.h:43
CipherAlgoType type
Definition: crypto.h:1071
General definitions for cryptographic algorithms.
uint8_t iv[]
Definition: ike.h:1502
#define MIN(a, b)
Definition: os_port.h:63
uint8_t s[16]
Definition: gmac.h:74
uint32_t dataLen
Definition: sftp_common.h:229
uint8_t z
Definition: dns_common.h:191
void gmacIncCounter(uint8_t *ctr)
Increment counter block.
Definition: gmac.c:577
#define STORE64BE(a, p)
Definition: cpu_endian.h:322
uint8_t n
#define cryptoFreeMem(p)
Definition: crypto.h:791
GMAC (Galois Message Authentication Code)
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
void gmacDeinit(GmacContext *context)
Release GMAC context.
Definition: gmac.c:451
CipherAlgoDeinit deinit
Definition: crypto.h:1078
Common interface for encryption algorithms.
Definition: crypto.h:1068
GMAC algorithm context.
Definition: gmac.h:70
#define cryptoAllocMem(size)
Definition: crypto.h:786
uint8_t buffer[16]
Definition: gmac.h:75
error_t gmacReset(GmacContext *context, const uint8_t *iv, size_t ivLen)
Reset GMAC context.
Definition: gmac.c:284
uint64_t totalLength
Definition: gmac.h:77
CipherContext cipherContext
Definition: gmac.h:72
void gmacXorBlock(uint8_t *x, const uint8_t *a, const uint8_t *b, size_t n)
XOR operation.
Definition: gmac.c:560
uint32_t m[GMAC_TABLE_N][4]
Definition: gmac.h:73
uint8_t mac[16]
Definition: gmac.h:78
unsigned int uint_t
Definition: compiler_port.h:50
#define osMemset(p, value, length)
Definition: os_port.h:135
error_t gmacFinal(GmacContext *context, uint8_t *mac, size_t macLen)
Finish the GMAC calculation.
Definition: gmac.c:404
size_t bufferLength
Definition: gmac.h:76
#define STORE32BE(a, p)
Definition: cpu_endian.h:286
@ NO_ERROR
Success.
Definition: error.h:44
uint8_t c
Definition: ndp.h:514
#define GMAC_REVERSE_BITS(n)
Definition: gmac.h:48