From f2c9b2934b9be0f93105c411f5dbea564800fc3f Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 20 Jul 2026 21:32:29 +0200 Subject: remove a few levels of stupid indirection --- aesxx/include/aesxx/aes.hpp | 142 +++++++++++++++++++++---------------------- aesxx/include/aesxx/data.hpp | 18 +++--- aesxx/include/aesxx/mode.hpp | 140 +++++++++++++++++++++--------------------- 3 files changed, 150 insertions(+), 150 deletions(-) (limited to 'aesxx/include') diff --git a/aesxx/include/aesxx/aes.hpp b/aesxx/include/aesxx/aes.hpp index 1b5aefa..6271b24 100644 --- a/aesxx/include/aesxx/aes.hpp +++ b/aesxx/include/aesxx/aes.hpp @@ -19,9 +19,9 @@ namespace aes { namespace aes128 { -typedef AES_AES128_Block Block; -typedef AES_AES128_RoundKeys RoundKeys; -typedef AES_AES128_Key Key; +typedef AES_Block Block; +typedef AES128_RoundKeys RoundKeys; +typedef AES128_Key Key; } // namespace aes128 @@ -34,38 +34,38 @@ struct Types { template <> inline void from_string(aes128::Block& dest, std::string_view src) { - aes_AES128_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); + aes128_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); } template <> inline std::string to_string(const aes128::Block& src) { - AES_AES128_BlockString str; - aes_AES128_format_block(&str, &src, ErrorDetailsThrowsInDestructor{}); + AES128_BlockString str; + aes128_format_block(&str, &src, ErrorDetailsThrowsInDestructor{}); return {str.str}; } template <> inline std::string to_matrix_string(const aes128::Block& src) { - AES_AES128_BlockMatrixString str; - aes_AES128_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{}); + AES128_BlockMatrixString str; + aes128_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{}); return {str.str}; } template <> inline void from_string(aes128::Key& dest, std::string_view src) { - aes_AES128_parse_key(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); + aes128_parse_key(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); } template <> inline std::string to_string(const aes128::Key& src) { - AES_AES128_KeyString str; - aes_AES128_format_key(&str, &src, ErrorDetailsThrowsInDestructor{}); + AES128_KeyString str; + aes128_format_key(&str, &src, ErrorDetailsThrowsInDestructor{}); return {str.str}; } template <> inline void expand_key(const aes128::Key& key, aes128::RoundKeys& encryption_keys) { - aes_AES128_expand_key(&key, &encryption_keys); + aes128_expand_key(&key, &encryption_keys); } template <> @@ -73,25 +73,25 @@ inline void derive_decryption_keys( const aes128::RoundKeys& encryption_keys, aes128::RoundKeys& decryption_keys ) { - aes_AES128_derive_decryption_keys(&encryption_keys, &decryption_keys); + aes128_derive_decryption_keys(&encryption_keys, &decryption_keys); } -AESXX_ENCRYPT_BLOCK_ECB(AES128); -AESXX_DECRYPT_BLOCK_ECB(AES128); -AESXX_ENCRYPT_BLOCK_CBC(AES128); -AESXX_DECRYPT_BLOCK_CBC(AES128); -AESXX_ENCRYPT_BLOCK_CFB(AES128); -AESXX_DECRYPT_BLOCK_CFB(AES128); -AESXX_ENCRYPT_BLOCK_OFB(AES128); -AESXX_DECRYPT_BLOCK_OFB(AES128); -AESXX_ENCRYPT_BLOCK_CTR(AES128); -AESXX_DECRYPT_BLOCK_CTR(AES128); +AESXX_ENCRYPT_BLOCK_ECB(128); +AESXX_DECRYPT_BLOCK_ECB(128); +AESXX_ENCRYPT_BLOCK_CBC(128); +AESXX_DECRYPT_BLOCK_CBC(128); +AESXX_ENCRYPT_BLOCK_CFB(128); +AESXX_DECRYPT_BLOCK_CFB(128); +AESXX_ENCRYPT_BLOCK_OFB(128); +AESXX_DECRYPT_BLOCK_OFB(128); +AESXX_ENCRYPT_BLOCK_CTR(128); +AESXX_DECRYPT_BLOCK_CTR(128); namespace aes192 { -typedef AES_AES192_Block Block; -typedef AES_AES192_RoundKeys RoundKeys; -typedef AES_AES192_Key Key; +typedef AES_Block Block; +typedef AES192_RoundKeys RoundKeys; +typedef AES192_Key Key; } // namespace aes192 @@ -104,38 +104,38 @@ struct Types { template <> inline void from_string(aes192::Block& dest, std::string_view src) { - aes_AES192_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); + aes192_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); } template <> inline std::string to_string(const aes192::Block& src) { - AES_AES192_BlockString str; - aes_AES192_format_block(&str, &src, ErrorDetailsThrowsInDestructor{}); + AES192_BlockString str; + aes192_format_block(&str, &src, ErrorDetailsThrowsInDestructor{}); return {str.str}; } template <> inline std::string to_matrix_string(const aes192::Block& src) { - AES_AES192_BlockMatrixString str; - aes_AES192_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{}); + AES192_BlockMatrixString str; + aes192_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{}); return {str.str}; } template <> inline void from_string(aes192::Key& dest, std::string_view src) { - aes_AES192_parse_key(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); + aes192_parse_key(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); } template <> inline std::string to_string(const aes192::Key& src) { - AES_AES192_KeyString str; - aes_AES192_format_key(&str, &src, ErrorDetailsThrowsInDestructor{}); + AES192_KeyString str; + aes192_format_key(&str, &src, ErrorDetailsThrowsInDestructor{}); return {str.str}; } template <> inline void expand_key(const aes192::Key& key, aes192::RoundKeys& encryption_keys) { - aes_AES192_expand_key(&key, &encryption_keys); + aes192_expand_key(&key, &encryption_keys); } template <> @@ -143,25 +143,25 @@ inline void derive_decryption_keys( const aes192::RoundKeys& encryption_keys, aes192::RoundKeys& decryption_keys ) { - aes_AES192_derive_decryption_keys(&encryption_keys, &decryption_keys); + aes192_derive_decryption_keys(&encryption_keys, &decryption_keys); } -AESXX_ENCRYPT_BLOCK_ECB(AES192); -AESXX_DECRYPT_BLOCK_ECB(AES192); -AESXX_ENCRYPT_BLOCK_CBC(AES192); -AESXX_DECRYPT_BLOCK_CBC(AES192); -AESXX_ENCRYPT_BLOCK_CFB(AES192); -AESXX_DECRYPT_BLOCK_CFB(AES192); -AESXX_ENCRYPT_BLOCK_OFB(AES192); -AESXX_DECRYPT_BLOCK_OFB(AES192); -AESXX_ENCRYPT_BLOCK_CTR(AES192); -AESXX_DECRYPT_BLOCK_CTR(AES192); +AESXX_ENCRYPT_BLOCK_ECB(192); +AESXX_DECRYPT_BLOCK_ECB(192); +AESXX_ENCRYPT_BLOCK_CBC(192); +AESXX_DECRYPT_BLOCK_CBC(192); +AESXX_ENCRYPT_BLOCK_CFB(192); +AESXX_DECRYPT_BLOCK_CFB(192); +AESXX_ENCRYPT_BLOCK_OFB(192); +AESXX_DECRYPT_BLOCK_OFB(192); +AESXX_ENCRYPT_BLOCK_CTR(192); +AESXX_DECRYPT_BLOCK_CTR(192); namespace aes256 { -typedef AES_AES256_Block Block; -typedef AES_AES256_RoundKeys RoundKeys; -typedef AES_AES256_Key Key; +typedef AES_Block Block; +typedef AES256_RoundKeys RoundKeys; +typedef AES256_Key Key; } // namespace aes256 @@ -174,38 +174,38 @@ struct Types { template <> inline void from_string(aes256::Block& dest, std::string_view src) { - aes_AES256_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); + aes256_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); } template <> inline std::string to_string(const aes256::Block& src) { - AES_AES256_BlockString str; - aes_AES256_format_block(&str, &src, ErrorDetailsThrowsInDestructor{}); + AES256_BlockString str; + aes256_format_block(&str, &src, ErrorDetailsThrowsInDestructor{}); return {str.str}; } template <> inline std::string to_matrix_string(const aes256::Block& src) { - AES_AES256_BlockMatrixString str; - aes_AES256_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{}); + AES256_BlockMatrixString str; + aes256_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{}); return {str.str}; } template <> inline void from_string(aes256::Key& dest, std::string_view src) { - aes_AES256_parse_key(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); + aes256_parse_key(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); } template <> inline std::string to_string(const aes256::Key& src) { - AES_AES256_KeyString str; - aes_AES256_format_key(&str, &src, ErrorDetailsThrowsInDestructor{}); + AES256_KeyString str; + aes256_format_key(&str, &src, ErrorDetailsThrowsInDestructor{}); return {str.str}; } template <> inline void expand_key(const aes256::Key& key, aes256::RoundKeys& encryption_keys) { - aes_AES256_expand_key(&key, &encryption_keys); + aes256_expand_key(&key, &encryption_keys); } template <> @@ -213,18 +213,18 @@ inline void derive_decryption_keys( const aes256::RoundKeys& encryption_keys, aes256::RoundKeys& decryption_keys ) { - aes_AES256_derive_decryption_keys(&encryption_keys, &decryption_keys); -} - -AESXX_ENCRYPT_BLOCK_ECB(AES256); -AESXX_DECRYPT_BLOCK_ECB(AES256); -AESXX_ENCRYPT_BLOCK_CBC(AES256); -AESXX_DECRYPT_BLOCK_CBC(AES256); -AESXX_ENCRYPT_BLOCK_CFB(AES256); -AESXX_DECRYPT_BLOCK_CFB(AES256); -AESXX_ENCRYPT_BLOCK_OFB(AES256); -AESXX_DECRYPT_BLOCK_OFB(AES256); -AESXX_ENCRYPT_BLOCK_CTR(AES256); -AESXX_DECRYPT_BLOCK_CTR(AES256); + aes256_derive_decryption_keys(&encryption_keys, &decryption_keys); +} + +AESXX_ENCRYPT_BLOCK_ECB(256); +AESXX_DECRYPT_BLOCK_ECB(256); +AESXX_ENCRYPT_BLOCK_CBC(256); +AESXX_DECRYPT_BLOCK_CBC(256); +AESXX_ENCRYPT_BLOCK_CFB(256); +AESXX_DECRYPT_BLOCK_CFB(256); +AESXX_ENCRYPT_BLOCK_OFB(256); +AESXX_DECRYPT_BLOCK_OFB(256); +AESXX_ENCRYPT_BLOCK_CTR(256); +AESXX_DECRYPT_BLOCK_CTR(256); } // namespace aes diff --git a/aesxx/include/aesxx/data.hpp b/aesxx/include/aesxx/data.hpp index e381995..a93a781 100644 --- a/aesxx/include/aesxx/data.hpp +++ b/aesxx/include/aesxx/data.hpp @@ -11,38 +11,38 @@ namespace aes { -typedef AES_Block128 Block128; +typedef AES_Block Block128; inline void make_block(Block128& dest, int hi3, int hi2, int lo1, int lo0) { - dest = aes_make_block128(hi3, hi2, lo1, lo0); + dest = aes_make_block(hi3, hi2, lo1, lo0); } inline void load_block(Block128& dest, const void* src) { - dest = aes_load_block128(src); + dest = aes_load_block(src); } inline void load_block_aligned(Block128& dest, const void* src) { - dest = aes_load_block128_aligned(src); + dest = aes_load_block_aligned(src); } inline void store_block(void* dest, Block128& src) { - aes_store_block128(dest, src); + aes_store_block(dest, src); } inline void store_block_aligned(void* dest, Block128& src) { - aes_store_block128_aligned(dest, src); + aes_store_block_aligned(dest, src); } inline Block128 xor_blocks(Block128& a, Block128& b) { - return aes_xor_block128(a, b); + return aes_xor_blocks(a, b); } inline Block128 reverse_byte_order(Block128& block) { - return aes_reverse_byte_order_block128(block); + return aes_reverse_byte_order_block(block); } inline Block128 inc_block(Block128& block) { - return aes_inc_block128(block); + return aes_inc_block(block); } } // namespace aes diff --git a/aesxx/include/aesxx/mode.hpp b/aesxx/include/aesxx/mode.hpp index 9fbcaae..d6f282a 100644 --- a/aesxx/include/aesxx/mode.hpp +++ b/aesxx/include/aesxx/mode.hpp @@ -21,114 +21,114 @@ inline constexpr bool mode_uses_encryption_keys_only(Mode mode) { return mode != AES_ECB && mode != AES_CBC; } -#define AESXX_ENCRYPT_BLOCK_ECB(prefix) \ +#define AESXX_ENCRYPT_BLOCK_ECB(version) \ template <> \ - inline void encrypt_block( \ - const typename Types::Block& plaintext, \ - const typename Types::RoundKeys& encryption_keys, \ - typename Types::Block&, \ - typename Types::Block& ciphertext \ + inline void encrypt_block( \ + const typename Types::Block& plaintext, \ + const typename Types::RoundKeys& encryption_keys, \ + typename Types::Block&, \ + typename Types::Block& ciphertext \ ) { \ - ciphertext = aes_##prefix##_encrypt_block_ECB(plaintext, &encryption_keys); \ + ciphertext = aes##version##_encrypt_block_ECB(plaintext, &encryption_keys); \ } -#define AESXX_DECRYPT_BLOCK_ECB(prefix) \ +#define AESXX_DECRYPT_BLOCK_ECB(version) \ template <> \ - inline void decrypt_block( \ - const typename Types::Block& ciphertext, \ - const typename Types::RoundKeys& decryption_keys, \ - typename Types::Block&, \ - typename Types::Block& plaintext \ + inline void decrypt_block( \ + const typename Types::Block& ciphertext, \ + const typename Types::RoundKeys& decryption_keys, \ + typename Types::Block&, \ + typename Types::Block& plaintext \ ) { \ - plaintext = aes_##prefix##_decrypt_block_ECB(ciphertext, &decryption_keys); \ + plaintext = aes##version##_decrypt_block_ECB(ciphertext, &decryption_keys); \ } -#define AESXX_ENCRYPT_BLOCK_CBC(prefix) \ +#define AESXX_ENCRYPT_BLOCK_CBC(version) \ template <> \ - inline void encrypt_block( \ - const typename Types::Block& plaintext, \ - const typename Types::RoundKeys& encryption_keys, \ - typename Types::Block& iv, \ - typename Types::Block& ciphertext \ + inline void encrypt_block( \ + const typename Types::Block& plaintext, \ + const typename Types::RoundKeys& encryption_keys, \ + typename Types::Block& iv, \ + typename Types::Block& ciphertext \ ) { \ - ciphertext = aes_##prefix##_encrypt_block_CBC(plaintext, &encryption_keys, iv, &iv); \ + ciphertext = aes##version##_encrypt_block_CBC(plaintext, &encryption_keys, iv, &iv); \ } -#define AESXX_DECRYPT_BLOCK_CBC(prefix) \ +#define AESXX_DECRYPT_BLOCK_CBC(version) \ template <> \ - inline void decrypt_block( \ - const typename Types::Block& ciphertext, \ - const typename Types::RoundKeys& decryption_keys, \ - typename Types::Block& iv, \ - typename Types::Block& plaintext \ + inline void decrypt_block( \ + const typename Types::Block& ciphertext, \ + const typename Types::RoundKeys& decryption_keys, \ + typename Types::Block& iv, \ + typename Types::Block& plaintext \ ) { \ - plaintext = aes_##prefix##_decrypt_block_CBC(ciphertext, &decryption_keys, iv, &iv); \ + plaintext = aes##version##_decrypt_block_CBC(ciphertext, &decryption_keys, iv, &iv); \ } -#define AESXX_ENCRYPT_BLOCK_CFB(prefix) \ +#define AESXX_ENCRYPT_BLOCK_CFB(version) \ template <> \ - inline void encrypt_block( \ - const typename Types::Block& plaintext, \ - const typename Types::RoundKeys& encryption_keys, \ - typename Types::Block& iv, \ - typename Types::Block& ciphertext \ + inline void encrypt_block( \ + const typename Types::Block& plaintext, \ + const typename Types::RoundKeys& encryption_keys, \ + typename Types::Block& iv, \ + typename Types::Block& ciphertext \ ) { \ - ciphertext = aes_##prefix##_encrypt_block_CFB(plaintext, &encryption_keys, iv, &iv); \ + ciphertext = aes##version##_encrypt_block_CFB(plaintext, &encryption_keys, iv, &iv); \ } -#define AESXX_DECRYPT_BLOCK_CFB(prefix) \ +#define AESXX_DECRYPT_BLOCK_CFB(version) \ template <> \ - inline void decrypt_block( \ - const typename Types::Block& ciphertext, \ - const typename Types::RoundKeys& encryption_keys, \ - typename Types::Block& iv, \ - typename Types::Block& plaintext \ + inline void decrypt_block( \ + const typename Types::Block& ciphertext, \ + const typename Types::RoundKeys& encryption_keys, \ + typename Types::Block& iv, \ + typename Types::Block& plaintext \ ) { \ - plaintext = aes_##prefix##_decrypt_block_CFB(ciphertext, &encryption_keys, iv, &iv); \ + plaintext = aes##version##_decrypt_block_CFB(ciphertext, &encryption_keys, iv, &iv); \ } -#define AESXX_ENCRYPT_BLOCK_OFB(prefix) \ +#define AESXX_ENCRYPT_BLOCK_OFB(version) \ template <> \ - inline void encrypt_block( \ - const typename Types::Block& plaintext, \ - const typename Types::RoundKeys& encryption_keys, \ - typename Types::Block& iv, \ - typename Types::Block& ciphertext \ + inline void encrypt_block( \ + const typename Types::Block& plaintext, \ + const typename Types::RoundKeys& encryption_keys, \ + typename Types::Block& iv, \ + typename Types::Block& ciphertext \ ) { \ - ciphertext = aes_##prefix##_encrypt_block_OFB(plaintext, &encryption_keys, iv, &iv); \ + ciphertext = aes##version##_encrypt_block_OFB(plaintext, &encryption_keys, iv, &iv); \ } -#define AESXX_DECRYPT_BLOCK_OFB(prefix) \ +#define AESXX_DECRYPT_BLOCK_OFB(version) \ template <> \ - inline void decrypt_block( \ - const typename Types::Block& ciphertext, \ - const typename Types::RoundKeys& encryption_keys, \ - typename Types::Block& iv, \ - typename Types::Block& plaintext \ + inline void decrypt_block( \ + const typename Types::Block& ciphertext, \ + const typename Types::RoundKeys& encryption_keys, \ + typename Types::Block& iv, \ + typename Types::Block& plaintext \ ) { \ - plaintext = aes_##prefix##_decrypt_block_OFB(ciphertext, &encryption_keys, iv, &iv); \ + plaintext = aes##version##_decrypt_block_OFB(ciphertext, &encryption_keys, iv, &iv); \ } -#define AESXX_ENCRYPT_BLOCK_CTR(prefix) \ +#define AESXX_ENCRYPT_BLOCK_CTR(version) \ template <> \ - inline void encrypt_block( \ - const typename Types::Block& plaintext, \ - const typename Types::RoundKeys& encryption_keys, \ - typename Types::Block& iv, \ - typename Types::Block& ciphertext \ + inline void encrypt_block( \ + const typename Types::Block& plaintext, \ + const typename Types::RoundKeys& encryption_keys, \ + typename Types::Block& iv, \ + typename Types::Block& ciphertext \ ) { \ - ciphertext = aes_##prefix##_encrypt_block_CTR(plaintext, &encryption_keys, iv, &iv); \ + ciphertext = aes##version##_encrypt_block_CTR(plaintext, &encryption_keys, iv, &iv); \ } -#define AESXX_DECRYPT_BLOCK_CTR(prefix) \ +#define AESXX_DECRYPT_BLOCK_CTR(version) \ template <> \ - inline void decrypt_block( \ - const typename Types::Block& ciphertext, \ - const typename Types::RoundKeys& encryption_keys, \ - typename Types::Block& iv, \ - typename Types::Block& plaintext \ + inline void decrypt_block( \ + const typename Types::Block& ciphertext, \ + const typename Types::RoundKeys& encryption_keys, \ + typename Types::Block& iv, \ + typename Types::Block& plaintext \ ) { \ - plaintext = aes_##prefix##_decrypt_block_CTR(ciphertext, &encryption_keys, iv, &iv); \ + plaintext = aes##version##_decrypt_block_CTR(ciphertext, &encryption_keys, iv, &iv); \ } } // namespace aes -- cgit v1.3