48 #define GCM_FL_ENCRYPT 0x00ff 57 #define GCM_FL_IV 0x0100 119 gcm_reverse (
const uint8_t byte ) {
123 for ( mask = 1 ; mask ; mask <<= 1 ) {
153 static inline void gcm_xor (
const void *src1,
const void *src2,
void *dst,
156 const uint8_t *src1_bytes = src1;
157 const uint8_t *src2_bytes = src2;
161 *(dst_bytes++) = ( *(src1_bytes++) ^ *(src2_bytes++) );
193 for ( i = 0, carry = 0 ; i <
sizeof ( res->
byte ) ; i++ ) {
194 byte = mult->
byte[i];
195 res->
byte[i] = ( ( carry << 7 ) | (
byte >> 1 ) );
196 carry = (
byte & 0x01 );
223 for ( i = 1 ; i < 256 ; i++ ) {
226 this = gcm_reverse ( i );
233 other = (
this & 0x7f );
243 other = (
this << 1 );
268 byte = &poly->
byte[
sizeof ( poly->
byte ) - 1 ];
272 for ( ;
byte > &poly->
byte[0] ;
byte-- )
273 *
byte = *(
byte - 1 );
296 byte = &poly->
byte[
sizeof ( poly->
byte ) - 1 ];
298 for (
byte-- ;
byte >= &poly->
byte[0] ;
byte-- ) {
304 memcpy ( poly, &res,
sizeof ( *poly ) );
317 void *dst,
size_t len,
unsigned int flags ) {
325 ( 8 *
sizeof (
tmp ) ) ) +
327 ( 8 *
sizeof (
tmp ) ) ) + 1 );
332 *total += (
len * 8 );
339 if ( frag_len >
sizeof (
tmp ) )
340 frag_len =
sizeof (
tmp );
349 gcm_count ( &context->
ctr, 1 );
352 DBGC2 ( context,
"GCM %p Y[%d]:\n", context,
block );
354 sizeof ( context->
ctr ) );
357 DBGC2 ( context,
"GCM %p E(K,Y[%d]):\n",
367 ( frag_len &
flags ) );
372 DBGC2 ( context,
"GCM %p X[%d]:\n", context,
block );
374 sizeof ( context->
hash ) );
389 DBGC2 ( context,
"GCM %p len(A)||len(C):\n", context );
395 DBGC2 ( context,
"GCM %p GHASH(H,A,C):\n", context );
418 DBGC2 ( context,
"GCM %p E(K,Y[0]):\n", context );
423 DBGC2 ( context,
"GCM %p T:\n", context );
441 memset ( context, 0,
sizeof ( *context ) );
451 &context->
key, sizeof ( context->
key ) );
452 DBGC2 ( context,
"GCM %p H:\n", context );
472 union gcm_block *check = ( (
void * ) context );
487 if ( ivlen ==
sizeof ( context->
ctr.
ctr.
iv ) ) {
503 DBGC2 ( context,
"GCM %p Y[0]:\n", context );
#define cpu_to_be16(value)
struct arbelprm_rc_send_wqe rc
#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.
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.
#define offsetof(type, field)
Get offset of a field within a structure.
union gcm_block hash
Accumulated hash (X)
uint32_t value
Counter value.
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)
static __attribute__((always_inline))
Reverse bits in a byte.
void gcm_setiv(struct gcm_context *context, const void *iv, size_t ivlen)
Set initialisation vector.
static void gcm_process(struct gcm_context *context, const void *src, void *dst, size_t len, unsigned int flags)
Encrypt/decrypt/authenticate data.
static userptr_t size_t offset
Offset of the first segment within the content.
#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.
pseudo_bit_t value[0x00020]
static __always_inline void off_t userptr_t src
pseudo_bit_t hash[0x00010]
Hash algorithm.
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 cpu_to_be32(value)
union gcm_block ctr
Counter (Y)
uint8_t iv[12]
Initialisation vector.
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)
static const union gcm_block * gcm_cached_key
Hash key for which multiplication tables are cached.
typeof(acpi_finder=acpi_find)
ACPI table finder.
struct gcm_counter ctr
Counter.
uint64_t add
Additional data length.
uint64_t tag
Identity tag.
#define linker_assert(condition, error_symbol)
Assert a condition at link-time.
#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