48 #define GCM_FL_ENCRYPT 0x00ff 57 #define GCM_FL_IV 0x0100 113 #define gcm_offset( field ) offsetof ( struct gcm_context, field ) 126 for ( mask = 1 ; mask ; mask <<= 1 ) {
156 static inline void gcm_xor (
const void *src1,
const void *src2,
void *dst,
159 const uint8_t *src1_bytes = src1;
160 const uint8_t *src2_bytes = src2;
164 *(dst_bytes++) = ( *(src1_bytes++) ^ *(src2_bytes++) );
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 );
226 for ( i = 1 ; i < 256 ; i++ ) {
236 other = (
this & 0x7f );
246 other = (
this << 1 );
271 byte = &poly->
byte[
sizeof ( poly->
byte ) - 1 ];
275 for ( ;
byte > &poly->
byte[0] ;
byte-- )
276 *
byte = *(
byte - 1 );
299 byte = &poly->
byte[
sizeof ( poly->
byte ) - 1 ];
301 for (
byte-- ;
byte >= &poly->
byte[0] ;
byte-- ) {
307 memcpy ( poly, &res,
sizeof ( *poly ) );
320 void *dst,
size_t len,
unsigned int flags ) {
328 ( 8 *
sizeof (
tmp ) ) ) +
330 ( 8 *
sizeof (
tmp ) ) ) + 1 );
335 *total += (
len * 8 );
342 if ( frag_len >
sizeof (
tmp ) )
343 frag_len =
sizeof (
tmp );
355 DBGC2 ( context,
"GCM %p Y[%d]:\n", context,
block );
357 sizeof ( context->
ctr ) );
360 DBGC2 ( context,
"GCM %p E(K,Y[%d]):\n",
370 ( frag_len &
flags ) );
375 DBGC2 ( context,
"GCM %p X[%d]:\n", context,
block );
377 sizeof ( context->
hash ) );
392 DBGC2 ( context,
"GCM %p len(A)||len(C):\n", context );
398 DBGC2 ( context,
"GCM %p GHASH(H,A,C):\n", context );
421 DBGC2 ( context,
"GCM %p E(K,Y[0]):\n", context );
426 DBGC2 ( context,
"GCM %p T:\n", context );
444 memset ( context, 0,
sizeof ( *context ) );
454 &context->
key, sizeof ( context->
key ) );
455 DBGC2 ( context,
"GCM %p H:\n", context );
488 if ( ivlen ==
sizeof ( context->
ctr.
ctr.
iv ) ) {
509 DBGC2 ( context,
"GCM %p Y[0]:\n", context );
#define cpu_to_be16(value)
struct arbelprm_rc_send_wqe rc
pseudo_bit_t hash[0x00010]
#define GCM_FL_ENCRYPT
Perform encryption.
union gcm_block len
Accumulated lengths.
uint8_t raw_ctx[0]
Underlying block cipher context.
struct gcm_lengths len
Lengths.
uint8_t iv[12]
Initialisation vector.
static void gcm_hash(struct gcm_context *context, union gcm_block *hash)
Construct hash.
static void gcm_cache(const union gcm_block *key)
Construct cached tables.
static void gcm_count(union gcm_block *ctr, uint32_t delta)
Update GCM counter.
uint8_t byte[16]
Raw bytes.
#define GCM_FL_IV
Calculate hash over an initialisation vector value.
void gcm_tag(struct gcm_context *context, union gcm_block *tag)
Construct tag.
void gcm_decrypt(struct gcm_context *context, const void *src, void *dst, size_t len)
Decrypt data.
unsigned long long uint64_t
static union gcm_block gcm_cached_mult[256]
Cached multiplication table (M0) for Shoup's method.
static void gcm_xor_block(const union gcm_block *src, union gcm_block *dst)
XOR whole data block in situ.
union gcm_block hash
Accumulated hash (X)
uint32_t value
Counter value.
u8 iv[16]
Initialization vector.
struct cipher_algorithm * raw_cipher
Underlying block cipher.
#define cipher_encrypt(cipher, ctx, src, dst, len)
static void gcm_multiply_key(const union gcm_block *key, union gcm_block *poly)
Multiply polynomial by hash key in situ.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int gcm_setkey(struct gcm_context *context, const void *key, size_t keylen, struct cipher_algorithm *raw_cipher)
Set key.
#define be32_to_cpu(value)
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void gcm_setiv(struct gcm_context *context, const void *iv, size_t ivlen)
Set initialisation vector.
pseudo_bit_t value[0x00020]
#define build_assert(condition)
Assert a condition at build time (after dead code elimination)
static void gcm_process(struct gcm_context *context, const void *src, void *dst, size_t len, unsigned int flags)
Encrypt/decrypt/authenticate data.
#define be16_to_cpu(value)
union gcm_block key
Hash key (H)
void gcm_encrypt(struct gcm_context *context, const void *src, void *dst, size_t len)
Encrypt data.
uint64_t data
Data length.
struct gcm_counter ctr
Counter.
static uint8_t gcm_reverse(const uint8_t byte)
Reverse bits in a byte.
static void gcm_xor(const void *src1, const void *src2, void *dst, size_t len)
XOR partial data block.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
uint16_t word[8]
Raw words.
uint32_t dword[4]
Raw dwords.
#define gcm_offset(field)
Offset of a field within GCM context.
#define cpu_to_be32(value)
union gcm_block ctr
Counter (Y)
uint8_t block[3][8]
DES-encrypted blocks.
static void gcm_multiply_x_8(union gcm_block *poly)
Multiply polynomial by (x^8) in situ.
Galois/Counter Mode (GCM)
#define cpu_to_be64(value)
uint16_t offset
Offset to command line.
static const union gcm_block * gcm_cached_key
Hash key for which multiplication tables are cached.
uint64_t add
Additional data length.
uint64_t tag
Identity tag.
#define NULL
NULL pointer (VOID *)
#define GCM_POLY
GCM field polynomial.
static void gcm_multiply_x(const union gcm_block *mult, union gcm_block *res)
Multiply polynomial by (x)
static uint16_t gcm_cached_reduce[256]
Cached reduction table (R) for Shoup's method.
static int cipher_setkey(struct cipher_algorithm *cipher, void *ctx, const void *key, size_t keylen)
void * memset(void *dest, int character, size_t len) __nonnull