diff options
Diffstat (limited to 'aes')
| -rw-r--r-- | aes/include/aes/aes.h | 54 | ||||
| -rw-r--r-- | aes/include/aes/all.h | 4 | ||||
| -rw-r--r-- | aes/include/aes/data.h | 70 |
3 files changed, 8 insertions, 120 deletions
diff --git a/aes/include/aes/aes.h b/aes/include/aes/aes.h index 73d6618..80f2b6f 100644 --- a/aes/include/aes/aes.h +++ b/aes/include/aes/aes.h @@ -62,18 +62,10 @@ typedef struct { char str[33]; } AES_BlockString; -typedef AES_BlockString AES128_BlockString; -typedef AES_BlockString AES192_BlockString; -typedef AES_BlockString AES256_BlockString; - typedef struct { char str[49]; } AES_BlockMatrixString; -typedef AES_BlockMatrixString AES128_BlockMatrixString; -typedef AES_BlockMatrixString AES192_BlockMatrixString; -typedef AES_BlockMatrixString AES256_BlockMatrixString; - AES_StatusCode aes_format_block(AES_BlockString*, const AES_Block*, AES_ErrorDetails*); AES_StatusCode aes_format_block_as_matrix( @@ -101,21 +93,15 @@ typedef struct { } AES256_KeyString; AES_StatusCode aes128_format_key(AES128_KeyString*, const AES128_Key*, AES_ErrorDetails*); - AES_StatusCode aes192_format_key(AES192_KeyString*, const AES192_Key*, AES_ErrorDetails*); - AES_StatusCode aes256_format_key(AES256_KeyString*, const AES256_Key*, AES_ErrorDetails*); AES_StatusCode aes128_print_key(const AES128_Key*, AES_ErrorDetails*); - AES_StatusCode aes192_print_key(const AES192_Key*, AES_ErrorDetails*); - AES_StatusCode aes256_print_key(const AES256_Key*, AES_ErrorDetails*); AES_StatusCode aes128_parse_key(AES128_Key* dest, const char* src, AES_ErrorDetails* err_details); - AES_StatusCode aes192_parse_key(AES192_Key* dest, const char* src, AES_ErrorDetails* err_details); - AES_StatusCode aes256_parse_key(AES256_Key* dest, const char* src, AES_ErrorDetails* err_details); typedef struct { @@ -160,15 +146,11 @@ void __fastcall aes256_derive_decryption_keys_( ); AES_Block __fastcall aes128_encrypt_block_(AES_Block plaintext, const AES128_RoundKeys*); - AES_Block __fastcall aes192_encrypt_block_(AES_Block plaintext, const AES192_RoundKeys*); - AES_Block __fastcall aes256_encrypt_block_(AES_Block plaintext, const AES256_RoundKeys*); AES_Block __fastcall aes128_decrypt_block_(AES_Block ciphertext, const AES128_RoundKeys*); - AES_Block __fastcall aes192_decrypt_block_(AES_Block ciphertext, const AES192_RoundKeys*); - AES_Block __fastcall aes256_decrypt_block_(AES_Block ciphertext, const AES256_RoundKeys*); AES_ENCRYPT_BLOCK_ECB(128) @@ -204,12 +186,6 @@ AES_DECRYPT_BLOCK_OFB(256) AES_ENCRYPT_BLOCK_CTR(256) AES_DECRYPT_BLOCK_CTR(256) -/** - * \brief Expands an AES-128 key into 10 encryption round keys. - * - * \param[in] key The AES-128 key. - * \param[out] encryption_keys The AES-128 encryption round keys. Must not be `NULL`. - */ static inline void __fastcall aes128_expand_key( const AES128_Key* key, AES128_RoundKeys* encryption_keys @@ -219,12 +195,6 @@ static inline void __fastcall aes128_expand_key( aes128_expand_key_(key->key, encryption_keys); } -/** - * \brief Derives AES-128 decryption round keys from AES-128 encryption round keys. - * - * \param[in] encryption_keys The AES-128 encryption round keys. Must not be `NULL`. - * \param[out] decryption_keys The AES-128 decryption round keys. Must not be `NULL`. - */ static inline void __fastcall aes128_derive_decryption_keys( const AES128_RoundKeys* encryption_keys, AES128_RoundKeys* decryption_keys @@ -235,12 +205,6 @@ static inline void __fastcall aes128_derive_decryption_keys( aes128_derive_decryption_keys_(encryption_keys, decryption_keys); } -/** - * \brief Expands an AES-192 key into 12 encryption round keys. - * - * \param[in] key The AES-192 key. - * \param[out] encryption_keys The AES-192 encryption round keys. Must not be `NULL`. - */ static inline void __fastcall aes192_expand_key( const AES192_Key* key, AES192_RoundKeys* encryption_keys @@ -251,12 +215,6 @@ static inline void __fastcall aes192_expand_key( aes192_expand_key_(key->lo, key->hi, encryption_keys); } -/** - * \brief Derives AES-192 decryption round keys from AES-192 encryption round keys. - * - * \param[in] encryption_keys The AES-192 encryption round keys. Must not be `NULL`. - * \param[out] decryption_keys The AES-192 decryption round keys. Must not be `NULL`. - */ static inline void __fastcall aes192_derive_decryption_keys( const AES192_RoundKeys* encryption_keys, AES192_RoundKeys* decryption_keys @@ -267,12 +225,6 @@ static inline void __fastcall aes192_derive_decryption_keys( aes192_derive_decryption_keys_(encryption_keys, decryption_keys); } -/** - * \brief Expands an AES-256 key into 14 encryption round keys. - * - * \param[in] key The AES-256 key. - * \param[out] encryption_keys The AES-256 encryption round keys. Must not be `NULL`. - */ static inline void __fastcall aes256_expand_key( const AES256_Key* key, AES256_RoundKeys* encryption_keys @@ -283,12 +235,6 @@ static inline void __fastcall aes256_expand_key( aes256_expand_key_(key->lo, key->hi, encryption_keys); } -/** - * \brief Derives AES-256 decryption round keys from AES-256 encryption round keys. - * - * \param[in] encryption_keys The AES-256 encryption round keys. Must not be `NULL`. - * \param[out] decryption_keys The AES-256 decryption round keys. Must not be `NULL`. - */ static inline void __fastcall aes256_derive_decryption_keys( const AES256_RoundKeys* encryption_keys, AES256_RoundKeys* decryption_keys diff --git a/aes/include/aes/all.h b/aes/include/aes/all.h index ff27c18..8b60483 100644 --- a/aes/include/aes/all.h +++ b/aes/include/aes/all.h @@ -5,10 +5,6 @@ #pragma once -/** - * \defgroup aes AES - */ - #include "aes.h" #include "algorithm.h" #include "box.h" diff --git a/aes/include/aes/data.h b/aes/include/aes/data.h index b83cb1d..e06ec33 100644 --- a/aes/include/aes/data.h +++ b/aes/include/aes/data.h @@ -12,100 +12,46 @@ extern "C" { #endif -/** - * \brief Represents a 128-bit AES block. - */ typedef __m128i AES_Block; -/** - * \brief Loads a 128-bit block from a memory location. - * - * \param[in] src The pointer to a memory location. Must not be `NULL`. - * - * \return The loaded 128-bit block. - */ static inline AES_Block aes_load_block(const void* src) { return _mm_loadu_si128((AES_Block*)src); } -/** - * \brief Loads a 128-bit block from a 16-byte aligned memory location. - * - * \param[in] src The pointer to a 16-byte aligned memory location. Must not be `NULL`. - * - * \return The loaded 128-bit block. - */ static inline AES_Block aes_load_block_aligned(const void* src) { return _mm_load_si128((AES_Block*)src); } -/** - * \brief Stores a 128-bit block in a memory location. - * - * \param[out] dest The pointer to a memory location. Must not be `NULL`. - * - * \param[in] block The block to be stored. - */ static inline void __fastcall aes_store_block(void* dest, AES_Block block) { _mm_storeu_si128((AES_Block*)dest, block); } -/** - * \brief Stores a 128-bit block in a 16-byte aligned memory location. - * - * \param[out] dest The pointer to a 16-byte aligned memory location. Must not be `NULL`. - * - * \param[in] block The block to be stored. - */ static inline void __fastcall aes_store_block_aligned(void* dest, AES_Block block) { _mm_store_si128((AES_Block*)dest, block); } -/** - * \brief XORs two 128-bit blocks. - * - * \param[in] a The first XOR operand. - * \param[in] b The second XOR operand. - * - * \return `a^b`. - */ static inline AES_Block __fastcall aes_xor_blocks(AES_Block a, AES_Block b) { return _mm_xor_si128(a, b); } /** - * \brief Builds a 128-bit block from four 4-byte values. - * - * Builds a 128-bit block like this: - * - * * dest[127:96] = hi3 - * * dest[95:64] = hi2 - * * dest[63:32] = lo1 - * * dest[31:0] = lo0 - * - * \param[in] hi3 The most significant 4-byte value. - * \param[in] hi2 The more significant 4-byte value. - * \param[in] lo1 The less significant 4-byte value. - * \param[in] lo0 The least significant 4-byte value. - * - * \return The built 128-bit block. + * hi3 - The most significant 4-byte value. + * hi2 - The more significant 4-byte value. + * lo1 - The less significant 4-byte value. + * lo0 - The least significant 4-byte value. */ static inline AES_Block __fastcall aes_make_block(int hi3, int hi2, int lo1, int lo0) { return _mm_set_epi32(hi3, hi2, lo1, lo0); } -static inline AES_Block __fastcall aes_reverse_byte_order_block(AES_Block block) { +static inline AES_Block __fastcall aes_reverse_byte_order_in_block(AES_Block block) { return _mm_shuffle_epi8(block, aes_make_block(0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f)); } -static inline AES_Block __fastcall _aes_inc_block(AES_Block x) { - return _mm_add_epi32(x, aes_make_block(0, 0, 0, 1)); -} - static inline AES_Block __fastcall aes_inc_block(AES_Block x) { - x = aes_reverse_byte_order_block(x); - x = _aes_inc_block(x); - x = aes_reverse_byte_order_block(x); + x = aes_reverse_byte_order_in_block(x); + x = _mm_add_epi32(x, aes_make_block(0, 0, 0, 1)); + x = aes_reverse_byte_order_in_block(x); return x; } |
