iPXE
gcm.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 /** @file
27  *
28  * Galois/Counter Mode (GCM)
29  *
30  * The GCM algorithm is specified in
31  *
32  * https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
33  * https://csrc.nist.rip/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-spec.pdf
34  *
35  */
36 
37 #include <stdint.h>
38 #include <string.h>
39 #include <byteswap.h>
40 #include <ipxe/crypto.h>
41 #include <ipxe/gcm.h>
42 
43 /**
44  * Perform encryption
45  *
46  * This value is chosen to allow for ANDing with a fragment length.
47  */
48 #define GCM_FL_ENCRYPT 0x00ff
49 
50 /**
51  * Calculate hash over an initialisation vector value
52  *
53  * The hash calculation for a non 96-bit initialisation vector is
54  * identical to the calculation used for additional data, except that
55  * the non-additional data length counter is used.
56  */
57 #define GCM_FL_IV 0x0100
58 
59 /**
60  * GCM field polynomial
61  *
62  * GCM treats 128-bit blocks as polynomials in GF(2^128) with the
63  * field polynomial f(x) = 1 + x + x^2 + x^7 + x^128.
64  *
65  * In a somewhat bloody-minded interpretation of "big-endian", the
66  * constant term (with degree zero) is arbitrarily placed in the
67  * leftmost bit of the big-endian binary representation (i.e. the most
68  * significant bit of byte 0), thereby failing to correspond to the
69  * bit ordering in any CPU architecture in existence. This
70  * necessitates some wholly gratuitous byte reversals when
71  * constructing the multiplication tables, since all CPUs will treat
72  * bit 0 as being the least significant bit within a byte.
73  *
74  * The field polynomial maps to the 128-bit constant
75  * 0xe1000000000000000000000000000000 (with the x^128 term outside the
76  * 128-bit range), and can therefore be treated as a single-byte
77  * value.
78  */
79 #define GCM_POLY 0xe1
80 
81 /**
82  * Hash key for which multiplication tables are cached
83  *
84  * GCM operates much more efficiently with a cached multiplication
85  * table, which costs 4kB per hash key. Since this exceeds the
86  * available stack space, we place a single 4kB cache in .bss and
87  * recalculate the cached values as required. In the common case of a
88  * single HTTPS connection being used to download a (relatively) large
89  * file, the same key will be used repeatedly for almost all GCM
90  * operations, and so the overhead of recalculation is negligible.
91  */
92 static const union gcm_block *gcm_cached_key;
93 
94 /**
95  * Cached multiplication table (M0) for Shoup's method
96  *
97  * Each entry within this table represents the result of multiplying
98  * the cached hash key by an arbitrary 8-bit polynomial.
99  */
100 static union gcm_block gcm_cached_mult[256];
101 
102 /**
103  * Cached reduction table (R) for Shoup's method
104  *
105  * Each entry within this table represents the result of multiplying
106  * the fixed polynomial x^128 by an arbitrary 8-bit polynomial. Only
107  * the leftmost 16 bits are stored, since all other bits within the
108  * result will always be zero.
109  */
111 
112 /** Offset of a field within GCM context */
113 #define gcm_offset( field ) offsetof ( struct gcm_context, field )
114 
115 /**
116  * Reverse bits in a byte
117  *
118  * @v byte Byte
119  * @ret etyb Bit-reversed byte
120  */
121 static inline __attribute__ (( always_inline )) uint8_t
122 gcm_reverse ( const uint8_t byte ) {
123  uint8_t etyb = etyb;
124  uint8_t mask;
125 
126  for ( mask = 1 ; mask ; mask <<= 1 ) {
127  etyb <<= 1;
128  if ( byte & mask )
129  etyb |= 1;
130  }
131  return etyb;
132 }
133 
134 /**
135  * Update GCM counter
136  *
137  * @v ctr Counter
138  * @v delta Amount to add to counter
139  */
140 static inline __attribute__ (( always_inline )) void
141 gcm_count ( union gcm_block *ctr, uint32_t delta ) {
142  uint32_t *value = &ctr->ctr.value;
143 
144  /* Update counter modulo 2^32 */
145  *value = cpu_to_be32 ( be32_to_cpu ( *value ) + delta );
146 }
147 
148 /**
149  * XOR partial data block
150  *
151  * @v src1 Source buffer 1
152  * @v src2 Source buffer 2
153  * @v dst Destination buffer
154  * @v len Length
155  */
156 static inline void gcm_xor ( const void *src1, const void *src2, void *dst,
157  size_t len ) {
158  uint8_t *dst_bytes = dst;
159  const uint8_t *src1_bytes = src1;
160  const uint8_t *src2_bytes = src2;
161 
162  /* XOR one byte at a time */
163  while ( len-- )
164  *(dst_bytes++) = ( *(src1_bytes++) ^ *(src2_bytes++) );
165 }
166 
167 /**
168  * XOR whole data block in situ
169  *
170  * @v src Source block
171  * @v dst Destination block
172  */
173 static inline void gcm_xor_block ( const union gcm_block *src,
174  union gcm_block *dst ) {
175 
176  /* XOR whole dwords */
177  dst->dword[0] ^= src->dword[0];
178  dst->dword[1] ^= src->dword[1];
179  dst->dword[2] ^= src->dword[2];
180  dst->dword[3] ^= src->dword[3];
181 }
182 
183 /**
184  * Multiply polynomial by (x)
185  *
186  * @v mult Multiplicand
187  * @v res Result
188  */
189 static void gcm_multiply_x ( const union gcm_block *mult,
190  union gcm_block *res ) {
191  unsigned int i;
192  uint8_t byte;
193  uint8_t carry;
194 
195  /* Multiply by (x) by shifting all bits rightward */
196  for ( i = 0, carry = 0 ; i < sizeof ( res->byte ) ; i++ ) {
197  byte = mult->byte[i];
198  res->byte[i] = ( ( carry << 7 ) | ( byte >> 1 ) );
199  carry = ( byte & 0x01 );
200  }
201 
202  /* If result overflows, reduce modulo the field polynomial */
203  if ( carry )
204  res->byte[0] ^= GCM_POLY;
205 }
206 
207 /**
208  * Construct cached tables
209  *
210  * @v key Hash key
211  * @v context Context
212  */
213 static void gcm_cache ( const union gcm_block *key ) {
214  union gcm_block *mult;
215  uint16_t reduce;
216  unsigned int this;
217  unsigned int other;
218  unsigned int i;
219 
220  /* Calculate M0[1..255] and R[1..255]
221  *
222  * The R[] values are independent of the key, but the overhead
223  * of recalculating them here is negligible and saves on
224  * overall code size since the calculations are related.
225  */
226  for ( i = 1 ; i < 256 ; i++ ) {
227 
228  /* Reverse bit order to compensate for poor life choices */
229  this = gcm_reverse ( i );
230 
231  /* Construct entries */
232  mult = &gcm_cached_mult[this];
233  if ( this & 0x80 ) {
234 
235  /* Odd number: entry[i] = entry[i - 1] + poly */
236  other = ( this & 0x7f ); /* bit-reversed (i - 1) */
237  gcm_xor ( key, &gcm_cached_mult[other], mult,
238  sizeof ( *mult ) );
239  reduce = gcm_cached_reduce[other];
240  reduce ^= be16_to_cpu ( GCM_POLY << 8 );
241  gcm_cached_reduce[this] = reduce;
242 
243  } else {
244 
245  /* Even number: entry[i] = entry[i/2] * (x) */
246  other = ( this << 1 ); /* bit-reversed (i / 2) */
247  gcm_multiply_x ( &gcm_cached_mult[other], mult );
248  reduce = be16_to_cpu ( gcm_cached_reduce[other] );
249  reduce >>= 1;
250  gcm_cached_reduce[this] = cpu_to_be16 ( reduce );
251  }
252  }
253 
254  /* Record cached key */
256 }
257 
258 /**
259  * Multiply polynomial by (x^8) in situ
260  *
261  * @v poly Multiplicand and result
262  */
263 static void gcm_multiply_x_8 ( union gcm_block *poly ) {
264  uint8_t *byte;
265  uint8_t msb;
266 
267  /* Reduction table must already have been calculated */
268  assert ( gcm_cached_key != NULL );
269 
270  /* Record most significant byte */
271  byte = &poly->byte[ sizeof ( poly->byte ) - 1 ];
272  msb = *byte;
273 
274  /* Multiply least significant bytes by shifting */
275  for ( ; byte > &poly->byte[0] ; byte-- )
276  *byte = *( byte - 1 );
277  *byte = 0;
278 
279  /* Multiply most significant byte via reduction table */
280  poly->word[0] ^= gcm_cached_reduce[msb];
281 }
282 
283 /**
284  * Multiply polynomial by hash key in situ
285  *
286  * @v key Hash key
287  * @v poly Multiplicand and result
288  */
289 static void gcm_multiply_key ( const union gcm_block *key,
290  union gcm_block *poly ) {
291  union gcm_block res;
292  uint8_t *byte;
293 
294  /* Construct tables, if necessary */
295  if ( gcm_cached_key != key )
296  gcm_cache ( key );
297 
298  /* Multiply using Shoup's algorithm */
299  byte = &poly->byte[ sizeof ( poly->byte ) - 1 ];
300  memcpy ( &res, &gcm_cached_mult[ *byte ], sizeof ( res ) );
301  for ( byte-- ; byte >= &poly->byte[0] ; byte-- ) {
302  gcm_multiply_x_8 ( &res );
303  gcm_xor_block ( &gcm_cached_mult[ *byte ], &res );
304  }
305 
306  /* Overwrite result */
307  memcpy ( poly, &res, sizeof ( *poly ) );
308 }
309 
310 /**
311  * Encrypt/decrypt/authenticate data
312  *
313  * @v context Context
314  * @v src Input data
315  * @v dst Output data, or NULL to process additional data
316  * @v len Length of data
317  * @v flags Operation flags
318  */
319 static void gcm_process ( struct gcm_context *context, const void *src,
320  void *dst, size_t len, unsigned int flags ) {
321  union gcm_block tmp;
322  uint64_t *total;
323  size_t frag_len;
324  unsigned int block;
325 
326  /* Calculate block number (for debugging) */
327  block = ( ( ( context->len.len.add + 8 * sizeof ( tmp ) - 1 ) /
328  ( 8 * sizeof ( tmp ) ) ) +
329  ( ( context->len.len.data + 8 * sizeof ( tmp ) - 1 ) /
330  ( 8 * sizeof ( tmp ) ) ) + 1 );
331 
332  /* Update total length (in bits) */
333  total = ( ( dst || ( flags & GCM_FL_IV ) ) ?
334  &context->len.len.data : &context->len.len.add );
335  *total += ( len * 8 );
336 
337  /* Process data */
338  for ( ; len ; src += frag_len, len -= frag_len, block++ ) {
339 
340  /* Calculate fragment length */
341  frag_len = len;
342  if ( frag_len > sizeof ( tmp ) )
343  frag_len = sizeof ( tmp );
344 
345  /* Update hash with input data */
346  gcm_xor ( src, &context->hash, &context->hash, frag_len );
347 
348  /* Encrypt/decrypt block, if applicable */
349  if ( dst ) {
350 
351  /* Increment counter */
352  gcm_count ( &context->ctr, 1 );
353 
354  /* Encrypt counter */
355  DBGC2 ( context, "GCM %p Y[%d]:\n", context, block );
356  DBGC2_HDA ( context, 0, &context->ctr,
357  sizeof ( context->ctr ) );
358  cipher_encrypt ( context->raw_cipher, &context->raw_ctx,
359  &context->ctr, &tmp, sizeof ( tmp ) );
360  DBGC2 ( context, "GCM %p E(K,Y[%d]):\n",
361  context, block );
362  DBGC2_HDA ( context, 0, &tmp, sizeof ( tmp ) );
363 
364  /* Encrypt/decrypt data */
365  gcm_xor ( src, &tmp, dst, frag_len );
366  dst += frag_len;
367 
368  /* Update hash with encrypted data, if applicable */
369  gcm_xor ( &tmp, &context->hash, &context->hash,
370  ( frag_len & flags ) );
371  }
372 
373  /* Update hash */
374  gcm_multiply_key ( &context->key, &context->hash );
375  DBGC2 ( context, "GCM %p X[%d]:\n", context, block );
376  DBGC2_HDA ( context, 0, &context->hash,
377  sizeof ( context->hash ) );
378  }
379 }
380 
381 /**
382  * Construct hash
383  *
384  * @v context Context
385  * @v hash Hash to fill in
386  */
387 static void gcm_hash ( struct gcm_context *context, union gcm_block *hash ) {
388 
389  /* Construct big-endian lengths block */
390  hash->len.add = cpu_to_be64 ( context->len.len.add );
391  hash->len.data = cpu_to_be64 ( context->len.len.data );
392  DBGC2 ( context, "GCM %p len(A)||len(C):\n", context );
393  DBGC2_HDA ( context, 0, hash, sizeof ( *hash ) );
394 
395  /* Update hash */
396  gcm_xor_block ( &context->hash, hash );
397  gcm_multiply_key ( &context->key, hash );
398  DBGC2 ( context, "GCM %p GHASH(H,A,C):\n", context );
399  DBGC2_HDA ( context, 0, hash, sizeof ( *hash ) );
400 }
401 
402 /**
403  * Construct tag
404  *
405  * @v context Context
406  * @v tag Tag
407  */
408 void gcm_tag ( struct gcm_context *context, union gcm_block *tag ) {
409  union gcm_block tmp;
411 
412  /* Construct hash */
413  gcm_hash ( context, tag );
414 
415  /* Construct encrypted initial counter value */
416  memcpy ( &tmp, &context->ctr, sizeof ( tmp ) );
417  offset = ( ( -context->len.len.data ) / ( 8 * sizeof ( tmp ) ) );
418  gcm_count ( &tmp, offset );
419  cipher_encrypt ( context->raw_cipher, &context->raw_ctx, &tmp,
420  &tmp, sizeof ( tmp ) );
421  DBGC2 ( context, "GCM %p E(K,Y[0]):\n", context );
422  DBGC2_HDA ( context, 0, &tmp, sizeof ( tmp ) );
423 
424  /* Construct tag */
425  gcm_xor_block ( &tmp, tag );
426  DBGC2 ( context, "GCM %p T:\n", context );
427  DBGC2_HDA ( context, 0, tag, sizeof ( *tag ) );
428 }
429 
430 /**
431  * Set key
432  *
433  * @v context Context
434  * @v key Key
435  * @v keylen Key length
436  * @v raw_cipher Underlying cipher
437  * @ret rc Return status code
438  */
439 int gcm_setkey ( struct gcm_context *context, const void *key, size_t keylen,
440  struct cipher_algorithm *raw_cipher ) {
441  int rc;
442 
443  /* Initialise GCM context */
444  memset ( context, 0, sizeof ( *context ) );
445  context->raw_cipher = raw_cipher;
446 
447  /* Set underlying block cipher key */
448  if ( ( rc = cipher_setkey ( raw_cipher, context->raw_ctx, key,
449  keylen ) ) != 0 )
450  return rc;
451 
452  /* Construct GCM hash key */
453  cipher_encrypt ( raw_cipher, context->raw_ctx, &context->ctr,
454  &context->key, sizeof ( context->key ) );
455  DBGC2 ( context, "GCM %p H:\n", context );
456  DBGC2_HDA ( context, 0, &context->key, sizeof ( context->key ) );
457 
458  /* Reset counter */
459  context->ctr.ctr.value = cpu_to_be32 ( 1 );
460 
461  /* Construct cached tables */
462  gcm_cache ( &context->key );
463 
464  return 0;
465 }
466 
467 /**
468  * Set initialisation vector
469  *
470  * @v ctx Context
471  * @v iv Initialisation vector
472  * @v ivlen Initialisation vector length
473  */
474 void gcm_setiv ( struct gcm_context *context, const void *iv, size_t ivlen ) {
475 
476  /* Reset non-key state */
477  memset ( context, 0, gcm_offset ( key ) );
478  build_assert ( gcm_offset ( key ) > gcm_offset ( hash ) );
479  build_assert ( gcm_offset ( key ) > gcm_offset ( len ) );
480  build_assert ( gcm_offset ( key ) > gcm_offset ( ctr ) );
481  build_assert ( gcm_offset ( key ) < gcm_offset ( raw_cipher ) );
482  build_assert ( gcm_offset ( key ) < gcm_offset ( raw_ctx ) );
483 
484  /* Reset counter */
485  context->ctr.ctr.value = cpu_to_be32 ( 1 );
486 
487  /* Process initialisation vector */
488  if ( ivlen == sizeof ( context->ctr.ctr.iv ) ) {
489 
490  /* Initialisation vector is exactly 96 bits, use it as-is */
491  memcpy ( context->ctr.ctr.iv, iv, ivlen );
492 
493  } else {
494 
495  /* Calculate hash over initialisation vector */
496  gcm_process ( context, iv, NULL, ivlen, GCM_FL_IV );
497  gcm_hash ( context, &context->ctr );
498  assert ( context->len.len.add == 0 );
499 
500  /* Reset non-key, non-counter state */
501  memset ( context, 0, gcm_offset ( ctr ) );
502  build_assert ( gcm_offset ( ctr ) > gcm_offset ( hash ) );
503  build_assert ( gcm_offset ( ctr ) > gcm_offset ( len ) );
504  build_assert ( gcm_offset ( ctr ) < gcm_offset ( key ) );
505  build_assert ( gcm_offset ( ctr ) < gcm_offset ( raw_cipher ) );
506  build_assert ( gcm_offset ( ctr ) < gcm_offset ( raw_ctx ) );
507  }
508 
509  DBGC2 ( context, "GCM %p Y[0]:\n", context );
510  DBGC2_HDA ( context, 0, &context->ctr, sizeof ( context->ctr ) );
511 }
512 
513 /**
514  * Encrypt data
515  *
516  * @v context Context
517  * @v src Data to encrypt
518  * @v dst Buffer for encrypted data, or NULL for additional data
519  * @v len Length of data
520  */
521 void gcm_encrypt ( struct gcm_context *context, const void *src, void *dst,
522  size_t len ) {
523 
524  /* Process data */
525  gcm_process ( context, src, dst, len, GCM_FL_ENCRYPT );
526 }
527 
528 /**
529  * Decrypt data
530  *
531  * @v context Context
532  * @v src Data to decrypt
533  * @v dst Buffer for decrypted data, or NULL for additional data
534  * @v len Length of data
535  */
536 void gcm_decrypt ( struct gcm_context *context, const void *src, void *dst,
537  size_t len ) {
538 
539  /* Process data */
540  gcm_process ( context, src, dst, len, 0 );
541 }
#define cpu_to_be16(value)
Definition: byteswap.h:109
A GCM block.
Definition: gcm.h:32
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define GCM_FL_ENCRYPT
Perform encryption.
Definition: gcm.c:48
unsigned short uint16_t
Definition: stdint.h:11
union gcm_block len
Accumulated lengths.
Definition: gcm.h:50
uint8_t raw_ctx[0]
Underlying block cipher context.
Definition: gcm.h:58
struct gcm_lengths len
Lengths.
Definition: gcm.h:42
uint8_t iv[12]
Initialisation vector.
Definition: gcm.h:18
static void gcm_hash(struct gcm_context *context, union gcm_block *hash)
Construct hash.
Definition: gcm.c:387
static void gcm_cache(const union gcm_block *key)
Construct cached tables.
Definition: gcm.c:213
static void const void void * dst
Definition: crypto.h:244
uint8_t byte[16]
Raw bytes.
Definition: gcm.h:34
static void const void * src
Definition: crypto.h:244
#define GCM_FL_IV
Calculate hash over an initialisation vector value.
Definition: gcm.c:57
void gcm_tag(struct gcm_context *context, union gcm_block *tag)
Construct tag.
Definition: gcm.c:408
void gcm_decrypt(struct gcm_context *context, const void *src, void *dst, size_t len)
Decrypt data.
Definition: gcm.c:536
unsigned long long uint64_t
Definition: stdint.h:13
static union gcm_block gcm_cached_mult[256]
Cached multiplication table (M0) for Shoup's method.
Definition: gcm.c:100
static void gcm_xor_block(const union gcm_block *src, union gcm_block *dst)
XOR whole data block in situ.
Definition: gcm.c:173
Cryptographic API.
union gcm_block hash
Accumulated hash (X)
Definition: gcm.h:48
uint32_t value
Counter value.
Definition: gcm.h:20
struct cipher_algorithm * raw_cipher
Underlying block cipher.
Definition: gcm.h:56
static void const void size_t ivlen
Definition: crypto.h:239
unsigned long tmp
Definition: linux_pci.h:53
#define cipher_encrypt(cipher, ctx, src, dst, len)
Definition: crypto.h:248
static void gcm_multiply_key(const union gcm_block *key, union gcm_block *poly)
Multiply polynomial by hash key in situ.
Definition: gcm.c:289
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void const void size_t keylen
Definition: crypto.h:233
int gcm_setkey(struct gcm_context *context, const void *key, size_t keylen, struct cipher_algorithm *raw_cipher)
Set key.
Definition: gcm.c:439
#define be32_to_cpu(value)
Definition: byteswap.h:116
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static __attribute__((always_inline))
Reverse bits in a byte.
Definition: gcm.c:121
void gcm_setiv(struct gcm_context *context, const void *iv, size_t ivlen)
Set initialisation vector.
Definition: gcm.c:474
#define build_assert(condition)
Assert a condition at build time (after dead code elimination)
Definition: assert.h:76
static void gcm_process(struct gcm_context *context, const void *src, void *dst, size_t len, unsigned int flags)
Encrypt/decrypt/authenticate data.
Definition: gcm.c:319
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
#define be16_to_cpu(value)
Definition: byteswap.h:115
union gcm_block key
Hash key (H)
Definition: gcm.h:54
void gcm_encrypt(struct gcm_context *context, const void *src, void *dst, size_t len)
Encrypt data.
Definition: gcm.c:521
uint64_t data
Data length.
Definition: gcm.h:28
struct gcm_counter ctr
Counter.
Definition: gcm.h:40
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define DBGC2_HDA(...)
Definition: compiler.h:523
pseudo_bit_t hash[0x00010]
Hash algorithm.
Definition: arbel.h:13
static void gcm_xor(const void *src1, const void *src2, void *dst, size_t len)
XOR partial data block.
Definition: gcm.c:156
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
GCM context.
Definition: gcm.h:46
uint16_t word[8]
Raw words.
Definition: gcm.h:36
#define gcm_offset(field)
Offset of a field within GCM context.
Definition: gcm.c:113
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
unsigned char byte
Definition: smc9000.h:38
#define cpu_to_be32(value)
Definition: byteswap.h:110
union gcm_block ctr
Counter (Y)
Definition: gcm.h:52
uint32_t len
Length.
Definition: ena.h:14
static void const void * iv
Definition: crypto.h:238
#define DBGC2(...)
Definition: compiler.h:522
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
static void gcm_multiply_x_8(union gcm_block *poly)
Multiply polynomial by (x^8) in situ.
Definition: gcm.c:263
Galois/Counter Mode (GCM)
#define cpu_to_be64(value)
Definition: byteswap.h:111
A cipher algorithm.
Definition: crypto.h:49
static const union gcm_block * gcm_cached_key
Hash key for which multiplication tables are cached.
Definition: gcm.c:92
struct gcm_counter ctr
Counter.
Definition: gcm.h:18
uint64_t add
Additional data length.
Definition: gcm.h:26
uint64_t tag
Identity tag.
Definition: edd.h:30
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define GCM_POLY
GCM field polynomial.
Definition: gcm.c:79
String functions.
static void gcm_multiply_x(const union gcm_block *mult, union gcm_block *res)
Multiply polynomial by (x)
Definition: gcm.c:189
static uint16_t gcm_cached_reduce[256]
Cached reduction table (R) for Shoup's method.
Definition: gcm.c:110
union @382 key
Sense key.
Definition: crypto.h:284
void * memset(void *dest, int character, size_t len) __nonnull
uint8_t flags
Flags.
Definition: ena.h:18