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