diff options
-rw-r--r-- | cxx/include/aesnixx/aes.hpp | 122 | ||||
-rw-r--r-- | include/aesni/aes.h | 503 | ||||
-rw-r--r-- | include/aesni/box_data.h | 20 | ||||
-rw-r--r-- | include/aesni/mode.h | 160 | ||||
-rw-r--r-- | src/aes.c | 105 | ||||
-rw-r--r-- | src/asm/aes128.asm | 16 | ||||
-rw-r--r-- | src/asm/aes192.asm | 16 | ||||
-rw-r--r-- | src/asm/aes256.asm | 16 | ||||
-rw-r--r-- | src/box_aes.c | 28 | ||||
-rw-r--r-- | src/c/aes128.c | 32 | ||||
-rw-r--r-- | src/c/aes192.c | 34 | ||||
-rw-r--r-- | src/c/aes256.c | 40 |
12 files changed, 624 insertions, 468 deletions
diff --git a/cxx/include/aesnixx/aes.hpp b/cxx/include/aesnixx/aes.hpp index 231e223..358e24f 100644 --- a/cxx/include/aesnixx/aes.hpp +++ b/cxx/include/aesnixx/aes.hpp @@ -20,49 +20,49 @@ namespace aesni { namespace aes { - typedef AesNI_Aes_Block Block; + typedef AesNI_AES_Block Block; - typedef AesNI_Aes128_Key Key128; - typedef AesNI_Aes192_Key Key192; - typedef AesNI_Aes256_Key Key256; + typedef AesNI_AES128_Key Key128; + typedef AesNI_AES192_Key Key192; + typedef AesNI_AES256_Key Key256; inline void make_block(Block& dest, int hi3, int hi2, int lo1, int lo0) { - aesni_aes_make_block(&dest, hi3, hi2, lo1, lo0); + aesni_AES_make_block(&dest, hi3, hi2, lo1, lo0); } inline void make_key(Key128& dest, int hi3, int hi2, int lo1, int lo0) { - aesni_aes128_make_key(&dest, hi3, hi2, lo1, lo0); + aesni_AES128_make_key(&dest, hi3, hi2, lo1, lo0); } inline void make_key(Key192& dest, int hi5, int hi4, int hi3, int lo2, int lo1, int lo0) { - aesni_aes192_make_key(&dest, hi5, hi4, hi3, lo2, lo1, lo0); + aesni_AES192_make_key(&dest, hi5, hi4, hi3, lo2, lo1, lo0); } inline void make_key(Key256& dest, int hi7, int hi6, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0) { - aesni_aes256_make_key(&dest, hi7, hi6, hi5, hi4, lo3, lo2, lo1, lo0); + aesni_AES256_make_key(&dest, hi7, hi6, hi5, hi4, lo3, lo2, lo1, lo0); } std::string to_string(const Block& block) { - AesNI_Aes_BlockString str; - aesni_aes_format_block(&str, &block, ErrorDetailsThrowsInDestructor()); + AesNI_AES_BlockString str; + aesni_AES_format_block(&str, &block, ErrorDetailsThrowsInDestructor()); return std::string(str.str); } std::string to_matrix_string(const Block& block) { - AesNI_Aes_BlockMatrixString str; - aesni_aes_format_block_as_matrix(&str, &block, ErrorDetailsThrowsInDestructor()); + AesNI_AES_BlockMatrixString str; + aesni_AES_format_block_as_matrix(&str, &block, ErrorDetailsThrowsInDestructor()); return std::string(str.str); } inline void from_string(Block& dest, const char* src) { - aesni_aes_parse_block(&dest, src, ErrorDetailsThrowsInDestructor()); + aesni_AES_parse_block(&dest, src, ErrorDetailsThrowsInDestructor()); } inline void from_string(Block& dest, const std::string& src) @@ -72,38 +72,38 @@ namespace aesni std::string to_string(const Key128& block) { - AesNI_Aes128_KeyString str; - aesni_aes128_format_key(&str, &block, ErrorDetailsThrowsInDestructor()); + AesNI_AES128_KeyString str; + aesni_AES128_format_key(&str, &block, ErrorDetailsThrowsInDestructor()); return std::string(str.str); } std::string to_string(const Key192& block) { - AesNI_Aes192_KeyString str; - aesni_aes192_format_key(&str, &block, ErrorDetailsThrowsInDestructor()); + AesNI_AES192_KeyString str; + aesni_AES192_format_key(&str, &block, ErrorDetailsThrowsInDestructor()); return std::string(str.str); } std::string to_string(const Key256& block) { - AesNI_Aes256_KeyString str; - aesni_aes256_format_key(&str, &block, ErrorDetailsThrowsInDestructor()); + AesNI_AES256_KeyString str; + aesni_AES256_format_key(&str, &block, ErrorDetailsThrowsInDestructor()); return std::string(str.str); } inline void from_string(Key128& dest, const char* src) { - aesni_aes128_parse_key(&dest, src, ErrorDetailsThrowsInDestructor()); + aesni_AES128_parse_key(&dest, src, ErrorDetailsThrowsInDestructor()); } inline void from_string(Key192& dest, const char* src) { - aesni_aes192_parse_key(&dest, src, ErrorDetailsThrowsInDestructor()); + aesni_AES192_parse_key(&dest, src, ErrorDetailsThrowsInDestructor()); } inline void from_string(Key256& dest, const char* src) { - aesni_aes256_parse_key(&dest, src, ErrorDetailsThrowsInDestructor()); + aesni_AES256_parse_key(&dest, src, ErrorDetailsThrowsInDestructor()); } inline void from_string(Key128& dest, const std::string& src) @@ -121,9 +121,9 @@ namespace aesni return from_string(dest, src.c_str()); } - typedef AesNI_Aes128_RoundKeys RoundKeys128; - typedef AesNI_Aes192_RoundKeys RoundKeys192; - typedef AesNI_Aes256_RoundKeys RoundKeys256; + typedef AesNI_AES128_RoundKeys RoundKeys128; + typedef AesNI_AES192_RoundKeys RoundKeys192; + typedef AesNI_AES256_RoundKeys RoundKeys256; template <typename RoundKeysT> inline std::size_t get_number_of_rounds(const RoundKeysT& round_keys) @@ -135,28 +135,28 @@ namespace aesni const Key128& key, RoundKeys128& encryption_keys) { - aesni_aes128_expand_key(&key, &encryption_keys); + aesni_AES128_expand_key(&key, &encryption_keys); } inline void expand_key( const Key192& key, RoundKeys192& encryption_keys) { - aesni_aes192_expand_key(&key, &encryption_keys); + aesni_AES192_expand_key(&key, &encryption_keys); } inline void expand_key( const Key256& key, RoundKeys256& encryption_keys) { - aesni_aes256_expand_key(&key, &encryption_keys); + aesni_AES256_expand_key(&key, &encryption_keys); } inline void derive_decryption_keys( const RoundKeys128& encryption_keys, RoundKeys128& decryption_keys) { - aesni_aes128_derive_decryption_keys( + aesni_AES128_derive_decryption_keys( &encryption_keys, &decryption_keys); } @@ -164,7 +164,7 @@ namespace aesni const RoundKeys192& encryption_keys, RoundKeys192& decryption_keys) { - aesni_aes192_derive_decryption_keys( + aesni_AES192_derive_decryption_keys( &encryption_keys, &decryption_keys); } @@ -172,7 +172,7 @@ namespace aesni const RoundKeys256& encryption_keys, RoundKeys256& decryption_keys) { - aesni_aes256_derive_decryption_keys( + aesni_AES256_derive_decryption_keys( &encryption_keys, &decryption_keys); } @@ -180,14 +180,14 @@ namespace aesni const Block& plaintext, const RoundKeys128& encryption_keys) { - return aesni_aes128_encrypt_block_ecb(plaintext, &encryption_keys); + return aesni_AES128_encrypt_block_ECB(plaintext, &encryption_keys); } inline Block decrypt_ecb( const Block& ciphertext, const RoundKeys128& decryption_keys) { - return aesni_aes128_decrypt_block_ecb(ciphertext, &decryption_keys); + return aesni_AES128_decrypt_block_ECB(ciphertext, &decryption_keys); } inline Block encrypt_cbc( @@ -196,7 +196,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes128_encrypt_block_cbc(plaintext, &encryption_keys, iv, &next_iv); + return aesni_AES128_encrypt_block_CBC(plaintext, &encryption_keys, iv, &next_iv); } inline Block decrypt_cbc( @@ -205,7 +205,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes128_decrypt_block_cbc(ciphertext, &decryption_keys, iv, &next_iv); + return aesni_AES128_decrypt_block_CBC(ciphertext, &decryption_keys, iv, &next_iv); } inline Block encrypt_cfb( @@ -214,7 +214,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes128_encrypt_block_cfb(plaintext, &encryption_keys, iv, &next_iv); + return aesni_AES128_encrypt_block_CFB(plaintext, &encryption_keys, iv, &next_iv); } inline Block decrypt_cfb( @@ -223,7 +223,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes128_decrypt_block_cfb(ciphertext, &encryption_keys, iv, &next_iv); + return aesni_AES128_decrypt_block_CFB(ciphertext, &encryption_keys, iv, &next_iv); } inline Block encrypt_ofb( @@ -232,7 +232,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes128_encrypt_block_ofb(plaintext, &encryption_keys, iv, &next_iv); + return aesni_AES128_encrypt_block_OFB(plaintext, &encryption_keys, iv, &next_iv); } inline Block decrypt_ofb( @@ -241,7 +241,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes128_decrypt_block_ofb(ciphertext, &encryption_keys, iv, &next_iv); + return aesni_AES128_decrypt_block_OFB(ciphertext, &encryption_keys, iv, &next_iv); } inline Block encrypt_ctr( @@ -250,7 +250,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes128_encrypt_block_ctr(plaintext, &encryption_keys, iv, &next_iv); + return aesni_AES128_encrypt_block_CTR(plaintext, &encryption_keys, iv, &next_iv); } inline Block decrypt_ctr( @@ -259,21 +259,21 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes128_decrypt_block_ctr(ciphertext, &encryption_keys, iv, &next_iv); + return aesni_AES128_decrypt_block_CTR(ciphertext, &encryption_keys, iv, &next_iv); } inline Block encrypt_ecb( const Block& plaintext, const RoundKeys192& encryption_keys) { - return aesni_aes192_encrypt_block_ecb(plaintext, &encryption_keys); + return aesni_AES192_encrypt_block_ECB(plaintext, &encryption_keys); } inline Block decrypt_ecb( const Block& ciphertext, const RoundKeys192& decryption_keys) { - return aesni_aes192_decrypt_block_ecb(ciphertext, &decryption_keys); + return aesni_AES192_decrypt_block_ECB(ciphertext, &decryption_keys); } inline Block encrypt_cbc( @@ -282,7 +282,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes192_encrypt_block_cbc(plaintext, &encryption_keys, iv, &next_iv); + return aesni_AES192_encrypt_block_CBC(plaintext, &encryption_keys, iv, &next_iv); } inline Block decrypt_cbc( @@ -291,7 +291,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes192_decrypt_block_cbc(ciphertext, &decryption_keys, iv, &next_iv); + return aesni_AES192_decrypt_block_CBC(ciphertext, &decryption_keys, iv, &next_iv); } inline Block encrypt_cfb( @@ -300,7 +300,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes192_encrypt_block_cfb(plaintext, &encryption_keys, iv, &next_iv); + return aesni_AES192_encrypt_block_CFB(plaintext, &encryption_keys, iv, &next_iv); } inline Block decrypt_cfb( @@ -309,7 +309,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes192_decrypt_block_cfb(ciphertext, &encryption_keys, iv, &next_iv); + return aesni_AES192_decrypt_block_CFB(ciphertext, &encryption_keys, iv, &next_iv); } inline Block encrypt_ofb( @@ -318,7 +318,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes192_encrypt_block_ofb(plaintext, &encryption_keys, iv, &next_iv); + return aesni_AES192_encrypt_block_OFB(plaintext, &encryption_keys, iv, &next_iv); } inline Block decrypt_ofb( @@ -327,7 +327,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes192_decrypt_block_ofb(ciphertext, &encryption_keys, iv, &next_iv); + return aesni_AES192_decrypt_block_OFB(ciphertext, &encryption_keys, iv, &next_iv); } inline Block encrypt_ctr( @@ -336,7 +336,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes192_encrypt_block_ctr(plaintext, &encryption_keys, iv, &next_iv); + return aesni_AES192_encrypt_block_CTR(plaintext, &encryption_keys, iv, &next_iv); } inline Block decrypt_ctr( @@ -345,21 +345,21 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes192_decrypt_block_ctr(ciphertext, &encryption_keys, iv, &next_iv); + return aesni_AES192_decrypt_block_CTR(ciphertext, &encryption_keys, iv, &next_iv); } inline Block encrypt_ecb( const Block& plaintext, const RoundKeys256& encryption_keys) { - return aesni_aes256_encrypt_block_ecb(plaintext, &encryption_keys); + return aesni_AES256_encrypt_block_ECB(plaintext, &encryption_keys); } inline Block decrypt_ecb( const Block& ciphertext, const RoundKeys256& decryption_keys) { - return aesni_aes256_decrypt_block_ecb(ciphertext, &decryption_keys); + return aesni_AES256_decrypt_block_ECB(ciphertext, &decryption_keys); } inline Block encrypt_cbc( @@ -368,7 +368,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes256_encrypt_block_cbc(plaintext, &encryption_keys, iv, &next_iv); + return aesni_AES256_encrypt_block_CBC(plaintext, &encryption_keys, iv, &next_iv); } inline Block decrypt_cbc( @@ -377,7 +377,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes256_decrypt_block_cbc(ciphertext, &decryption_keys, iv, &next_iv); + return aesni_AES256_decrypt_block_CBC(ciphertext, &decryption_keys, iv, &next_iv); } inline Block encrypt_cfb( @@ -386,7 +386,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes256_encrypt_block_cfb(plaintext, &encryption_keys, iv, &next_iv); + return aesni_AES256_encrypt_block_CFB(plaintext, &encryption_keys, iv, &next_iv); } inline Block decrypt_cfb( @@ -395,7 +395,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes256_decrypt_block_cfb(ciphertext, &encryption_keys, iv, &next_iv); + return aesni_AES256_decrypt_block_CFB(ciphertext, &encryption_keys, iv, &next_iv); } inline Block encrypt_ofb( @@ -404,7 +404,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes256_encrypt_block_ofb(plaintext, &encryption_keys, iv, &next_iv); + return aesni_AES256_encrypt_block_OFB(plaintext, &encryption_keys, iv, &next_iv); } inline Block decrypt_ofb( @@ -413,7 +413,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes256_decrypt_block_ofb(ciphertext, &encryption_keys, iv, &next_iv); + return aesni_AES256_decrypt_block_OFB(ciphertext, &encryption_keys, iv, &next_iv); } inline Block encrypt_ctr( @@ -422,7 +422,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes256_encrypt_block_ctr(plaintext, &encryption_keys, iv, &next_iv); + return aesni_AES256_encrypt_block_CTR(plaintext, &encryption_keys, iv, &next_iv); } inline Block decrypt_ctr( @@ -431,7 +431,7 @@ namespace aesni const Block& iv, Block& next_iv) { - return aesni_aes256_decrypt_block_ctr(ciphertext, &encryption_keys, iv, &next_iv); + return aesni_AES256_decrypt_block_CTR(ciphertext, &encryption_keys, iv, &next_iv); } template <Algorithm> diff --git a/include/aesni/aes.h b/include/aesni/aes.h index 427ca85..ea859a3 100644 --- a/include/aesni/aes.h +++ b/include/aesni/aes.h @@ -19,276 +19,415 @@ extern "C" { #endif -typedef AesNI_Block128 AesNI_Aes_Block; +typedef AesNI_Block128 AesNI_AES_Block; +typedef AesNI_AES_Block AesNI_AES128_Block; +typedef AesNI_AES_Block AesNI_AES192_Block; +typedef AesNI_AES_Block AesNI_AES256_Block; typedef struct { - AesNI_Aes_Block key; + AesNI_AES_Block key; } -AesNI_Aes128_Key; +AesNI_AES128_Key; typedef struct { - AesNI_Aes_Block hi; - AesNI_Aes_Block lo; + AesNI_AES_Block hi; + AesNI_AES_Block lo; } -AesNI_Aes192_Key; +AesNI_AES192_Key; typedef struct { - AesNI_Aes_Block hi; - AesNI_Aes_Block lo; + AesNI_AES_Block hi; + AesNI_AES_Block lo; } -AesNI_Aes256_Key; +AesNI_AES256_Key; -static __inline void aesni_aes_make_block(AesNI_Aes_Block* dest, int hi3, int hi2, int lo1, int lo0) +static __inline void aesni_AES_make_block(AesNI_AES_Block* dest, int hi3, int hi2, int lo1, int lo0) { *dest = aesni_make_block128(hi3, hi2, lo1, lo0); } -static __inline void aesni_aes128_make_key(AesNI_Aes128_Key* dest, int hi3, int hi2, int lo1, int lo0) +static __inline void aesni_AES128_make_block(AesNI_AES128_Block* dest, int hi3, int hi2, int lo1, int lo0) { - dest->key = aesni_make_block128(hi3, hi2, lo1, lo0); + aesni_AES_make_block(dest, hi3, hi2, lo1, lo0); } -static __inline void aesni_aes192_make_key(AesNI_Aes192_Key* dest, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0) +static __inline void aesni_AES192_make_block(AesNI_AES192_Block* dest, int hi3, int hi2, int lo1, int lo0) { - dest->hi = aesni_make_block128(0, 0, hi5, hi4); - dest->lo = aesni_make_block128(lo3, lo2, lo1, lo0); + aesni_AES_make_block(dest, hi3, hi2, lo1, lo0); } -static __inline void aesni_aes256_make_key(AesNI_Aes256_Key* dest, int hi7, int hi6, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0) +static __inline void aesni_AES256_make_block(AesNI_AES256_Block* dest, int hi3, int hi2, int lo1, int lo0) { - dest->hi = aesni_make_block128(hi7, hi6, hi5, hi4); - dest->lo = aesni_make_block128(lo3, lo2, lo1, lo0); + aesni_AES_make_block(dest, hi3, hi2, lo1, lo0); } -typedef struct { char str[33]; } AesNI_Aes_BlockString; -typedef struct { char str[49]; } AesNI_Aes_BlockMatrixString; +static __inline void aesni_AES128_make_key(AesNI_AES128_Key* dest, int hi3, int hi2, int lo1, int lo0) +{ + aesni_AES_make_block(&dest->key, hi3, hi2, lo1, lo0); +} + +static __inline void aesni_AES192_make_key(AesNI_AES192_Key* dest, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0) +{ + aesni_AES_make_block(&dest->hi, 0, 0, hi5, hi4); + aesni_AES_make_block(&dest->lo, lo3, lo2, lo1, lo0); +} + +static __inline void aesni_AES256_make_key(AesNI_AES256_Key* dest, int hi7, int hi6, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0) +{ + aesni_AES_make_block(&dest->hi, hi7, hi6, hi5, hi4); + aesni_AES_make_block(&dest->lo, lo3, lo2, lo1, lo0); +} -AesNI_StatusCode aesni_aes_format_block( - AesNI_Aes_BlockString*, - const AesNI_Aes_Block*, +typedef struct { char str[33]; } AesNI_AES_BlockString; +typedef AesNI_AES_BlockString AesNI_AES128_BlockString; +typedef AesNI_AES_BlockString AesNI_AES192_BlockString; +typedef AesNI_AES_BlockString AesNI_AES256_BlockString; + +typedef struct { char str[49]; } AesNI_AES_BlockMatrixString; +typedef AesNI_AES_BlockMatrixString AesNI_AES128_BlockMatrixString; +typedef AesNI_AES_BlockMatrixString AesNI_AES192_BlockMatrixString; +typedef AesNI_AES_BlockMatrixString AesNI_AES256_BlockMatrixString; + +AesNI_StatusCode aesni_AES_format_block( + AesNI_AES_BlockString*, + const AesNI_AES_Block*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_aes_format_block_as_matrix( - AesNI_Aes_BlockMatrixString*, - const AesNI_Aes_Block*, +static __inline AesNI_StatusCode aesni_AES128_format_block( + AesNI_AES128_BlockString* dest, + const AesNI_AES128_Block* src, + AesNI_ErrorDetails* err_details) +{ + return aesni_AES_format_block(dest, src, err_details); +} + +static __inline AesNI_StatusCode aesni_AES192_format_block( + AesNI_AES192_BlockString* dest, + const AesNI_AES192_Block* src, + AesNI_ErrorDetails* err_details) +{ + return aesni_AES_format_block(dest, src, err_details); +} + +static __inline AesNI_StatusCode aesni_AES256_format_block( + AesNI_AES256_BlockString* dest, + const AesNI_AES256_Block* src, + AesNI_ErrorDetails* err_details) +{ + return aesni_AES_format_block(dest, src, err_details); +} + +AesNI_StatusCode aesni_AES_format_block_as_matrix( + AesNI_AES_BlockMatrixString*, + const AesNI_AES_Block*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_aes_print_block( - const AesNI_Aes_Block*, +static __inline AesNI_StatusCode aesni_AES128_format_block_as_matrix( + AesNI_AES128_BlockMatrixString* dest, + const AesNI_AES128_Block* src, + AesNI_ErrorDetails* err_details) +{ + return aesni_AES_format_block_as_matrix(dest, src, err_details); +} + +static __inline AesNI_StatusCode aesni_AES192_format_block_as_matrix( + AesNI_AES192_BlockMatrixString* dest, + const AesNI_AES192_Block* src, + AesNI_ErrorDetails* err_details) +{ + return aesni_AES_format_block_as_matrix(dest, src, err_details); +} + +static __inline AesNI_StatusCode aesni_AES256_format_block_as_matrix( + AesNI_AES256_BlockMatrixString* dest, + const AesNI_AES256_Block* src, + AesNI_ErrorDetails* err_details) +{ + return aesni_AES_format_block_as_matrix(dest, src, err_details); +} + +AesNI_StatusCode aesni_AES_print_block( + const AesNI_AES_Block*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_aes_print_block_as_matrix( - const AesNI_Aes_Block*, +static __inline AesNI_StatusCode aesni_AES128_print_block( + const AesNI_AES128_Block* block, + AesNI_ErrorDetails* err_details) +{ + return aesni_AES_print_block(block, err_details); +} + +static __inline AesNI_StatusCode aesni_AES192_print_block( + const AesNI_AES192_Block* block, + AesNI_ErrorDetails* err_details) +{ + return aesni_AES_print_block(block, err_details); +} + +static __inline AesNI_StatusCode aesni_AES256_print_block( + const AesNI_AES256_Block* block, + AesNI_ErrorDetails* err_details) +{ + return aesni_AES_print_block(block, err_details); +} + +AesNI_StatusCode aesni_AES_print_block_as_matrix( + const AesNI_AES_Block*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_aes_parse_block( - AesNI_Aes_Block* dest, +static __inline AesNI_StatusCode aesni_AES128_print_block_as_matrix( + const AesNI_AES128_Block* block, + AesNI_ErrorDetails* err_details) +{ + return aesni_AES_print_block_as_matrix(block, err_details); +} + +static __inline AesNI_StatusCode aesni_AES192_print_block_as_matrix( + const AesNI_AES192_Block* block, + AesNI_ErrorDetails* err_details) +{ + return aesni_AES_print_block_as_matrix(block, err_details); +} + +static __inline AesNI_StatusCode aesni_AES256_print_block_as_matrix( + const AesNI_AES256_Block* block, + AesNI_ErrorDetails* err_details) +{ + return aesni_AES_print_block_as_matrix(block, err_details); +} + +AesNI_StatusCode aesni_AES_parse_block( + AesNI_AES_Block* dest, const char* src, AesNI_ErrorDetails* err_details); -typedef AesNI_Aes_BlockString AesNI_Aes128_KeyString; -typedef struct { char str[49]; } AesNI_Aes192_KeyString; -typedef struct { char str[65]; } AesNI_Aes256_KeyString; +static __inline AesNI_StatusCode aesni_AES128_parse_block( + AesNI_AES128_Block* dest, + const char* src, + AesNI_ErrorDetails* err_details) +{ + return aesni_AES_parse_block(dest, src, err_details); +} + +static __inline AesNI_StatusCode aesni_AES192_parse_block( + AesNI_AES192_Block* dest, + const char* src, + AesNI_ErrorDetails* err_details) +{ + return aesni_AES_parse_block(dest, src, err_details); +} -AesNI_StatusCode aesni_aes128_format_key( - AesNI_Aes128_KeyString*, - const AesNI_Aes128_Key*, +static __inline AesNI_StatusCode aesni_AES256_parse_block( + AesNI_AES256_Block* dest, + const char* src, + AesNI_ErrorDetails* err_details) +{ + return aesni_AES_parse_block(dest, src, err_details); +} + +typedef struct { char str[33]; } AesNI_AES128_KeyString; +typedef struct { char str[49]; } AesNI_AES192_KeyString; +typedef struct { char str[65]; } AesNI_AES256_KeyString; + +AesNI_StatusCode aesni_AES128_format_key( + AesNI_AES128_KeyString*, + const AesNI_AES128_Key*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_aes192_format_key( - AesNI_Aes192_KeyString*, - const AesNI_Aes192_Key*, +AesNI_StatusCode aesni_AES192_format_key( + AesNI_AES192_KeyString*, + const AesNI_AES192_Key*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_aes256_format_key( - AesNI_Aes256_KeyString*, - const AesNI_Aes256_Key*, +AesNI_StatusCode aesni_AES256_format_key( + AesNI_AES256_KeyString*, + const AesNI_AES256_Key*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_aes128_print_key( - const AesNI_Aes128_Key*, +AesNI_StatusCode aesni_AES128_print_key( + const AesNI_AES128_Key*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_aes192_print_key( - const AesNI_Aes192_Key*, +AesNI_StatusCode aesni_AES192_print_key( + const AesNI_AES192_Key*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_aes256_print_key( - const AesNI_Aes256_Key*, +AesNI_StatusCode aesni_AES256_print_key( + const AesNI_AES256_Key*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_aes128_parse_key( - AesNI_Aes128_Key* dest, +AesNI_StatusCode aesni_AES128_parse_key( + AesNI_AES128_Key* dest, const char* src, AesNI_ErrorDetails* err_details); -AesNI_StatusCode aesni_aes192_parse_key( - AesNI_Aes192_Key* dest, +AesNI_StatusCode aesni_AES192_parse_key( + AesNI_AES192_Key* dest, const char* src, AesNI_ErrorDetails* err_details); -AesNI_StatusCode aesni_aes256_parse_key( - AesNI_Aes256_Key* dest, +AesNI_StatusCode aesni_AES256_parse_key( + AesNI_AES256_Key* dest, const char* src, AesNI_ErrorDetails* err_details); typedef struct { - AesNI_Aes_Block keys[11]; + AesNI_AES_Block keys[11]; } -AesNI_Aes128_RoundKeys; +AesNI_AES128_RoundKeys; typedef struct { - AesNI_Aes_Block keys[13]; + AesNI_AES_Block keys[13]; } -AesNI_Aes192_RoundKeys; +AesNI_AES192_RoundKeys; typedef struct { - AesNI_Aes_Block keys[15]; + AesNI_AES_Block keys[15]; } -AesNI_Aes256_RoundKeys; +AesNI_AES256_RoundKeys; -void __fastcall aesni_aes128_expand_key_( - AesNI_Aes_Block key, - AesNI_Aes128_RoundKeys* encryption_keys); +void __fastcall aesni_AES128_expand_key_( + AesNI_AES_Block key, + AesNI_AES128_RoundKeys* encryption_keys); -void __fastcall aesni_aes192_expand_key_( - AesNI_Aes_Block key_lo, - AesNI_Aes_Block key_hi, - AesNI_Aes192_RoundKeys* encryption_keys); +void __fastcall aesni_AES192_expand_key_( + AesNI_AES_Block key_lo, + AesNI_AES_Block key_hi, + AesNI_AES192_RoundKeys* encryption_keys); -void __fastcall aesni_aes256_expand_key_( - AesNI_Aes_Block key_lo, - AesNI_Aes_Block key_hi, - AesNI_Aes256_RoundKeys* encryption_keys); +void __fastcall aesni_AES256_expand_key_( + AesNI_AES_Block key_lo, + AesNI_AES_Block key_hi, + AesNI_AES256_RoundKeys* encryption_keys); -void __fastcall aesni_aes128_derive_decryption_keys_( - const AesNI_Aes128_RoundKeys* encryption_keys, - AesNI_Aes128_RoundKeys* decryption_keys); +void __fastcall aesni_AES128_derive_decryption_keys_( + const AesNI_AES128_RoundKeys* encryption_keys, + AesNI_AES128_RoundKeys* decryption_keys); -void __fastcall aesni_aes192_derive_decryption_keys_( - const AesNI_Aes192_RoundKeys* encryption_keys, - AesNI_Aes192_RoundKeys* decryption_keys); +void __fastcall aesni_AES192_derive_decryption_keys_( + const AesNI_AES192_RoundKeys* encryption_keys, + AesNI_AES192_RoundKeys* decryption_keys); -void __fastcall aesni_aes256_derive_decryption_keys_( - const AesNI_Aes256_RoundKeys* encryption_keys, - AesNI_Aes256_RoundKeys* decryption_keys); +void __fastcall aesni_AES256_derive_decryption_keys_( + const AesNI_AES256_RoundKeys* encryption_keys, + AesNI_AES256_RoundKeys* decryption_keys); -AesNI_Aes_Block __fastcall aesni_aes128_encrypt_block_( - AesNI_Aes_Block plaintext, - const AesNI_Aes128_RoundKeys*); +AesNI_AES_Block __fastcall aesni_AES128_encrypt_block_( + AesNI_AES_Block plaintext, + const AesNI_AES128_RoundKeys*); -AesNI_Aes_Block __fastcall aesni_aes192_encrypt_block_( - AesNI_Aes_Block plaintext, - const AesNI_Aes192_RoundKeys*); +AesNI_AES_Block __fastcall aesni_AES192_encrypt_block_( + AesNI_AES_Block plaintext, + const AesNI_AES192_RoundKeys*); -AesNI_Aes_Block __fastcall aesni_aes256_encrypt_block_( - AesNI_Aes_Block plaintext, - const AesNI_Aes256_RoundKeys*); +AesNI_AES_Block __fastcall aesni_AES256_encrypt_block_( + AesNI_AES_Block plaintext, + const AesNI_AES256_RoundKeys*); -AesNI_Aes_Block __fastcall aesni_aes128_decrypt_block_( - AesNI_Aes_Block ciphertext, - const AesNI_Aes128_RoundKeys*); +AesNI_AES_Block __fastcall aesni_AES128_decrypt_block_( + AesNI_AES_Block ciphertext, + const AesNI_AES128_RoundKeys*); -AesNI_Aes_Block __fastcall aesni_aes192_decrypt_block_( - AesNI_Aes_Block ciphertext, - const AesNI_Aes192_RoundKeys*); +AesNI_AES_Block __fastcall aesni_AES192_decrypt_block_( + AesNI_AES_Block ciphertext, + const AesNI_AES192_RoundKeys*); -AesNI_Aes_Block __fastcall aesni_aes256_decrypt_block_( - AesNI_Aes_Block ciphertext, - const AesNI_Aes256_RoundKeys*); +AesNI_AES_Block __fastcall aesni_AES256_decrypt_block_( + AesNI_AES_Block ciphertext, + const AesNI_AES256_RoundKeys*); -static __inline AesNI_Aes_Block __fastcall aesni_aes_xor_blocks( - AesNI_Aes_Block a, - AesNI_Aes_Block b) +static __inline AesNI_AES_Block __fastcall aesni_AES_xor_blocks( + AesNI_AES_Block a, + AesNI_AES_Block b) { return aesni_xor_block128(a, b); } -static __inline AesNI_Aes_Block __fastcall aesni_aes128_xor_blocks( - AesNI_Aes_Block a, - AesNI_Aes_Block b) +static __inline AesNI_AES_Block __fastcall aesni_AES128_xor_blocks( + AesNI_AES128_Block a, + AesNI_AES128_Block b) { - return aesni_aes_xor_blocks(a, b); + return aesni_AES_xor_blocks(a, b); } -static __inline AesNI_Aes_Block __fastcall aesni_aes192_xor_blocks( - AesNI_Aes_Block a, - AesNI_Aes_Block b) +static __inline AesNI_AES_Block __fastcall aesni_AES192_xor_blocks( + AesNI_AES192_Block a, + AesNI_AES192_Block b) { - return aesni_aes_xor_blocks(a, b); + return aesni_AES_xor_blocks(a, b); } -static __inline AesNI_Aes_Block __fastcall aesni_aes256_xor_blocks( - AesNI_Aes_Block a, - AesNI_Aes_Block b) +static __inline AesNI_AES_Block __fastcall aesni_AES256_xor_blocks( + AesNI_AES256_Block a, + AesNI_AES256_Block b) { - return aesni_aes_xor_blocks(a, b); + return aesni_AES_xor_blocks(a, b); } -static __inline AesNI_Aes_Block __fastcall aesni_aes_inc_block( - AesNI_Aes_Block block) +static __inline AesNI_AES_Block __fastcall aesni_AES_inc_block( + AesNI_AES_Block block) { block = aesni_reverse_byte_order_block128(block); block = aesni_inc_block128(block); return aesni_reverse_byte_order_block128(block); } -static __inline AesNI_Aes_Block __fastcall aesni_aes128_inc_block( - AesNI_Aes_Block block) +static __inline AesNI_AES_Block __fastcall aesni_AES128_inc_block( + AesNI_AES128_Block block) { - return aesni_aes_inc_block(block); + return aesni_AES_inc_block(block); } -static __inline AesNI_Aes_Block __fastcall aesni_aes192_inc_block( - AesNI_Aes_Block block) +static __inline AesNI_AES_Block __fastcall aesni_AES192_inc_block( + AesNI_AES192_Block block) { - return aesni_aes_inc_block(block); + return aesni_AES_inc_block(block); } -static __inline AesNI_Aes_Block __fastcall aesni_aes256_inc_block( - AesNI_Aes_Block block) +static __inline AesNI_AES_Block __fastcall aesni_AES256_inc_block( + AesNI_AES256_Block block) { - return aesni_aes_inc_block(block); + return aesni_AES_inc_block(block); } -AESNI_ENCRYPT_BLOCK_ECB(aes128, AesNI_Aes_Block, AesNI_Aes128_RoundKeys); -AESNI_DECRYPT_BLOCK_ECB(aes128, AesNI_Aes_Block, AesNI_Aes128_RoundKeys); -AESNI_ENCRYPT_BLOCK_CBC(aes128, AesNI_Aes_Block, AesNI_Aes128_RoundKeys); -AESNI_DECRYPT_BLOCK_CBC(aes128, AesNI_Aes_Block, AesNI_Aes128_RoundKeys); -AESNI_ENCRYPT_BLOCK_CFB(aes128, AesNI_Aes_Block, AesNI_Aes128_RoundKeys); -AESNI_DECRYPT_BLOCK_CFB(aes128, AesNI_Aes_Block, AesNI_Aes128_RoundKeys); -AESNI_ENCRYPT_BLOCK_OFB(aes128, AesNI_Aes_Block, AesNI_Aes128_RoundKeys); -AESNI_DECRYPT_BLOCK_OFB(aes128, AesNI_Aes_Block, AesNI_Aes128_RoundKeys); -AESNI_ENCRYPT_BLOCK_CTR(aes128, AesNI_Aes_Block, AesNI_Aes128_RoundKeys); -AESNI_DECRYPT_BLOCK_CTR(aes128, AesNI_Aes_Block, AesNI_Aes128_RoundKeys); - -AESNI_ENCRYPT_BLOCK_ECB(aes192, AesNI_Aes_Block, AesNI_Aes192_RoundKeys); -AESNI_DECRYPT_BLOCK_ECB(aes192, AesNI_Aes_Block, AesNI_Aes192_RoundKeys); -AESNI_ENCRYPT_BLOCK_CBC(aes192, AesNI_Aes_Block, AesNI_Aes192_RoundKeys); -AESNI_DECRYPT_BLOCK_CBC(aes192, AesNI_Aes_Block, AesNI_Aes192_RoundKeys); -AESNI_ENCRYPT_BLOCK_CFB(aes192, AesNI_Aes_Block, AesNI_Aes192_RoundKeys); -AESNI_DECRYPT_BLOCK_CFB(aes192, AesNI_Aes_Block, AesNI_Aes192_RoundKeys); -AESNI_ENCRYPT_BLOCK_OFB(aes192, AesNI_Aes_Block, AesNI_Aes192_RoundKeys); -AESNI_DECRYPT_BLOCK_OFB(aes192, AesNI_Aes_Block, AesNI_Aes192_RoundKeys); -AESNI_ENCRYPT_BLOCK_CTR(aes192, AesNI_Aes_Block, AesNI_Aes192_RoundKeys); -AESNI_DECRYPT_BLOCK_CTR(aes192, AesNI_Aes_Block, AesNI_Aes192_RoundKeys); - -AESNI_ENCRYPT_BLOCK_ECB(aes256, AesNI_Aes_Block, AesNI_Aes256_RoundKeys); -AESNI_DECRYPT_BLOCK_ECB(aes256, AesNI_Aes_Block, AesNI_Aes256_RoundKeys); -AESNI_ENCRYPT_BLOCK_CBC(aes256, AesNI_Aes_Block, AesNI_Aes256_RoundKeys); -AESNI_DECRYPT_BLOCK_CBC(aes256, AesNI_Aes_Block, AesNI_Aes256_RoundKeys); -AESNI_ENCRYPT_BLOCK_CFB(aes256, AesNI_Aes_Block, AesNI_Aes256_RoundKeys); -AESNI_DECRYPT_BLOCK_CFB(aes256, AesNI_Aes_Block, AesNI_Aes256_RoundKeys); -AESNI_ENCRYPT_BLOCK_OFB(aes256, AesNI_Aes_Block, AesNI_Aes256_RoundKeys); -AESNI_DECRYPT_BLOCK_OFB(aes256, AesNI_Aes_Block, AesNI_Aes256_RoundKeys); -AESNI_ENCRYPT_BLOCK_CTR(aes256, AesNI_Aes_Block, AesNI_Aes256_RoundKeys); -AESNI_DECRYPT_BLOCK_CTR(aes256, AesNI_Aes_Block, AesNI_Aes256_RoundKeys); +AESNI_ENCRYPT_BLOCK_ECB(AES128); +AESNI_DECRYPT_BLOCK_ECB(AES128); +AESNI_ENCRYPT_BLOCK_CBC(AES128); +AESNI_DECRYPT_BLOCK_CBC(AES128); +AESNI_ENCRYPT_BLOCK_CFB(AES128); +AESNI_DECRYPT_BLOCK_CFB(AES128); +AESNI_ENCRYPT_BLOCK_OFB(AES128); +AESNI_DECRYPT_BLOCK_OFB(AES128); +AESNI_ENCRYPT_BLOCK_CTR(AES128); +AESNI_DECRYPT_BLOCK_CTR(AES128); + +AESNI_ENCRYPT_BLOCK_ECB(AES192); +AESNI_DECRYPT_BLOCK_ECB(AES192); +AESNI_ENCRYPT_BLOCK_CBC(AES192); +AESNI_DECRYPT_BLOCK_CBC(AES192); +AESNI_ENCRYPT_BLOCK_CFB(AES192); +AESNI_DECRYPT_BLOCK_CFB(AES192); +AESNI_ENCRYPT_BLOCK_OFB(AES192); +AESNI_DECRYPT_BLOCK_OFB(AES192); +AESNI_ENCRYPT_BLOCK_CTR(AES192); +AESNI_DECRYPT_BLOCK_CTR(AES192); + +AESNI_ENCRYPT_BLOCK_ECB(AES256); +AESNI_DECRYPT_BLOCK_ECB(AES256); +AESNI_ENCRYPT_BLOCK_CBC(AES256); +AESNI_DECRYPT_BLOCK_CBC(AES256); +AESNI_ENCRYPT_BLOCK_CFB(AES256); +AESNI_DECRYPT_BLOCK_CFB(AES256); +AESNI_ENCRYPT_BLOCK_OFB(AES256); +AESNI_DECRYPT_BLOCK_OFB(AES256); +AESNI_ENCRYPT_BLOCK_CTR(AES256); +AESNI_DECRYPT_BLOCK_CTR(AES256); /** * \brief Expands an AES-128 key into 10 encryption round keys. @@ -296,13 +435,13 @@ AESNI_DECRYPT_BLOCK_CTR(aes256, AesNI_Aes_Block, AesNI_Aes256_RoundKeys); * \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 aesni_aes128_expand_key( - const AesNI_Aes128_Key* key, - AesNI_Aes128_RoundKeys* encryption_keys) +static __inline void __fastcall aesni_AES128_expand_key( + const AesNI_AES128_Key* key, + AesNI_AES128_RoundKeys* encryption_keys) { assert(encryption_keys); - aesni_aes128_expand_key_(key->key, encryption_keys); + aesni_AES128_expand_key_(key->key, encryption_keys); } /** @@ -311,14 +450,14 @@ static __inline void __fastcall aesni_aes128_expand_key( * \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 aesni_aes128_derive_decryption_keys( - const AesNI_Aes128_RoundKeys* encryption_keys, - AesNI_Aes128_RoundKeys* decryption_keys) +static __inline void __fastcall aesni_AES128_derive_decryption_keys( + const AesNI_AES128_RoundKeys* encryption_keys, + AesNI_AES128_RoundKeys* decryption_keys) { assert(encryption_keys); assert(decryption_keys); - aesni_aes128_derive_decryption_keys_(encryption_keys, decryption_keys); + aesni_AES128_derive_decryption_keys_(encryption_keys, decryption_keys); } /** @@ -327,14 +466,14 @@ static __inline void __fastcall aesni_aes128_derive_decryption_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 aesni_aes192_expand_key( - const AesNI_Aes192_Key* key, - AesNI_Aes192_RoundKeys* encryption_keys) +static __inline void __fastcall aesni_AES192_expand_key( + const AesNI_AES192_Key* key, + AesNI_AES192_RoundKeys* encryption_keys) { assert(key); assert(encryption_keys); - aesni_aes192_expand_key_(key->lo, key->hi, encryption_keys); + aesni_AES192_expand_key_(key->lo, key->hi, encryption_keys); } /** @@ -343,14 +482,14 @@ static __inline void __fastcall aesni_aes192_expand_key( * \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 aesni_aes192_derive_decryption_keys( - const AesNI_Aes192_RoundKeys* encryption_keys, - AesNI_Aes192_RoundKeys* decryption_keys) +static __inline void __fastcall aesni_AES192_derive_decryption_keys( + const AesNI_AES192_RoundKeys* encryption_keys, + AesNI_AES192_RoundKeys* decryption_keys) { assert(encryption_keys); assert(decryption_keys); - aesni_aes192_derive_decryption_keys_(encryption_keys, decryption_keys); + aesni_AES192_derive_decryption_keys_(encryption_keys, decryption_keys); } /** @@ -359,14 +498,14 @@ static __inline void __fastcall aesni_aes192_derive_decryption_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 aesni_aes256_expand_key( - const AesNI_Aes256_Key* key, - AesNI_Aes256_RoundKeys* encryption_keys) +static __inline void __fastcall aesni_AES256_expand_key( + const AesNI_AES256_Key* key, + AesNI_AES256_RoundKeys* encryption_keys) { assert(key); assert(encryption_keys); - aesni_aes256_expand_key_(key->lo, key->hi, encryption_keys); + aesni_AES256_expand_key_(key->lo, key->hi, encryption_keys); } /** @@ -375,14 +514,14 @@ static __inline void __fastcall aesni_aes256_expand_key( * \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 aesni_aes256_derive_decryption_keys( - const AesNI_Aes256_RoundKeys* encryption_keys, - AesNI_Aes256_RoundKeys* decryption_keys) +static __inline void __fastcall aesni_AES256_derive_decryption_keys( + const AesNI_AES256_RoundKeys* encryption_keys, + AesNI_AES256_RoundKeys* decryption_keys) { assert(encryption_keys); assert(decryption_keys); - aesni_aes256_derive_decryption_keys_(encryption_keys, decryption_keys); + aesni_AES256_derive_decryption_keys_(encryption_keys, decryption_keys); } #ifdef __cplusplus diff --git a/include/aesni/box_data.h b/include/aesni/box_data.h index ff36885..5d27641 100644 --- a/include/aesni/box_data.h +++ b/include/aesni/box_data.h @@ -21,31 +21,31 @@ extern "C" typedef union { - AesNI_Aes128_Key aes128_key; - AesNI_Aes192_Key aes192_key; - AesNI_Aes256_Key aes256_key; + AesNI_AES128_Key aes128_key; + AesNI_AES192_Key aes192_key; + AesNI_AES256_Key aes256_key; } AesNI_BoxAlgorithmParams; typedef union { - AesNI_Aes128_RoundKeys aes128_encryption_keys; - AesNI_Aes192_RoundKeys aes192_encryption_keys; - AesNI_Aes256_RoundKeys aes256_encryption_keys; + AesNI_AES128_RoundKeys aes128_encryption_keys; + AesNI_AES192_RoundKeys aes192_encryption_keys; + AesNI_AES256_RoundKeys aes256_encryption_keys; } AesNI_BoxEncryptionParams; typedef union { - AesNI_Aes128_RoundKeys aes128_decryption_keys; - AesNI_Aes192_RoundKeys aes192_decryption_keys; - AesNI_Aes256_RoundKeys aes256_decryption_keys; + AesNI_AES128_RoundKeys aes128_decryption_keys; + AesNI_AES192_RoundKeys aes192_decryption_keys; + AesNI_AES256_RoundKeys aes256_decryption_keys; } AesNI_BoxDecryptionParams; typedef union { - AesNI_Aes_Block aes_block; + AesNI_AES_Block aes_block; } AesNI_BoxBlock; diff --git a/include/aesni/mode.h b/include/aesni/mode.h index 831183c..81e6c5c 100644 --- a/include/aesni/mode.h +++ b/include/aesni/mode.h @@ -25,137 +25,137 @@ typedef enum } AesNI_Mode; -#define AESNI_ENCRYPT_BLOCK_ECB(prefix, BlockT, KeyT) \ -static __inline BlockT __fastcall aesni_## prefix ##_encrypt_block_ecb( \ - BlockT plaintext, \ - const KeyT* key) \ +#define AESNI_ENCRYPT_BLOCK_ECB(prefix) \ +static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_encrypt_block_ECB( \ + AesNI_## prefix ##_Block plaintext, \ + const AesNI_## prefix ##_RoundKeys* encryption_keys) \ { \ - assert(key); \ + assert(encryption_keys); \ \ - return aesni_## prefix ##_encrypt_block_(plaintext, key); \ + return aesni_## prefix ##_encrypt_block_(plaintext, encryption_keys); \ } -#define AESNI_DECRYPT_BLOCK_ECB(prefix, BlockT, KeyT) \ -static __inline BlockT __fastcall aesni_## prefix ##_decrypt_block_ecb( \ - BlockT ciphertext, \ - const KeyT* key) \ +#define AESNI_DECRYPT_BLOCK_ECB(prefix) \ +static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_decrypt_block_ECB( \ + AesNI_## prefix ##_Block ciphertext, \ + const AesNI_## prefix ##_RoundKeys* decryption_keys) \ { \ - assert(key); \ + assert(decryption_keys); \ \ - return aesni_## prefix ##_decrypt_block_(ciphertext, key); \ + return aesni_## prefix ##_decrypt_block_(ciphertext, decryption_keys); \ } -#define AESNI_ENCRYPT_BLOCK_CBC(prefix, BlockT, KeyT) \ -static __inline BlockT __fastcall aesni_## prefix ##_encrypt_block_cbc( \ - BlockT plaintext, \ - const KeyT* key, \ - BlockT init_vector, \ - BlockT* next_init_vector) \ +#define AESNI_ENCRYPT_BLOCK_CBC(prefix) \ +static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_encrypt_block_CBC( \ + AesNI_## prefix ##_Block plaintext, \ + const AesNI_## prefix ##_RoundKeys* encryption_keys, \ + AesNI_## prefix ##_Block init_vector, \ + AesNI_## prefix ##_Block* next_init_vector) \ { \ - assert(key); \ + assert(encryption_keys); \ assert(next_init_vector); \ \ - return *next_init_vector = aesni_## prefix ##_encrypt_block_ecb( \ - aesni_## prefix ##_xor_blocks(plaintext, init_vector), key); \ + return *next_init_vector = aesni_## prefix ##_encrypt_block_( \ + aesni_## prefix ##_xor_blocks(plaintext, init_vector), encryption_keys); \ } -#define AESNI_DECRYPT_BLOCK_CBC(prefix, BlockT, KeyT) \ -static __inline BlockT __fastcall aesni_## prefix ##_decrypt_block_cbc( \ - BlockT ciphertext, \ - const KeyT* key, \ - BlockT init_vector, \ - BlockT* next_init_vector) \ +#define AESNI_DECRYPT_BLOCK_CBC(prefix) \ +static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_decrypt_block_CBC( \ + AesNI_## prefix ##_Block ciphertext, \ + const AesNI_## prefix ##_RoundKeys* decryption_keys, \ + AesNI_## prefix ##_Block init_vector, \ + AesNI_## prefix ##_Block* next_init_vector) \ { \ - assert(key); \ + assert(decryption_keys); \ assert(next_init_vector); \ \ - BlockT plaintext = aesni_## prefix ##_xor_blocks( \ - aesni_## prefix ##_decrypt_block_ecb(ciphertext, key), init_vector); \ + AesNI_## prefix ##_Block plaintext = aesni_## prefix ##_xor_blocks( \ + aesni_## prefix ##_decrypt_block_(ciphertext, decryption_keys), init_vector); \ *next_init_vector = ciphertext; \ return plaintext; \ } -#define AESNI_ENCRYPT_BLOCK_CFB(prefix, BlockT, KeyT) \ -static __inline BlockT __fastcall aesni_## prefix ##_encrypt_block_cfb( \ - BlockT plaintext, \ - const KeyT* key, \ - BlockT init_vector, \ - BlockT* next_init_vector) \ +#define AESNI_ENCRYPT_BLOCK_CFB(prefix) \ +static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_encrypt_block_CFB( \ + AesNI_## prefix ##_Block plaintext, \ + const AesNI_## prefix ##_RoundKeys* encryption_keys, \ + AesNI_## prefix ##_Block init_vector, \ + AesNI_## prefix ##_Block* next_init_vector) \ { \ - assert(key); \ + assert(encryption_keys); \ assert(next_init_vector); \ \ return *next_init_vector = aesni_## prefix ##_xor_blocks( \ - aesni_## prefix ##_encrypt_block_ecb(init_vector, key), plaintext); \ + aesni_## prefix ##_encrypt_block_(init_vector, encryption_keys), plaintext); \ } -#define AESNI_DECRYPT_BLOCK_CFB(prefix, BlockT, KeyT) \ -static __inline BlockT __fastcall aesni_## prefix ##_decrypt_block_cfb( \ - BlockT ciphertext, \ - const KeyT* key, \ - BlockT init_vector, \ - BlockT* next_init_vector) \ +#define AESNI_DECRYPT_BLOCK_CFB(prefix) \ +static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_decrypt_block_CFB( \ + AesNI_## prefix ##_Block ciphertext, \ + const AesNI_## prefix ##_RoundKeys* encryption_keys, \ + AesNI_## prefix ##_Block init_vector, \ + AesNI_## prefix ##_Block* next_init_vector) \ { \ - assert(key); \ + assert(encryption_keys); \ assert(next_init_vector); \ \ - BlockT plaintext = aesni_## prefix ##_xor_blocks( \ - aesni_## prefix ##_encrypt_block_ecb(init_vector, key), ciphertext); \ + AesNI_## prefix ##_Block plaintext = aesni_## prefix ##_xor_blocks( \ + aesni_## prefix ##_encrypt_block_(init_vector, encryption_keys), ciphertext); \ *next_init_vector = ciphertext; \ return plaintext; \ } -#define AESNI_ENCRYPT_BLOCK_OFB(prefix, BlockT, KeyT) \ -static __inline BlockT __fastcall aesni_## prefix ##_encrypt_block_ofb( \ - BlockT plaintext, \ - const KeyT* key, \ - BlockT init_vector, \ - BlockT* next_init_vector) \ +#define AESNI_ENCRYPT_BLOCK_OFB(prefix) \ +static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_encrypt_block_OFB( \ + AesNI_## prefix ##_Block plaintext, \ + const AesNI_## prefix ##_RoundKeys* encryption_keys, \ + AesNI_## prefix ##_Block init_vector, \ + AesNI_## prefix ##_Block* next_init_vector) \ { \ - assert(key); \ + assert(encryption_keys); \ assert(next_init_vector); \ \ - BlockT tmp = aesni_## prefix ##_encrypt_block_ecb(init_vector, key); \ + AesNI_## prefix ##_Block tmp = aesni_## prefix ##_encrypt_block_(init_vector, encryption_keys); \ *next_init_vector = tmp; \ return aesni_## prefix ##_xor_blocks(tmp, plaintext); \ } -#define AESNI_DECRYPT_BLOCK_OFB(prefix, BlockT, KeyT) \ -static __inline BlockT __fastcall aesni_## prefix ##_decrypt_block_ofb( \ - BlockT ciphertext, \ - const KeyT* key, \ - BlockT init_vector, \ - BlockT* next_init_vector) \ +#define AESNI_DECRYPT_BLOCK_OFB(prefix) \ +static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_decrypt_block_OFB( \ + AesNI_## prefix ##_Block ciphertext, \ + const AesNI_## prefix ##_RoundKeys* encryption_keys, \ + AesNI_## prefix ##_Block init_vector, \ + AesNI_## prefix ##_Block* next_init_vector) \ { \ - return aesni_## prefix ##_encrypt_block_ofb( \ - ciphertext, key, init_vector, next_init_vector); \ + return aesni_## prefix ##_encrypt_block_OFB( \ + ciphertext, encryption_keys, init_vector, next_init_vector); \ } -#define AESNI_ENCRYPT_BLOCK_CTR(prefix, BlockT, KeyT) \ -static __inline BlockT __fastcall aesni_## prefix ##_encrypt_block_ctr( \ - BlockT plaintext, \ - const KeyT* key, \ - BlockT init_vector, \ - BlockT* next_init_vector) \ +#define AESNI_ENCRYPT_BLOCK_CTR(prefix) \ +static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_encrypt_block_CTR( \ + AesNI_## prefix ##_Block plaintext, \ + const AesNI_## prefix ##_RoundKeys* encryption_keys, \ + AesNI_## prefix ##_Block init_vector, \ + AesNI_## prefix ##_Block* next_init_vector) \ { \ - assert(key); \ + assert(encryption_keys); \ assert(next_init_vector); \ \ - BlockT ciphertext = aesni_## prefix ##_xor_blocks( \ - plaintext, aesni_## prefix ##_encrypt_block_ecb(init_vector, key)); \ + AesNI_## prefix ##_Block ciphertext = aesni_## prefix ##_xor_blocks( \ + plaintext, aesni_## prefix ##_encrypt_block_(init_vector, encryption_keys)); \ *next_init_vector = aesni_## prefix ##_inc_block(init_vector); \ return ciphertext; \ } -#define AESNI_DECRYPT_BLOCK_CTR(prefix, BlockT, KeyT) \ -static __inline BlockT __fastcall aesni_## prefix ##_decrypt_block_ctr( \ - BlockT ciphertext, \ - const KeyT* key, \ - BlockT init_vector, \ - BlockT* next_init_vector) \ +#define AESNI_DECRYPT_BLOCK_CTR(prefix) \ +static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_decrypt_block_CTR( \ + AesNI_## prefix ##_Block ciphertext, \ + const AesNI_## prefix ##_RoundKeys* encryption_keys, \ + AesNI_## prefix ##_Block init_vector, \ + AesNI_## prefix ##_Block* next_init_vector) \ { \ - return aesni_## prefix ##_encrypt_block_ctr( \ - ciphertext, key, init_vector, next_init_vector); \ + return aesni_## prefix ##_encrypt_block_CTR( \ + ciphertext, encryption_keys, init_vector, next_init_vector); \ } #ifdef __cplusplus @@ -12,9 +12,9 @@ #include <stdio.h> #include <string.h> -AesNI_StatusCode aesni_aes_format_block( - AesNI_Aes_BlockString* str, - const AesNI_Aes_Block* block, +AesNI_StatusCode aesni_AES_format_block( + AesNI_AES_BlockString* str, + const AesNI_AES_Block* block, AesNI_ErrorDetails* err_details) { assert(str); @@ -37,9 +37,9 @@ AesNI_StatusCode aesni_aes_format_block( return AESNI_SUCCESS; } -AesNI_StatusCode aesni_aes_format_block_as_matrix( - AesNI_Aes_BlockMatrixString* str, - const AesNI_Aes_Block* block, +AesNI_StatusCode aesni_AES_format_block_as_matrix( + AesNI_AES_BlockMatrixString* str, + const AesNI_AES_Block* block, AesNI_ErrorDetails* err_details) { assert(str); @@ -66,8 +66,8 @@ AesNI_StatusCode aesni_aes_format_block_as_matrix( return AESNI_SUCCESS; } -AesNI_StatusCode aesni_aes_print_block( - const AesNI_Aes_Block* block, +AesNI_StatusCode aesni_AES_print_block( + const AesNI_AES_Block* block, AesNI_ErrorDetails* err_details) { assert(block); @@ -76,17 +76,17 @@ AesNI_StatusCode aesni_aes_print_block( return aesni_error_null_argument(err_details, "block"); AesNI_StatusCode ec = AESNI_SUCCESS; - AesNI_Aes_BlockString str; + AesNI_AES_BlockString str; - if (aesni_is_error(ec = aesni_aes_format_block(&str, block, err_details))) + if (aesni_is_error(ec = aesni_AES_format_block(&str, block, err_details))) return ec; printf("%s\n", str.str); return ec; } -AesNI_StatusCode aesni_aes_print_block_as_matrix( - const AesNI_Aes_Block* block, +AesNI_StatusCode aesni_AES_print_block_as_matrix( + const AesNI_AES_Block* block, AesNI_ErrorDetails* err_details) { assert(block); @@ -95,17 +95,17 @@ AesNI_StatusCode aesni_aes_print_block_as_matrix( return aesni_error_null_argument(err_details, "block"); AesNI_StatusCode ec = AESNI_SUCCESS; - AesNI_Aes_BlockMatrixString str; + AesNI_AES_BlockMatrixString str; - if (aesni_is_error(ec = aesni_aes_format_block_as_matrix(&str, block, err_details))) + if (aesni_is_error(ec = aesni_AES_format_block_as_matrix(&str, block, err_details))) return ec; printf("%s", str.str); return ec; } -AesNI_StatusCode aesni_aes_parse_block( - AesNI_Aes_Block* dest, +AesNI_StatusCode aesni_AES_parse_block( + AesNI_AES_Block* dest, const char* src, AesNI_ErrorDetails* err_details) { @@ -135,17 +135,34 @@ AesNI_StatusCode aesni_aes_parse_block( return AESNI_SUCCESS; } -AesNI_StatusCode aesni_aes128_format_key( - AesNI_Aes128_KeyString* str, - const AesNI_Aes128_Key* key, +AesNI_StatusCode aesni_AES128_format_key( + AesNI_AES128_KeyString* str, + const AesNI_AES128_Key* key, AesNI_ErrorDetails* err_details) { - return aesni_aes_format_block(str, &key->key, err_details); + assert(str); + assert(key); + + if (str == NULL) + return aesni_error_null_argument(err_details, "str"); + if (key == NULL) + return aesni_error_null_argument(err_details, "key"); + + char* cursor = str->str; + + __declspec(align(16)) unsigned char bytes[16]; + aesni_store_block128_aligned(bytes, key->key); + + for (int i = 0; i < 16; ++i, cursor += 2) + sprintf(cursor, "%02x", bytes[i]); + + *cursor = '\0'; + return AESNI_SUCCESS; } -AesNI_StatusCode aesni_aes192_format_key( - AesNI_Aes192_KeyString* str, - const AesNI_Aes192_Key* key, +AesNI_StatusCode aesni_AES192_format_key( + AesNI_AES192_KeyString* str, + const AesNI_AES192_Key* key, AesNI_ErrorDetails* err_details) { assert(str); @@ -178,9 +195,9 @@ AesNI_StatusCode aesni_aes192_format_key( return AESNI_SUCCESS; } -AesNI_StatusCode aesni_aes256_format_key( - AesNI_Aes256_KeyString* str, - const AesNI_Aes256_Key* key, +AesNI_StatusCode aesni_AES256_format_key( + AesNI_AES256_KeyString* str, + const AesNI_AES256_Key* key, AesNI_ErrorDetails* err_details) { assert(str); @@ -213,15 +230,15 @@ AesNI_StatusCode aesni_aes256_format_key( return AESNI_SUCCESS; } -AesNI_StatusCode aesni_aes128_print_key( - const AesNI_Aes128_Key* key, +AesNI_StatusCode aesni_AES128_print_key( + const AesNI_AES128_Key* key, AesNI_ErrorDetails* err_details) { - return aesni_aes_print_block(&key->key, err_details); + return aesni_AES_print_block(&key->key, err_details); } -AesNI_StatusCode aesni_aes192_print_key( - const AesNI_Aes192_Key* key, +AesNI_StatusCode aesni_AES192_print_key( + const AesNI_AES192_Key* key, AesNI_ErrorDetails* err_details) { assert(key); @@ -230,17 +247,17 @@ AesNI_StatusCode aesni_aes192_print_key( return aesni_error_null_argument(err_details, "key"); AesNI_StatusCode ec = AESNI_SUCCESS; - AesNI_Aes192_KeyString str; + AesNI_AES192_KeyString str; - if (aesni_is_error(ec = aesni_aes192_format_key(&str, key, err_details))) + if (aesni_is_error(ec = aesni_AES192_format_key(&str, key, err_details))) return ec; printf("%s\n", str.str); return ec; } -AesNI_StatusCode aesni_aes256_print_key( - const AesNI_Aes256_Key* key, +AesNI_StatusCode aesni_AES256_print_key( + const AesNI_AES256_Key* key, AesNI_ErrorDetails* err_details) { assert(key); @@ -249,25 +266,25 @@ AesNI_StatusCode aesni_aes256_print_key( return aesni_error_null_argument(err_details, "key"); AesNI_StatusCode ec = AESNI_SUCCESS; - AesNI_Aes256_KeyString str; + AesNI_AES256_KeyString str; - if (aesni_is_error(ec = aesni_aes256_format_key(&str, key, err_details))) + if (aesni_is_error(ec = aesni_AES256_format_key(&str, key, err_details))) return ec; printf("%s\n", str.str); return ec; } -AesNI_StatusCode aesni_aes128_parse_key( - AesNI_Aes128_Key* dest, +AesNI_StatusCode aesni_AES128_parse_key( + AesNI_AES128_Key* dest, const char* src, AesNI_ErrorDetails* err_details) { - return aesni_aes_parse_block(&dest->key, src, err_details); + return aesni_AES_parse_block(&dest->key, src, err_details); } -AesNI_StatusCode aesni_aes192_parse_key( - AesNI_Aes192_Key* dest, +AesNI_StatusCode aesni_AES192_parse_key( + AesNI_AES192_Key* dest, const char* src, AesNI_ErrorDetails* err_details) { @@ -317,8 +334,8 @@ AesNI_StatusCode aesni_aes192_parse_key( return AESNI_SUCCESS; } -AesNI_StatusCode aesni_aes256_parse_key( - AesNI_Aes256_Key* dest, +AesNI_StatusCode aesni_AES256_parse_key( + AesNI_AES256_Key* dest, const char* src, AesNI_ErrorDetails* err_details) { diff --git a/src/asm/aes128.asm b/src/asm/aes128.asm index 70d2010..af9c839 100644 --- a/src/asm/aes128.asm +++ b/src/asm/aes128.asm @@ -8,7 +8,7 @@ .code -@aesni_aes128_encrypt_block_@20 proc +@aesni_AES128_encrypt_block_@20 proc pxor xmm0, [ecx] aesenc xmm0, [ecx + 10h] aesenc xmm0, [ecx + 20h] @@ -21,9 +21,9 @@ aesenc xmm0, [ecx + 90h] aesenclast xmm0, [ecx + 0A0h] ret -@aesni_aes128_encrypt_block_@20 endp +@aesni_AES128_encrypt_block_@20 endp -@aesni_aes128_decrypt_block_@20 proc +@aesni_AES128_decrypt_block_@20 proc pxor xmm0, [ecx] aesdec xmm0, [ecx + 10h] aesdec xmm0, [ecx + 20h] @@ -36,9 +36,9 @@ aesdec xmm0, [ecx + 90h] aesdeclast xmm0, [ecx + 0A0h] ret -@aesni_aes128_decrypt_block_@20 endp +@aesni_AES128_decrypt_block_@20 endp -@aesni_aes128_expand_key_@20 proc +@aesni_AES128_expand_key_@20 proc ; A "word" (in terms of the FIPS 187 standard) is a 32-bit block. ; Words are denoted by `w[N]`. ; @@ -165,9 +165,9 @@ aes128_keygen_assist: add ecx, 10h ; ecx = &w[i+8] ret -@aesni_aes128_expand_key_@20 endp +@aesni_AES128_expand_key_@20 endp -@aesni_aes128_derive_decryption_keys_@8 proc +@aesni_AES128_derive_decryption_keys_@8 proc movdqa xmm5, [ecx] movdqa xmm4, [ecx + 0A0h] movdqa [edx], xmm4 @@ -197,6 +197,6 @@ aes128_keygen_assist: movdqa [edx + 50h], xmm5 ret -@aesni_aes128_derive_decryption_keys_@8 endp +@aesni_AES128_derive_decryption_keys_@8 endp end diff --git a/src/asm/aes192.asm b/src/asm/aes192.asm index cd28143..05e4f08 100644 --- a/src/asm/aes192.asm +++ b/src/asm/aes192.asm @@ -8,7 +8,7 @@ .code -@aesni_aes192_encrypt_block_@20 proc +@aesni_AES192_encrypt_block_@20 proc pxor xmm0, [ecx] aesenc xmm0, [ecx + 10h] aesenc xmm0, [ecx + 20h] @@ -23,9 +23,9 @@ aesenc xmm0, [ecx + 0B0h] aesenclast xmm0, [ecx + 0C0h] ret -@aesni_aes192_encrypt_block_@20 endp +@aesni_AES192_encrypt_block_@20 endp -@aesni_aes192_decrypt_block_@20 proc +@aesni_AES192_decrypt_block_@20 proc pxor xmm0, [ecx] aesdec xmm0, [ecx + 10h] aesdec xmm0, [ecx + 20h] @@ -40,9 +40,9 @@ aesdec xmm0, [ecx + 0B0h] aesdeclast xmm0, [ecx + 0C0h] ret -@aesni_aes192_decrypt_block_@20 endp +@aesni_AES192_decrypt_block_@20 endp -@aesni_aes192_expand_key_@36 proc +@aesni_AES192_expand_key_@36 proc ; A "word" (in terms of the FIPS 187 standard) is a 32-bit block. ; Words are denoted by `w[N]`. ; @@ -206,9 +206,9 @@ aes192_keygen_assist: ; xmm1[31:0] == w[i+10] == RotWord(SubWord(w[i+5]))^Rcon^w[i+4]^w[i+3]^w[i+2]^w[i+1]^w[i] ret -@aesni_aes192_expand_key_@36 endp +@aesni_AES192_expand_key_@36 endp -@aesni_aes192_derive_decryption_keys_@8 proc +@aesni_AES192_derive_decryption_keys_@8 proc movdqa xmm5, [ecx] movdqa xmm4, [ecx + 0C0h] movdqa [edx], xmm4 @@ -243,6 +243,6 @@ aes192_keygen_assist: movdqa [edx + 60h], xmm5 ret -@aesni_aes192_derive_decryption_keys_@8 endp +@aesni_AES192_derive_decryption_keys_@8 endp end diff --git a/src/asm/aes256.asm b/src/asm/aes256.asm index 9f1e735..0d19c26 100644 --- a/src/asm/aes256.asm +++ b/src/asm/aes256.asm @@ -8,7 +8,7 @@ .code -@aesni_aes256_encrypt_block_@20 proc +@aesni_AES256_encrypt_block_@20 proc pxor xmm0, [ecx] aesenc xmm0, [ecx + 10h] aesenc xmm0, [ecx + 20h] @@ -25,9 +25,9 @@ aesenc xmm0, [ecx + 0D0h] aesenclast xmm0, [ecx + 0E0h] ret -@aesni_aes256_encrypt_block_@20 endp +@aesni_AES256_encrypt_block_@20 endp -@aesni_aes256_decrypt_block_@20 proc +@aesni_AES256_decrypt_block_@20 proc pxor xmm0, [ecx] aesdec xmm0, [ecx + 10h] aesdec xmm0, [ecx + 20h] @@ -44,9 +44,9 @@ aesdec xmm0, [ecx + 0D0h] aesdeclast xmm0, [ecx + 0E0h] ret -@aesni_aes256_decrypt_block_@20 endp +@aesni_AES256_decrypt_block_@20 endp -@aesni_aes256_expand_key_@36 proc +@aesni_AES256_expand_key_@36 proc ; A "word" (in terms of the FIPS 187 standard) is a 32-bit block. ; Words are denoted by `w[N]`. ; @@ -239,9 +239,9 @@ aes256_keygen_assist: pxor xmm0, xmm1 ret -@aesni_aes256_expand_key_@36 endp +@aesni_AES256_expand_key_@36 endp -@aesni_aes256_derive_decryption_keys_@8 proc +@aesni_AES256_derive_decryption_keys_@8 proc movdqa xmm5, [ecx] movdqa xmm4, [ecx + 0E0h] movdqa [edx], xmm4 @@ -281,6 +281,6 @@ aes256_keygen_assist: movdqa [edx + 70h], xmm5 ret -@aesni_aes256_derive_decryption_keys_@8 endp +@aesni_AES256_derive_decryption_keys_@8 endp end diff --git a/src/box_aes.c b/src/box_aes.c index 4e32aea..8642f31 100644 --- a/src/box_aes.c +++ b/src/box_aes.c @@ -17,10 +17,10 @@ static AesNI_StatusCode aesni_box_derive_params_aes128( AesNI_BoxDecryptionParams* decrypt_params, AesNI_ErrorDetails* err_details) { - aesni_aes128_expand_key_( + aesni_AES128_expand_key_( algorithm_params->aes128_key.key, &encrypt_params->aes128_encryption_keys); - aesni_aes128_derive_decryption_keys_( + aesni_AES128_derive_decryption_keys_( &encrypt_params->aes128_encryption_keys, &decrypt_params->aes128_decryption_keys); return AESNI_SUCCESS; @@ -32,11 +32,11 @@ static AesNI_StatusCode aesni_box_derive_params_aes192( AesNI_BoxDecryptionParams* decrypt_params, AesNI_ErrorDetails* err_details) { - aesni_aes192_expand_key_( + aesni_AES192_expand_key_( algorithm_params->aes192_key.lo, algorithm_params->aes192_key.hi, &encrypt_params->aes192_encryption_keys); - aesni_aes192_derive_decryption_keys_( + aesni_AES192_derive_decryption_keys_( &encrypt_params->aes192_encryption_keys, &decrypt_params->aes192_decryption_keys); return AESNI_SUCCESS; @@ -48,11 +48,11 @@ static AesNI_StatusCode aesni_box_derive_params_aes256( AesNI_BoxDecryptionParams* decrypt_params, AesNI_ErrorDetails* err_details) { - aesni_aes256_expand_key_( + aesni_AES256_expand_key_( algorithm_params->aes256_key.lo, algorithm_params->aes256_key.hi, &encrypt_params->aes256_encryption_keys); - aesni_aes256_derive_decryption_keys_( + aesni_AES256_derive_decryption_keys_( &encrypt_params->aes256_encryption_keys, &decrypt_params->aes256_decryption_keys); return AESNI_SUCCESS; @@ -63,7 +63,7 @@ static AesNI_StatusCode aesni_box_xor_block_aes( const AesNI_BoxBlock* src, AesNI_ErrorDetails* err_details) { - dest->aes_block = aesni_aes_xor_blocks(dest->aes_block, src->aes_block); + dest->aes_block = aesni_AES_xor_blocks(dest->aes_block, src->aes_block); return AESNI_SUCCESS; } @@ -71,7 +71,7 @@ static AesNI_StatusCode aesni_box_inc_block_aes( AesNI_BoxBlock* ctr, AesNI_ErrorDetails* err_details) { - ctr->aes_block = aesni_aes_inc_block(ctr->aes_block); + ctr->aes_block = aesni_AES_inc_block(ctr->aes_block); return AESNI_SUCCESS; } @@ -107,7 +107,7 @@ static AesNI_StatusCode aesni_box_encrypt_block_aes128( AesNI_BoxBlock* output, AesNI_ErrorDetails* err_details) { - output->aes_block = aesni_aes128_encrypt_block_( + output->aes_block = aesni_AES128_encrypt_block_( input->aes_block, ¶ms->aes128_encryption_keys); return AESNI_SUCCESS; @@ -119,7 +119,7 @@ static AesNI_StatusCode aesni_box_decrypt_block_aes128( AesNI_BoxBlock* output, AesNI_ErrorDetails* err_details) { - output->aes_block = aesni_aes128_decrypt_block_( + output->aes_block = aesni_AES128_decrypt_block_( input->aes_block, ¶ms->aes128_decryption_keys); return AESNI_SUCCESS; @@ -131,7 +131,7 @@ static AesNI_StatusCode aesni_box_encrypt_block_aes192( AesNI_BoxBlock* output, AesNI_ErrorDetails* err_details) { - output->aes_block = aesni_aes192_encrypt_block_( + output->aes_block = aesni_AES192_encrypt_block_( input->aes_block, ¶ms->aes192_encryption_keys); return AESNI_SUCCESS; @@ -143,7 +143,7 @@ static AesNI_StatusCode aesni_box_decrypt_block_aes192( AesNI_BoxBlock* output, AesNI_ErrorDetails* err_details) { - output->aes_block = aesni_aes192_decrypt_block_( + output->aes_block = aesni_AES192_decrypt_block_( input->aes_block, ¶ms->aes192_decryption_keys); return AESNI_SUCCESS; @@ -155,7 +155,7 @@ static AesNI_StatusCode aesni_box_encrypt_block_aes256( AesNI_BoxBlock* output, AesNI_ErrorDetails* err_details) { - output->aes_block = aesni_aes256_encrypt_block_( + output->aes_block = aesni_AES256_encrypt_block_( input->aes_block, ¶ms->aes256_encryption_keys); return AESNI_SUCCESS; @@ -167,7 +167,7 @@ static AesNI_StatusCode aesni_box_decrypt_block_aes256( AesNI_BoxBlock* output, AesNI_ErrorDetails* err_details) { - output->aes_block = aesni_aes256_decrypt_block_( + output->aes_block = aesni_AES256_decrypt_block_( input->aes_block, ¶ms->aes256_decryption_keys); return AESNI_SUCCESS; diff --git a/src/c/aes128.c b/src/c/aes128.c index b2e37ba..a99c8a7 100644 --- a/src/c/aes128.c +++ b/src/c/aes128.c @@ -11,9 +11,9 @@ #include <emmintrin.h> #include <wmmintrin.h> -AesNI_Aes_Block __fastcall aesni_aes128_encrypt_block_( - AesNI_Aes_Block plaintext, - const AesNI_Aes128_RoundKeys* encryption_keys) +AesNI_AES_Block __fastcall aesni_AES128_encrypt_block_( + AesNI_AES_Block plaintext, + const AesNI_AES128_RoundKeys* encryption_keys) { plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]); plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[1]); @@ -28,9 +28,9 @@ AesNI_Aes_Block __fastcall aesni_aes128_encrypt_block_( return _mm_aesenclast_si128(plaintext, encryption_keys->keys[10]); } -AesNI_Aes_Block __fastcall aesni_aes128_decrypt_block_( - AesNI_Aes_Block ciphertext, - const AesNI_Aes128_RoundKeys* decryption_keys) +AesNI_AES_Block __fastcall aesni_AES128_decrypt_block_( + AesNI_AES_Block ciphertext, + const AesNI_AES128_RoundKeys* decryption_keys) { ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]); ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[1]); @@ -45,11 +45,11 @@ AesNI_Aes_Block __fastcall aesni_aes128_decrypt_block_( return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[10]); } -static AesNI_Aes_Block __fastcall aesni_aes128_expand_key_assist( - AesNI_Aes_Block prev, - AesNI_Aes_Block hwgen) +static AesNI_AES_Block __fastcall aesni_aes128_expand_key_assist( + AesNI_AES_Block prev, + AesNI_AES_Block hwgen) { - AesNI_Aes_Block tmp = prev; + AesNI_AES_Block tmp = prev; tmp = _mm_slli_si128(tmp, 4); prev = _mm_xor_si128(prev, tmp); @@ -64,9 +64,9 @@ static AesNI_Aes_Block __fastcall aesni_aes128_expand_key_assist( return prev; } -void __fastcall aesni_aes128_expand_key_( - AesNI_Aes_Block key, - AesNI_Aes128_RoundKeys* encryption_keys) +void __fastcall aesni_AES128_expand_key_( + AesNI_AES_Block key, + AesNI_AES128_RoundKeys* encryption_keys) { AesNI_Block128 prev = encryption_keys->keys[0] = key; prev = encryption_keys->keys[1] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x01)); @@ -81,9 +81,9 @@ void __fastcall aesni_aes128_expand_key_( prev = encryption_keys->keys[10] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x36)); } -void __fastcall aesni_aes128_derive_decryption_keys_( - const AesNI_Aes128_RoundKeys* encryption_keys, - AesNI_Aes128_RoundKeys* decryption_keys) +void __fastcall aesni_AES128_derive_decryption_keys_( + const AesNI_AES128_RoundKeys* encryption_keys, + AesNI_AES128_RoundKeys* decryption_keys) { decryption_keys->keys[0] = encryption_keys->keys[10]; decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[9]); diff --git a/src/c/aes192.c b/src/c/aes192.c index 702ee5e..a8ae6cf 100644 --- a/src/c/aes192.c +++ b/src/c/aes192.c @@ -11,9 +11,9 @@ #include <emmintrin.h> #include <wmmintrin.h> -AesNI_Aes_Block __fastcall aesni_aes192_encrypt_block_( - AesNI_Aes_Block plaintext, - const AesNI_Aes192_RoundKeys* encryption_keys) +AesNI_AES_Block __fastcall aesni_AES192_encrypt_block_( + AesNI_AES_Block plaintext, + const AesNI_AES192_RoundKeys* encryption_keys) { plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]); plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[1]); @@ -30,9 +30,9 @@ AesNI_Aes_Block __fastcall aesni_aes192_encrypt_block_( return _mm_aesenclast_si128(plaintext, encryption_keys->keys[12]); } -AesNI_Aes_Block __fastcall aesni_aes192_decrypt_block_( - AesNI_Aes_Block ciphertext, - const AesNI_Aes192_RoundKeys* decryption_keys) +AesNI_AES_Block __fastcall aesni_AES192_decrypt_block_( + AesNI_AES_Block ciphertext, + const AesNI_AES192_RoundKeys* decryption_keys) { ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]); ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[1]); @@ -50,11 +50,11 @@ AesNI_Aes_Block __fastcall aesni_aes192_decrypt_block_( } static void __fastcall aesni_aes192_expand_key_assist( - AesNI_Aes_Block* prev_lo, - AesNI_Aes_Block* prev_hi, - AesNI_Aes_Block hwgen) + AesNI_AES_Block* prev_lo, + AesNI_AES_Block* prev_hi, + AesNI_AES_Block hwgen) { - AesNI_Aes_Block tmp = *prev_lo; + AesNI_AES_Block tmp = *prev_lo; tmp = _mm_slli_si128(tmp, 4); *prev_lo = _mm_xor_si128(*prev_lo, tmp); @@ -74,10 +74,10 @@ static void __fastcall aesni_aes192_expand_key_assist( *prev_hi = _mm_xor_si128(*prev_hi, tmp); } -void __fastcall aesni_aes192_expand_key_( - AesNI_Aes_Block key_lo, - AesNI_Aes_Block key_hi, - AesNI_Aes192_RoundKeys* encryption_keys) +void __fastcall aesni_AES192_expand_key_( + AesNI_AES_Block key_lo, + AesNI_AES_Block key_hi, + AesNI_AES192_RoundKeys* encryption_keys) { encryption_keys->keys[0] = key_lo; encryption_keys->keys[1] = key_hi; @@ -114,9 +114,9 @@ void __fastcall aesni_aes192_expand_key_( encryption_keys->keys[12] = key_lo; } -void __fastcall aesni_aes192_derive_decryption_keys_( - const AesNI_Aes192_RoundKeys* encryption_keys, - AesNI_Aes192_RoundKeys* decryption_keys) +void __fastcall aesni_AES192_derive_decryption_keys_( + const AesNI_AES192_RoundKeys* encryption_keys, + AesNI_AES192_RoundKeys* decryption_keys) { decryption_keys->keys[0] = encryption_keys->keys[12]; decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[11]); diff --git a/src/c/aes256.c b/src/c/aes256.c index 243ec03..6099204 100644 --- a/src/c/aes256.c +++ b/src/c/aes256.c @@ -11,9 +11,9 @@ #include <emmintrin.h> #include <wmmintrin.h> -AesNI_Aes_Block __fastcall aesni_aes256_encrypt_block_( - AesNI_Aes_Block plaintext, - const AesNI_Aes256_RoundKeys* encryption_keys) +AesNI_AES_Block __fastcall aesni_AES256_encrypt_block_( + AesNI_AES_Block plaintext, + const AesNI_AES256_RoundKeys* encryption_keys) { plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]); plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[1]); @@ -32,9 +32,9 @@ AesNI_Aes_Block __fastcall aesni_aes256_encrypt_block_( return _mm_aesenclast_si128(plaintext, encryption_keys->keys[14]); } -AesNI_Aes_Block __fastcall aesni_aes256_decrypt_block_( - AesNI_Aes_Block ciphertext, - const AesNI_Aes256_RoundKeys* decryption_keys) +AesNI_AES_Block __fastcall aesni_AES256_decrypt_block_( + AesNI_AES_Block ciphertext, + const AesNI_AES256_RoundKeys* decryption_keys) { ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]); ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[1]); @@ -53,12 +53,12 @@ AesNI_Aes_Block __fastcall aesni_aes256_decrypt_block_( return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[14]); } -static AesNI_Aes_Block __fastcall aesni_aes256_expand_key_assist( - AesNI_Aes_Block* prev_lo, - AesNI_Aes_Block* prev_hi, - AesNI_Aes_Block hwgen) +static AesNI_AES_Block __fastcall aesni_aes256_expand_key_assist( + AesNI_AES_Block* prev_lo, + AesNI_AES_Block* prev_hi, + AesNI_AES_Block hwgen) { - AesNI_Aes_Block tmp = *prev_lo; + AesNI_AES_Block tmp = *prev_lo; tmp = _mm_slli_si128(tmp, 4); *prev_lo = _mm_xor_si128(*prev_lo, tmp); @@ -76,13 +76,13 @@ static AesNI_Aes_Block __fastcall aesni_aes256_expand_key_assist( return *prev_hi; } -void __fastcall aesni_aes256_expand_key_( - AesNI_Aes_Block key_lo, - AesNI_Aes_Block key_hi, - AesNI_Aes256_RoundKeys* encryption_keys) +void __fastcall aesni_AES256_expand_key_( + AesNI_AES_Block key_lo, + AesNI_AES_Block key_hi, + AesNI_AES256_RoundKeys* encryption_keys) { - AesNI_Aes_Block prev_lo, prev_hi; - AesNI_Aes_Block hwgen; + AesNI_AES_Block prev_lo, prev_hi; + AesNI_AES_Block hwgen; prev_lo = encryption_keys->keys[0] = key_lo; prev_hi = encryption_keys->keys[1] = key_hi; @@ -140,9 +140,9 @@ void __fastcall aesni_aes256_expand_key_( encryption_keys->keys[14] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); } -void __fastcall aesni_aes256_derive_decryption_keys_( - const AesNI_Aes256_RoundKeys* encryption_keys, - AesNI_Aes256_RoundKeys* decryption_keys) +void __fastcall aesni_AES256_derive_decryption_keys_( + const AesNI_AES256_RoundKeys* encryption_keys, + AesNI_AES256_RoundKeys* decryption_keys) { decryption_keys->keys[0] = encryption_keys->keys[14]; decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[13]); |