228 unsigned int column ) {
229 size_t offset = ( column * 4 );
239 key->column[column] );
295 }
while ( --rounds );
336 }
while ( --rounds );
372 for ( out_offset = 0, in_offset = 0 ; out_offset < 16 ;
373 out_offset++, in_offset = ( ( in_offset +
stride ) & 0xf ) ) {
376 byte =
in->byte[in_offset];
384 out->byte[out_offset] = entry->
byte[0];
401 const void *
src,
void *dst,
size_t len ) {
406 unsigned int rounds = aes->
rounds;
439 const void *
src,
void *dst,
size_t len ) {
444 unsigned int rounds = aes->
rounds;
478 poly = rol8 ( poly, 1 );
499 unsigned int scalar_x_1;
500 unsigned int scalar_x;
504 scalar = entry->
byte[0];
505 entry->
byte[1] = scalar;
506 entry->
byte[2] = scalar;
507 entry->
byte[5] = scalar;
508 entry->
byte[6] = scalar;
512 entry->
byte[4] = scalar_x;
515 scalar_x_1 = ( scalar_x ^ scalar );
516 entry->
byte[3] = scalar_x_1;
517 entry->
byte[7] = scalar_x_1;
528 unsigned int scalar_x3_x2_x;
529 unsigned int scalar_x3_x2_1;
530 unsigned int scalar_x3_x2;
531 unsigned int scalar_x3_x_1;
532 unsigned int scalar_x3_1;
533 unsigned int scalar_x3;
534 unsigned int scalar_x2;
535 unsigned int scalar_x;
539 scalar = entry->
byte[0];
551 scalar_x3_1 = ( scalar_x3 ^ scalar );
552 entry->
byte[1] = scalar_x3_1;
553 entry->
byte[5] = scalar_x3_1;
556 scalar_x3_x_1 = ( scalar_x3_1 ^ scalar_x );
557 entry->
byte[3] = scalar_x3_x_1;
558 entry->
byte[7] = scalar_x3_x_1;
561 scalar_x3_x2 = ( scalar_x3 ^ scalar_x2 );
564 scalar_x3_x2_1 = ( scalar_x3_x2 ^ scalar );
565 entry->
byte[2] = scalar_x3_x2_1;
566 entry->
byte[6] = scalar_x3_x2_1;
569 scalar_x3_x2_x = ( scalar_x3_x2 ^ scalar_x );
570 entry->
byte[4] = scalar_x3_x2_x;
580 unsigned int poly = 0x01;
581 unsigned int invpoly = 0x01;
582 unsigned int transformed;
596 invpoly ^= ( invpoly << 1 );
597 invpoly ^= ( invpoly << 2 );
598 invpoly ^= ( invpoly << 4 );
599 if ( invpoly & 0x80 )
604 transformed = ( 0x63 ^ invpoly ^ rol8 ( invpoly, 1 ) ^
605 rol8 ( invpoly, 2 ) ^ rol8 ( invpoly, 3 ) ^
606 rol8 ( invpoly, 4 ) );
611 }
while ( poly != 0x01 );
617 for ( i = 0 ; i < 256 ; i++ ) {
625 inventry->
byte[0] = i;
655 for ( i = 0 ; i < 4 ; i++ ) {
656 byte = ( column & 0xff );
658 column = ( ( column & ~0xff ) |
byte );
659 column =
rol32 ( column, 8 );
675 ( column ^ rcon ) : ( column ^ ( rcon << 24 ) ) );
688 const void *
key,
size_t keylen ) {
694 unsigned int rcon = 0x01;
718 DBGC ( aes,
"AES %p unsupported key length (%zd bits)\n",
719 aes, ( keylen * 8 ) );
729 next = ( ( (
void * ) prev ) + keylen );
758 offset +=
sizeof ( *next );
764 DBGC2 ( aes,
"AES %p expanded %zd-bit key:\n", aes, ( keylen * 8 ) );
768 memset ( &zero, 0,
sizeof ( zero ) );
770 memcpy ( dec--, enc++,
sizeof ( *dec ) );
779 enc++, &temp, &zero );
782 memcpy ( dec--, enc++,
sizeof ( *dec ) );
783 DBGC2 ( aes,
"AES %p inverted %zd-bit key:\n", aes, ( keylen * 8 ) );
struct golan_eq_context ctx
union @162305117151260234136356364136041353210355154177 key
typeof(acpi_finder=acpi_find)
ACPI table finder.
static uint32_t aes_key_sbox(uint32_t column)
Apply S-box to key column.
static struct aes_table aes_mixcolumns
AES MixColumns lookup table.
static void aes_decrypt_rounds(union aes_matrix *in, union aes_matrix *out, const union aes_matrix *key, unsigned int rounds)
Perform decryption intermediate rounds.
struct cipher_algorithm aes_algorithm
Basic AES algorithm.
static void aes_round(const struct aes_table *table, size_t stride, const union aes_matrix *in, union aes_matrix *out, const union aes_matrix *key)
Perform a single intermediate round.
static void aes_generate(void)
Generate AES lookup tables.
@ AES_STRIDE_SHIFTROWS
Input stride for ShiftRows.
@ AES_STRIDE_INVSHIFTROWS
Input stride for InvShiftRows.
static void aes_final(const struct aes_table *table, size_t stride, const union aes_matrix *in, union aes_matrix *out, const union aes_matrix *key)
Perform final round.
static void aes_addroundkey(union aes_matrix *state, const union aes_matrix *key)
Perform standalone AddRoundKey.
static uint32_t aes_key_rcon(uint32_t column, unsigned int rcon)
Apply schedule round constant to key column.
static void aes_encrypt(struct cipher_algorithm *cipher __unused, void *ctx, const void *src, void *dst, size_t len)
Encrypt data.
static void aes_decrypt(struct cipher_algorithm *cipher __unused, void *ctx, const void *src, void *dst, size_t len)
Decrypt data.
static uint32_t aes_entry_column(const union aes_table_entry *entry, unsigned int column)
Multiply [Inv]MixColumns matrix column by scalar multiplicand.
static uint32_t aes_output(const struct aes_table *table, size_t stride, const union aes_matrix *in, const union aes_matrix *key, unsigned int column)
Calculate intermediate round output column.
static unsigned int aes_double(unsigned int poly)
Multiply a polynomial by (x) modulo (x^8 + x^4 + x^3 + x^2 + 1) in GF(2^8).
static void aes_encrypt_rounds(union aes_matrix *in, union aes_matrix *out, const union aes_matrix *key, unsigned int rounds)
Perform encryption intermediate rounds.
static int aes_setkey(struct cipher_algorithm *cipher __unused, void *ctx, const void *key, size_t keylen)
Set key.
static uint32_t aes_column(const struct aes_table *table, size_t stride, const union aes_matrix *in, size_t offset)
Multiply [Inv]MixColumns matrix column by S-boxed input byte.
static void aes_mixcolumns_entry(union aes_table_entry *entry)
Fill in MixColumns lookup table entry.
static struct aes_table aes_invmixcolumns
AES InvMixColumns lookup table.
static void aes_invmixcolumns_entry(union aes_table_entry *entry)
Fill in InvMixColumns lookup table entry.
static uint32_t aes_key_rotate(uint32_t column)
Rotate key column.
struct cipher_algorithm aes_ecb_algorithm
struct cipher_algorithm aes_cbc_algorithm
struct cipher_algorithm aes_gcm_algorithm
#define AES_BLOCKSIZE
AES blocksize.
#define assert(condition)
Assert a condition at run-time.
uint16_t offset
Offset to command line.
#define CBC_CIPHER(_cbc_name, _cbc_cipher, _raw_cipher, _raw_context, _blocksize)
Create a cipher-block chaining mode of behaviour of an existing cipher.
int cipher_null_setiv(struct cipher_algorithm *cipher __unused, void *ctx __unused, const void *iv __unused, size_t ivlen __unused)
void cipher_null_auth(struct cipher_algorithm *cipher __unused, void *ctx __unused, void *auth __unused)
uint32_t next
Next descriptor address.
Electronic codebook (ECB).
#define ECB_CIPHER(_ecb_name, _ecb_cipher, _raw_cipher, _raw_context, _blocksize)
Create an electronic codebook mode of behaviour of an existing cipher.
struct ena_llq_option stride
Descriptor strides.
Galois/Counter Mode (GCM).
#define GCM_CIPHER(_gcm_name, _gcm_cipher, _raw_cipher, _raw_context, _blocksize)
Create a GCM mode of behaviour of an existing cipher.
#define __unused
Declare a variable or data structure as unused.
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER).
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define EINVAL
Invalid argument.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
#define __LITTLE_ENDIAN
Constant representing little-endian byte order.
uint8_t product
Product string.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
uint32_t end
Ending offset.
#define container_of(ptr, type, field)
Get containing structure.
struct aes_round_keys decrypt
Decryption keys.
unsigned int rounds
Number of rounds.
struct aes_round_keys encrypt
Encryption keys.
union aes_matrix key[AES_MAX_ROUNDS]
Round keys.
union aes_table_entry entry[256]
Table entries, indexed by S(N).
uint32_t column[4]
Viewed as an array of four-byte columns.
A single AES lookup table entry.
uint8_t byte[8]
Viewed as an array of bytes.
static u32 ror32(u32 v, int bits)
Rotate 32-bit value right.
static u32 rol32(u32 v, int bits)
Rotate 32-bit value left.