231 unsigned int column ) {
232 size_t offset = ( column * 4 );
242 key->column[column] );
299 }
while ( --rounds );
343 }
while ( --rounds );
381 for ( out_offset = 0, in_offset = 0 ; out_offset < 16 ;
382 out_offset++, in_offset = ( ( in_offset +
stride ) & 0xf ) ) {
385 byte =
in->byte[in_offset];
393 out->byte[out_offset] = entry->
byte[0];
412 rounds = ( ( aes->
rounds & 6 ) + 7 );
428 const void *
src,
void *dst,
size_t len ) {
465 const void *
src,
void *dst,
size_t len ) {
503 poly = rol8 ( poly, 1 );
524 unsigned int scalar_x_1;
525 unsigned int scalar_x;
529 scalar = entry->
byte[0];
530 entry->
byte[1] = scalar;
531 entry->
byte[2] = scalar;
532 entry->
byte[5] = scalar;
533 entry->
byte[6] = scalar;
537 entry->
byte[4] = scalar_x;
540 scalar_x_1 = ( scalar_x ^ scalar );
541 entry->
byte[3] = scalar_x_1;
542 entry->
byte[7] = scalar_x_1;
553 unsigned int scalar_x3_x2_x;
554 unsigned int scalar_x3_x2_1;
555 unsigned int scalar_x3_x2;
556 unsigned int scalar_x3_x_1;
557 unsigned int scalar_x3_1;
558 unsigned int scalar_x3;
559 unsigned int scalar_x2;
560 unsigned int scalar_x;
564 scalar = entry->
byte[0];
576 scalar_x3_1 = ( scalar_x3 ^ scalar );
577 entry->
byte[1] = scalar_x3_1;
578 entry->
byte[5] = scalar_x3_1;
581 scalar_x3_x_1 = ( scalar_x3_1 ^ scalar_x );
582 entry->
byte[3] = scalar_x3_x_1;
583 entry->
byte[7] = scalar_x3_x_1;
586 scalar_x3_x2 = ( scalar_x3 ^ scalar_x2 );
589 scalar_x3_x2_1 = ( scalar_x3_x2 ^ scalar );
590 entry->
byte[2] = scalar_x3_x2_1;
591 entry->
byte[6] = scalar_x3_x2_1;
594 scalar_x3_x2_x = ( scalar_x3_x2 ^ scalar_x );
595 entry->
byte[4] = scalar_x3_x2_x;
605 unsigned int poly = 0x01;
606 unsigned int invpoly = 0x01;
607 unsigned int transformed;
621 invpoly ^= ( invpoly << 1 );
622 invpoly ^= ( invpoly << 2 );
623 invpoly ^= ( invpoly << 4 );
624 if ( invpoly & 0x80 )
629 transformed = ( 0x63 ^ invpoly ^ rol8 ( invpoly, 1 ) ^
630 rol8 ( invpoly, 2 ) ^ rol8 ( invpoly, 3 ) ^
631 rol8 ( invpoly, 4 ) );
636 }
while ( poly != 0x01 );
642 for ( i = 0 ; i < 256 ; i++ ) {
650 inventry->
byte[0] = i;
680 for ( i = 0 ; i < 4 ; i++ ) {
681 byte = ( column & 0xff );
683 column = ( ( column & ~0xff ) |
byte );
684 column =
rol32 ( column, 8 );
700 ( column ^ rcon ) : ( column ^ ( rcon << 24 ) ) );
713 const void *
key,
size_t keylen ) {
719 unsigned int rcon = 0x01;
749 DBGC ( aes,
"AES %p unsupported key length (%zd bits)\n",
750 aes, ( keylen * 8 ) );
760 next = ( ( (
void * ) prev ) + keylen );
789 offset +=
sizeof ( *next );
795 DBGC2 ( aes,
"AES %p expanded %zd-bit key:\n", aes, ( keylen * 8 ) );
799 memset ( &zero, 0,
sizeof ( zero ) );
801 memcpy ( dec--, enc++,
sizeof ( *dec ) );
810 enc++, &temp, &zero );
813 memcpy ( dec--, enc++,
sizeof ( *dec ) );
814 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.
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.
int aes_is_accelerated(void)
Check if hardware acceleration is currently enabled (for testing).
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.
void aes_decelerate(void)
Disable hardware acceleration (for testing).
static unsigned int aes_rounds(const struct aes_context *aes)
Calculate number of intermediate rounds.
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 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 const union aes_matrix * aes_encrypt_rounds(union aes_matrix *in, union aes_matrix *out, const union aes_matrix *key, unsigned int rounds)
Perform encryption intermediate rounds.
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 int aes_selected
AES hardware acceleration mode has been selected.
static const union aes_matrix * aes_decrypt_rounds(union aes_matrix *in, union aes_matrix *out, const union aes_matrix *key, unsigned int rounds)
Perform decryption intermediate rounds.
static uint32_t aes_key_rotate(uint32_t column)
Rotate key column.
void aes_accelerate(void)
Enable hardware acceleration (if supported).
#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.
#define AES_MAX_ROUNDS
Maximum number of AES rounds.
struct cipher_algorithm aes_ecb_algorithm
struct cipher_algorithm aes_cbc_algorithm
static struct aes_context * aes_context(void *ctx)
Align AES context.
struct cipher_algorithm aes_gcm_algorithm
#define AES_BLOCKSIZE
AES blocksize.
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.
uint8_t 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.