diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-05-19 04:48:59 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-05-19 04:48:59 +0300 |
commit | f0393777befc4ff1024513dab3ab6bad0e7ec45f (patch) | |
tree | 97571103c522ff60f96a8fdde35a0bbee9532837 | |
parent | rename the project (diff) | |
download | aes-tools-f0393777befc4ff1024513dab3ab6bad0e7ec45f.tar.gz aes-tools-f0393777befc4ff1024513dab3ab6bad0e7ec45f.zip |
'aesni' -> 'aes'
41 files changed, 1670 insertions, 1670 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index db1581f..57398a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ project(aes_tools C CXX ASM_MASM) file(GLOB_RECURSE libaes_headers "include/*.h") -if(AESNI_USE_ASM) +if(LIBAES_USE_ASM) file(GLOB libaes_c_sources "src/*.c") file(GLOB libaes_asm_sources "src/asm/*.asm") set(libaes_sources ${libaes_asm_sources} ${libaes_c_sources}) @@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8 # title of most generated pages and in a few other places. # The default value is: My Project. -PROJECT_NAME = aesni +PROJECT_NAME = "AES tools" # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version diff --git a/cxx/include/aesxx/aes.hpp b/cxx/include/aesxx/aes.hpp index 698c0ef..fe0ade4 100644 --- a/cxx/include/aesxx/aes.hpp +++ b/cxx/include/aesxx/aes.hpp @@ -19,17 +19,17 @@ #include <string> -namespace aesni +namespace aes { namespace aes128 { - typedef AesNI_AES128_Block Block; - typedef AesNI_AES128_RoundKeys RoundKeys; - typedef AesNI_AES128_Key Key; + typedef AES_AES128_Block Block; + typedef AES_AES128_RoundKeys RoundKeys; + typedef AES_AES128_Key Key; } template <> - struct Types<AESNI_AES128> + struct Types<AES_AES128> { typedef aes128::Block Block; typedef aes128::RoundKeys RoundKeys; @@ -37,84 +37,84 @@ namespace aesni }; template <> - std::size_t get_number_of_rounds<AESNI_AES128>() + std::size_t get_number_of_rounds<AES_AES128>() { return 11; } template <> - void from_string<AESNI_AES128>(aes128::Block& dest, const char* src) + void from_string<AES_AES128>(aes128::Block& dest, const char* src) { - aesni_AES128_parse_block(&dest, src, ErrorDetailsThrowsInDestructor()); + aes_AES128_parse_block(&dest, src, ErrorDetailsThrowsInDestructor()); } template <> - std::string to_string<AESNI_AES128>(const aes128::Block& src) + std::string to_string<AES_AES128>(const aes128::Block& src) { - AesNI_AES128_BlockString str; - aesni_AES128_format_block(&str, &src, ErrorDetailsThrowsInDestructor()); + AES_AES128_BlockString str; + aes_AES128_format_block(&str, &src, ErrorDetailsThrowsInDestructor()); return { str.str }; } template <> - std::string to_matrix_string<AESNI_AES128>(const aes128::Block& src) + std::string to_matrix_string<AES_AES128>(const aes128::Block& src) { - AesNI_AES128_BlockMatrixString str; - aesni_AES128_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor()); + AES_AES128_BlockMatrixString str; + aes_AES128_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor()); return { str.str }; } template <> - void from_string<AESNI_AES128>(aes128::Key& dest, const char* src) + void from_string<AES_AES128>(aes128::Key& dest, const char* src) { - aesni_AES128_parse_key(&dest, src, ErrorDetailsThrowsInDestructor()); + aes_AES128_parse_key(&dest, src, ErrorDetailsThrowsInDestructor()); } template <> - std::string to_string<AESNI_AES128>(const aes128::Key& src) + std::string to_string<AES_AES128>(const aes128::Key& src) { - AesNI_AES128_KeyString str; - aesni_AES128_format_key(&str, &src, ErrorDetailsThrowsInDestructor()); + AES_AES128_KeyString str; + aes_AES128_format_key(&str, &src, ErrorDetailsThrowsInDestructor()); return { str.str }; } template <> - inline void expand_key<AESNI_AES128>( + inline void expand_key<AES_AES128>( const aes128::Key& key, aes128::RoundKeys& encryption_keys) { - aesni_AES128_expand_key(&key, &encryption_keys); + aes_AES128_expand_key(&key, &encryption_keys); } template <> - inline void derive_decryption_keys<AESNI_AES128>( + inline void derive_decryption_keys<AES_AES128>( const aes128::RoundKeys& encryption_keys, aes128::RoundKeys& decryption_keys) { - aesni_AES128_derive_decryption_keys( + aes_AES128_derive_decryption_keys( &encryption_keys, &decryption_keys); } - AESNIXX_ENCRYPT_BLOCK_ECB(AES128); - AESNIXX_DECRYPT_BLOCK_ECB(AES128); - AESNIXX_ENCRYPT_BLOCK_CBC(AES128); - AESNIXX_DECRYPT_BLOCK_CBC(AES128); - AESNIXX_ENCRYPT_BLOCK_CFB(AES128); - AESNIXX_DECRYPT_BLOCK_CFB(AES128); - AESNIXX_ENCRYPT_BLOCK_OFB(AES128); - AESNIXX_DECRYPT_BLOCK_OFB(AES128); - AESNIXX_ENCRYPT_BLOCK_CTR(AES128); - AESNIXX_DECRYPT_BLOCK_CTR(AES128); + 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); namespace aes192 { - typedef AesNI_AES192_Block Block; - typedef AesNI_AES192_RoundKeys RoundKeys; - typedef AesNI_AES192_Key Key; + typedef AES_AES192_Block Block; + typedef AES_AES192_RoundKeys RoundKeys; + typedef AES_AES192_Key Key; } template <> - struct Types<AESNI_AES192> + struct Types<AES_AES192> { typedef aes192::Block Block; typedef aes192::RoundKeys RoundKeys; @@ -122,84 +122,84 @@ namespace aesni }; template <> - std::size_t get_number_of_rounds<AESNI_AES192>() + std::size_t get_number_of_rounds<AES_AES192>() { return 13; } template <> - void from_string<AESNI_AES192>(aes192::Block& dest, const char* src) + void from_string<AES_AES192>(aes192::Block& dest, const char* src) { - aesni_AES192_parse_block(&dest, src, ErrorDetailsThrowsInDestructor()); + aes_AES192_parse_block(&dest, src, ErrorDetailsThrowsInDestructor()); } template <> - std::string to_string<AESNI_AES192>(const aes192::Block& src) + std::string to_string<AES_AES192>(const aes192::Block& src) { - AesNI_AES192_BlockString str; - aesni_AES192_format_block(&str, &src, ErrorDetailsThrowsInDestructor()); + AES_AES192_BlockString str; + aes_AES192_format_block(&str, &src, ErrorDetailsThrowsInDestructor()); return { str.str }; } template <> - std::string to_matrix_string<AESNI_AES192>(const aes192::Block& src) + std::string to_matrix_string<AES_AES192>(const aes192::Block& src) { - AesNI_AES192_BlockMatrixString str; - aesni_AES192_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor()); + AES_AES192_BlockMatrixString str; + aes_AES192_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor()); return { str.str }; } template <> - void from_string<AESNI_AES192>(aes192::Key& dest, const char* src) + void from_string<AES_AES192>(aes192::Key& dest, const char* src) { - aesni_AES192_parse_key(&dest, src, ErrorDetailsThrowsInDestructor()); + aes_AES192_parse_key(&dest, src, ErrorDetailsThrowsInDestructor()); } template <> - std::string to_string<AESNI_AES192>(const aes192::Key& src) + std::string to_string<AES_AES192>(const aes192::Key& src) { - AesNI_AES192_KeyString str; - aesni_AES192_format_key(&str, &src, ErrorDetailsThrowsInDestructor()); + AES_AES192_KeyString str; + aes_AES192_format_key(&str, &src, ErrorDetailsThrowsInDestructor()); return { str.str }; } template <> - inline void expand_key<AESNI_AES192>( + inline void expand_key<AES_AES192>( const aes192::Key& key, aes192::RoundKeys& encryption_keys) { - aesni_AES192_expand_key(&key, &encryption_keys); + aes_AES192_expand_key(&key, &encryption_keys); } template <> - inline void derive_decryption_keys<AESNI_AES192>( + inline void derive_decryption_keys<AES_AES192>( const aes192::RoundKeys& encryption_keys, aes192::RoundKeys& decryption_keys) { - aesni_AES192_derive_decryption_keys( + aes_AES192_derive_decryption_keys( &encryption_keys, &decryption_keys); } - AESNIXX_ENCRYPT_BLOCK_ECB(AES192); - AESNIXX_DECRYPT_BLOCK_ECB(AES192); - AESNIXX_ENCRYPT_BLOCK_CBC(AES192); - AESNIXX_DECRYPT_BLOCK_CBC(AES192); - AESNIXX_ENCRYPT_BLOCK_CFB(AES192); - AESNIXX_DECRYPT_BLOCK_CFB(AES192); - AESNIXX_ENCRYPT_BLOCK_OFB(AES192); - AESNIXX_DECRYPT_BLOCK_OFB(AES192); - AESNIXX_ENCRYPT_BLOCK_CTR(AES192); - AESNIXX_DECRYPT_BLOCK_CTR(AES192); + 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); namespace aes256 { - typedef AesNI_AES256_Block Block; - typedef AesNI_AES256_RoundKeys RoundKeys; - typedef AesNI_AES256_Key Key; + typedef AES_AES256_Block Block; + typedef AES_AES256_RoundKeys RoundKeys; + typedef AES_AES256_Key Key; } template <> - struct Types<AESNI_AES256> + struct Types<AES_AES256> { typedef aes256::Block Block; typedef aes256::RoundKeys RoundKeys; @@ -207,72 +207,72 @@ namespace aesni }; template <> - std::size_t get_number_of_rounds<AESNI_AES256>() + std::size_t get_number_of_rounds<AES_AES256>() { return 15; } template <> - void from_string<AESNI_AES256>(aes256::Block& dest, const char* src) + void from_string<AES_AES256>(aes256::Block& dest, const char* src) { - aesni_AES256_parse_block(&dest, src, ErrorDetailsThrowsInDestructor()); + aes_AES256_parse_block(&dest, src, ErrorDetailsThrowsInDestructor()); } template <> - std::string to_string<AESNI_AES256>(const aes256::Block& src) + std::string to_string<AES_AES256>(const aes256::Block& src) { - AesNI_AES256_BlockString str; - aesni_AES256_format_block(&str, &src, ErrorDetailsThrowsInDestructor()); + AES_AES256_BlockString str; + aes_AES256_format_block(&str, &src, ErrorDetailsThrowsInDestructor()); return { str.str }; } template <> - std::string to_matrix_string<AESNI_AES256>(const aes256::Block& src) + std::string to_matrix_string<AES_AES256>(const aes256::Block& src) { - AesNI_AES256_BlockMatrixString str; - aesni_AES256_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor()); + AES_AES256_BlockMatrixString str; + aes_AES256_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor()); return { str.str }; } template <> - void from_string<AESNI_AES256>(aes256::Key& dest, const char* src) + void from_string<AES_AES256>(aes256::Key& dest, const char* src) { - aesni_AES256_parse_key(&dest, src, ErrorDetailsThrowsInDestructor()); + aes_AES256_parse_key(&dest, src, ErrorDetailsThrowsInDestructor()); } template <> - std::string to_string<AESNI_AES256>(const aes256::Key& src) + std::string to_string<AES_AES256>(const aes256::Key& src) { - AesNI_AES256_KeyString str; - aesni_AES256_format_key(&str, &src, ErrorDetailsThrowsInDestructor()); + AES_AES256_KeyString str; + aes_AES256_format_key(&str, &src, ErrorDetailsThrowsInDestructor()); return { str.str }; } template <> - inline void expand_key<AESNI_AES256>( + inline void expand_key<AES_AES256>( const aes256::Key& key, aes256::RoundKeys& encryption_keys) { - aesni_AES256_expand_key(&key, &encryption_keys); + aes_AES256_expand_key(&key, &encryption_keys); } template <> - inline void derive_decryption_keys<AESNI_AES256>( + inline void derive_decryption_keys<AES_AES256>( const aes256::RoundKeys& encryption_keys, aes256::RoundKeys& decryption_keys) { - aesni_AES256_derive_decryption_keys( + aes_AES256_derive_decryption_keys( &encryption_keys, &decryption_keys); } - AESNIXX_ENCRYPT_BLOCK_ECB(AES256); - AESNIXX_DECRYPT_BLOCK_ECB(AES256); - AESNIXX_ENCRYPT_BLOCK_CBC(AES256); - AESNIXX_DECRYPT_BLOCK_CBC(AES256); - AESNIXX_ENCRYPT_BLOCK_CFB(AES256); - AESNIXX_DECRYPT_BLOCK_CFB(AES256); - AESNIXX_ENCRYPT_BLOCK_OFB(AES256); - AESNIXX_DECRYPT_BLOCK_OFB(AES256); - AESNIXX_ENCRYPT_BLOCK_CTR(AES256); - AESNIXX_DECRYPT_BLOCK_CTR(AES256); + 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); } diff --git a/cxx/include/aesxx/algorithm.hpp b/cxx/include/aesxx/algorithm.hpp index e2c73ac..c6f06d7 100644 --- a/cxx/include/aesxx/algorithm.hpp +++ b/cxx/include/aesxx/algorithm.hpp @@ -10,7 +10,7 @@ #include <aes/all.h> -namespace aesni +namespace aes { - typedef AesNI_Algorithm Algorithm; + typedef AES_Algorithm Algorithm; } diff --git a/cxx/include/aesxx/api.hpp b/cxx/include/aesxx/api.hpp index 6995ae2..0b183a8 100644 --- a/cxx/include/aesxx/api.hpp +++ b/cxx/include/aesxx/api.hpp @@ -16,7 +16,7 @@ #include <string> #include <type_traits> -namespace aesni +namespace aes { template <Algorithm algorithm> struct Types; @@ -129,7 +129,7 @@ namespace aesni const typename Types<algorithm>::Block& plaintext, typename Types<algorithm>::Block& ciphertext) { - aesni::encrypt_block<algorithm, mode>( + aes::encrypt_block<algorithm, mode>( plaintext, encryption_keys, iv, ciphertext); } @@ -161,7 +161,7 @@ namespace aesni const typename Types<algorithm>::Block& ciphertext, typename Types<algorithm>::Block& plaintext) { - aesni::decrypt_block<algorithm, mode>( + aes::decrypt_block<algorithm, mode>( ciphertext, decryption_keys, iv, plaintext); } diff --git a/cxx/include/aesxx/box.hpp b/cxx/include/aesxx/box.hpp index ffca6ce..7df8c97 100644 --- a/cxx/include/aesxx/box.hpp +++ b/cxx/include/aesxx/box.hpp @@ -21,26 +21,26 @@ #include <string> #include <vector> -namespace aesni +namespace aes { class Box { public: - typedef AesNI_BoxBlock Block; - typedef AesNI_BoxKey Key; + typedef AES_BoxBlock Block; + typedef AES_BoxKey Key; static std::string format_key(const Key& src, Algorithm algorithm) { - AesNI_BoxKeyString str; - aesni_box_format_key( + AES_BoxKeyString str; + aes_box_format_key( &str, algorithm, &src, ErrorDetailsThrowsInDestructor()); return reinterpret_cast<const char*>(&str); } static std::string format_block(const Block& src, Algorithm algorithm) { - AesNI_BoxBlockString str; - aesni_box_format_block( + AES_BoxBlockString str; + aes_box_format_block( &str, algorithm, &src, ErrorDetailsThrowsInDestructor()); return reinterpret_cast<const char*>(&str); } @@ -50,7 +50,7 @@ namespace aesni Algorithm algorithm, const char* src) { - aesni_box_parse_block(&dest, algorithm, src, + aes_box_parse_block(&dest, algorithm, src, ErrorDetailsThrowsInDestructor()); } @@ -67,7 +67,7 @@ namespace aesni Algorithm algorithm, const char* src) { - aesni_box_parse_key(&dest, algorithm, src, + aes_box_parse_key(&dest, algorithm, src, ErrorDetailsThrowsInDestructor()); } @@ -81,9 +81,9 @@ namespace aesni Box(Algorithm algorithm, const Key& key) : algorithm(algorithm) - , mode(AESNI_ECB) + , mode(AES_ECB) { - aesni_box_init(&impl, algorithm, &key, mode, nullptr, + aes_box_init(&impl, algorithm, &key, mode, nullptr, ErrorDetailsThrowsInDestructor()); } @@ -91,20 +91,20 @@ namespace aesni : algorithm(algorithm) , mode(mode) { - aesni_box_init(&impl, algorithm, &key, mode, &iv, + aes_box_init(&impl, algorithm, &key, mode, &iv, ErrorDetailsThrowsInDestructor()); } void encrypt_block(const Block& plaintext, Block& ciphertext) { - aesni_box_encrypt_block( + aes_box_encrypt_block( &impl, &plaintext, &ciphertext, ErrorDetailsThrowsInDestructor()); } void decrypt_block(const Block& ciphertext, Block& plaintext) { - aesni_box_decrypt_block( + aes_box_decrypt_block( &impl, &ciphertext, &plaintext, ErrorDetailsThrowsInDestructor()); } @@ -115,24 +115,24 @@ namespace aesni { std::size_t dest_size; - aesni_box_encrypt_buffer( + aes_box_encrypt_buffer( &impl, src_buf, src_size, nullptr, &dest_size, - aesni::ErrorDetailsThrowsInDestructor()); + aes::ErrorDetailsThrowsInDestructor()); std::vector<unsigned char> dest_buf; dest_buf.resize(dest_size); - aesni_box_encrypt_buffer( + aes_box_encrypt_buffer( &impl, src_buf, src_size, dest_buf.data(), &dest_size, - aesni::ErrorDetailsThrowsInDestructor()); + aes::ErrorDetailsThrowsInDestructor()); dest_buf.resize(dest_size); return dest_buf; @@ -144,24 +144,24 @@ namespace aesni { std::size_t dest_size; - aesni_box_decrypt_buffer( + aes_box_decrypt_buffer( &impl, src_buf, src_size, nullptr, &dest_size, - aesni::ErrorDetailsThrowsInDestructor()); + aes::ErrorDetailsThrowsInDestructor()); std::vector<unsigned char> dest_buf; dest_buf.resize(dest_size); - aesni_box_decrypt_buffer( + aes_box_decrypt_buffer( &impl, src_buf, src_size, dest_buf.data(), &dest_size, - aesni::ErrorDetailsThrowsInDestructor()); + aes::ErrorDetailsThrowsInDestructor()); dest_buf.resize(dest_size); return dest_buf; @@ -207,6 +207,6 @@ namespace aesni Algorithm algorithm; Mode mode; - AesNI_Box impl; + AES_Box impl; }; } diff --git a/cxx/include/aesxx/data.hpp b/cxx/include/aesxx/data.hpp index f52fe3e..9b07343 100644 --- a/cxx/include/aesxx/data.hpp +++ b/cxx/include/aesxx/data.hpp @@ -12,47 +12,47 @@ #include <aes/all.h> -namespace aesni +namespace aes { - typedef AesNI_Block128 Block128; + typedef AES_Block128 Block128; inline void make_block(Block128& dest, int hi3, int hi2, int lo1, int lo0) { - dest = aesni_make_block128(hi3, hi2, lo1, lo0); + dest = aes_make_block128(hi3, hi2, lo1, lo0); } inline void load_block(Block128& dest, const void* src) { - dest = aesni_load_block128(src); + dest = aes_load_block128(src); } inline void load_block_aligned(Block128& dest, const void* src) { - dest = aesni_load_block128_aligned(src); + dest = aes_load_block128_aligned(src); } inline void store_block(void* dest, Block128& src) { - aesni_store_block128(dest, src); + aes_store_block128(dest, src); } inline void store_block_aligned(void* dest, Block128& src) { - aesni_store_block128_aligned(dest, src); + aes_store_block128_aligned(dest, src); } inline Block128 xor_blocks(Block128& a, Block128& b) { - return aesni_xor_block128(a, b); + return aes_xor_block128(a, b); } inline Block128 reverse_byte_order(Block128& block) { - return aesni_reverse_byte_order_block128(block); + return aes_reverse_byte_order_block128(block); } inline Block128 inc_block(Block128& block) { - return aesni_inc_block128(block); + return aes_inc_block128(block); } } diff --git a/cxx/include/aesxx/debug.hpp b/cxx/include/aesxx/debug.hpp index f3e35f4..d690257 100644 --- a/cxx/include/aesxx/debug.hpp +++ b/cxx/include/aesxx/debug.hpp @@ -19,7 +19,7 @@ #include <sstream> #include <string> -namespace aesni +namespace aes { namespace aux { diff --git a/cxx/include/aesxx/error.hpp b/cxx/include/aesxx/error.hpp index 1f22535..85f45bf 100644 --- a/cxx/include/aesxx/error.hpp +++ b/cxx/include/aesxx/error.hpp @@ -24,12 +24,12 @@ #include <string> #include <vector> -namespace aesni +namespace aes { class Error : public std::runtime_error { public: - Error(const AesNI_ErrorDetails& err_details) + Error(const AES_ErrorDetails& err_details) : std::runtime_error(format_error_message(err_details)) { copy_call_stack(err_details); @@ -45,27 +45,27 @@ namespace aesni } private: - static std::string format_error_message(const AesNI_ErrorDetails& err_details) + static std::string format_error_message(const AES_ErrorDetails& err_details) { std::vector<char> buf; - buf.resize(aesni_format_error(&err_details, NULL, 0)); - aesni_format_error(&err_details, buf.data(), buf.size()); + buf.resize(aes_format_error(&err_details, NULL, 0)); + aes_format_error(&err_details, buf.data(), buf.size()); return { buf.begin(), buf.end() }; } - void copy_call_stack(const AesNI_ErrorDetails& err_details) + void copy_call_stack(const AES_ErrorDetails& err_details) { call_stack_size = err_details.call_stack_size; std::memcpy(call_stack, err_details.call_stack, call_stack_size * sizeof(void*)); } - void* call_stack[AESNI_MAX_CALL_STACK_LENGTH]; + void* call_stack[AES_MAX_CALL_STACK_LENGTH]; std::size_t call_stack_size; }; std::ostream& operator<<(std::ostream& os, const Error& e) { - os << "AesNI error: " << e.what() << '\n'; + os << "AES error: " << e.what() << '\n'; os << "Call stack:\n"; e.for_each_in_call_stack([&os] (void* addr, const std::string& name) { @@ -79,20 +79,20 @@ namespace aesni public: ErrorDetailsThrowsInDestructor() { - aesni_success(get()); + aes_success(get()); } ~ErrorDetailsThrowsInDestructor() BOOST_NOEXCEPT_IF(false) { - if (aesni_is_error(aesni_get_error_code(get()))) + if (aes_is_error(aes_get_error_code(get()))) throw Error(impl); } - AesNI_ErrorDetails* get() { return &impl; } + AES_ErrorDetails* get() { return &impl; } - operator AesNI_ErrorDetails*() { return get(); } + operator AES_ErrorDetails*() { return get(); } private: - AesNI_ErrorDetails impl; + AES_ErrorDetails impl; }; } diff --git a/cxx/include/aesxx/mode.hpp b/cxx/include/aesxx/mode.hpp index 706c4b5..70f16c6 100644 --- a/cxx/include/aesxx/mode.hpp +++ b/cxx/include/aesxx/mode.hpp @@ -12,16 +12,16 @@ #include <type_traits> -namespace aesni +namespace aes { - typedef AesNI_Mode Mode; + typedef AES_Mode Mode; template <Mode mode> struct ModeRequiresInitializationVector : public std::true_type { }; template <> - struct ModeRequiresInitializationVector<AESNI_ECB> : public std::false_type + struct ModeRequiresInitializationVector<AES_ECB> : public std::false_type { }; template <Mode mode> @@ -30,127 +30,127 @@ namespace aesni inline bool mode_requires_initialization_vector(Mode mode) { - return mode != AESNI_ECB; + return mode != AES_ECB; } template <> - struct ModeUsesEncryptionKeysOnly<AESNI_ECB> : public std::false_type + struct ModeUsesEncryptionKeysOnly<AES_ECB> : public std::false_type { }; template <> - struct ModeUsesEncryptionKeysOnly<AESNI_CBC> : public std::false_type + struct ModeUsesEncryptionKeysOnly<AES_CBC> : public std::false_type { }; inline bool mode_uses_encryption_keys_only(Mode mode) { - return mode != AESNI_ECB && mode != AESNI_CBC; + return mode != AES_ECB && mode != AES_CBC; } -#define AESNIXX_ENCRYPT_BLOCK_ECB(prefix) \ +#define AESXX_ENCRYPT_BLOCK_ECB(prefix) \ template <> \ - inline void encrypt_block<AESNI_## prefix, AESNI_ECB>( \ - const typename Types<AESNI_## prefix>::Block& plaintext, \ - const typename Types<AESNI_## prefix>::RoundKeys& encryption_keys, \ - typename Types<AESNI_## prefix>::Block& ciphertext) \ + inline void encrypt_block<AES_## prefix, AES_ECB>( \ + const typename Types<AES_## prefix>::Block& plaintext, \ + const typename Types<AES_## prefix>::RoundKeys& encryption_keys, \ + typename Types<AES_## prefix>::Block& ciphertext) \ { \ - ciphertext = aesni_## prefix ##_encrypt_block_ECB(plaintext, &encryption_keys); \ + ciphertext = aes_## prefix ##_encrypt_block_ECB(plaintext, &encryption_keys); \ } -#define AESNIXX_DECRYPT_BLOCK_ECB(prefix) \ +#define AESXX_DECRYPT_BLOCK_ECB(prefix) \ template <> \ - inline void decrypt_block<AESNI_## prefix, AESNI_ECB>( \ - const typename Types<AESNI_## prefix>::Block& ciphertext, \ - const typename Types<AESNI_## prefix>::RoundKeys& decryption_keys, \ - typename Types<AESNI_## prefix>::Block& plaintext) \ + inline void decrypt_block<AES_## prefix, AES_ECB>( \ + const typename Types<AES_## prefix>::Block& ciphertext, \ + const typename Types<AES_## prefix>::RoundKeys& decryption_keys, \ + typename Types<AES_## prefix>::Block& plaintext) \ { \ - plaintext = aesni_## prefix ##_decrypt_block_ECB(ciphertext, &decryption_keys); \ + plaintext = aes_## prefix ##_decrypt_block_ECB(ciphertext, &decryption_keys); \ } -#define AESNIXX_ENCRYPT_BLOCK_CBC(prefix) \ +#define AESXX_ENCRYPT_BLOCK_CBC(prefix) \ template <> \ - inline void encrypt_block<AESNI_## prefix, AESNI_CBC>( \ - const typename Types<AESNI_## prefix>::Block& plaintext, \ - const typename Types<AESNI_## prefix>::RoundKeys& encryption_keys, \ - typename Types<AESNI_## prefix>::Block& iv, \ - typename Types<AESNI_## prefix>::Block& ciphertext) \ + inline void encrypt_block<AES_## prefix, AES_CBC>( \ + const typename Types<AES_## prefix>::Block& plaintext, \ + const typename Types<AES_## prefix>::RoundKeys& encryption_keys, \ + typename Types<AES_## prefix>::Block& iv, \ + typename Types<AES_## prefix>::Block& ciphertext) \ { \ - ciphertext = aesni_## prefix ##_encrypt_block_CBC(plaintext, &encryption_keys, iv, &iv); \ + ciphertext = aes_## prefix ##_encrypt_block_CBC(plaintext, &encryption_keys, iv, &iv); \ } -#define AESNIXX_DECRYPT_BLOCK_CBC(prefix) \ +#define AESXX_DECRYPT_BLOCK_CBC(prefix) \ template <> \ - inline void decrypt_block<AESNI_## prefix, AESNI_CBC>( \ - const typename Types<AESNI_## prefix>::Block& ciphertext, \ - const typename Types<AESNI_## prefix>::RoundKeys& decryption_keys, \ - typename Types<AESNI_## prefix>::Block& iv, \ - typename Types<AESNI_## prefix>::Block& plaintext) \ + inline void decrypt_block<AES_## prefix, AES_CBC>( \ + const typename Types<AES_## prefix>::Block& ciphertext, \ + const typename Types<AES_## prefix>::RoundKeys& decryption_keys, \ + typename Types<AES_## prefix>::Block& iv, \ + typename Types<AES_## prefix>::Block& plaintext) \ { \ - plaintext = aesni_## prefix ##_decrypt_block_CBC(ciphertext, &decryption_keys, iv, &iv); \ + plaintext = aes_## prefix ##_decrypt_block_CBC(ciphertext, &decryption_keys, iv, &iv); \ } -#define AESNIXX_ENCRYPT_BLOCK_CFB(prefix) \ +#define AESXX_ENCRYPT_BLOCK_CFB(prefix) \ template <> \ - inline void encrypt_block<AESNI_## prefix, AESNI_CFB>( \ - const typename Types<AESNI_## prefix>::Block& plaintext, \ - const typename Types<AESNI_## prefix>::RoundKeys& encryption_keys, \ - typename Types<AESNI_## prefix>::Block& iv, \ - typename Types<AESNI_## prefix>::Block& ciphertext) \ + inline void encrypt_block<AES_## prefix, AES_CFB>( \ + const typename Types<AES_## prefix>::Block& plaintext, \ + const typename Types<AES_## prefix>::RoundKeys& encryption_keys, \ + typename Types<AES_## prefix>::Block& iv, \ + typename Types<AES_## prefix>::Block& ciphertext) \ { \ - ciphertext = aesni_## prefix ##_encrypt_block_CFB(plaintext, &encryption_keys, iv, &iv); \ + ciphertext = aes_## prefix ##_encrypt_block_CFB(plaintext, &encryption_keys, iv, &iv); \ } -#define AESNIXX_DECRYPT_BLOCK_CFB(prefix) \ +#define AESXX_DECRYPT_BLOCK_CFB(prefix) \ template <> \ - inline void decrypt_block<AESNI_## prefix, AESNI_CFB>( \ - const typename Types<AESNI_## prefix>::Block& ciphertext, \ - const typename Types<AESNI_## prefix>::RoundKeys& encryption_keys, \ - typename Types<AESNI_## prefix>::Block& iv, \ - typename Types<AESNI_## prefix>::Block& plaintext) \ + inline void decrypt_block<AES_## prefix, AES_CFB>( \ + const typename Types<AES_## prefix>::Block& ciphertext, \ + const typename Types<AES_## prefix>::RoundKeys& encryption_keys, \ + typename Types<AES_## prefix>::Block& iv, \ + typename Types<AES_## prefix>::Block& plaintext) \ { \ - plaintext = aesni_## prefix ##_decrypt_block_CFB(ciphertext, &encryption_keys, iv, &iv); \ + plaintext = aes_## prefix ##_decrypt_block_CFB(ciphertext, &encryption_keys, iv, &iv); \ } -#define AESNIXX_ENCRYPT_BLOCK_OFB(prefix) \ +#define AESXX_ENCRYPT_BLOCK_OFB(prefix) \ template <> \ - inline void encrypt_block<AESNI_## prefix, AESNI_OFB>( \ - const typename Types<AESNI_## prefix>::Block& plaintext, \ - const typename Types<AESNI_## prefix>::RoundKeys& encryption_keys, \ - typename Types<AESNI_## prefix>::Block& iv, \ - typename Types<AESNI_## prefix>::Block& ciphertext) \ + inline void encrypt_block<AES_## prefix, AES_OFB>( \ + const typename Types<AES_## prefix>::Block& plaintext, \ + const typename Types<AES_## prefix>::RoundKeys& encryption_keys, \ + typename Types<AES_## prefix>::Block& iv, \ + typename Types<AES_## prefix>::Block& ciphertext) \ { \ - ciphertext = aesni_## prefix ##_encrypt_block_OFB(plaintext, &encryption_keys, iv, &iv); \ + ciphertext = aes_## prefix ##_encrypt_block_OFB(plaintext, &encryption_keys, iv, &iv); \ } -#define AESNIXX_DECRYPT_BLOCK_OFB(prefix) \ +#define AESXX_DECRYPT_BLOCK_OFB(prefix) \ template <> \ - inline void decrypt_block<AESNI_## prefix, AESNI_OFB>( \ - const typename Types<AESNI_## prefix>::Block& ciphertext, \ - const typename Types<AESNI_## prefix>::RoundKeys& encryption_keys, \ - typename Types<AESNI_## prefix>::Block& iv, \ - typename Types<AESNI_## prefix>::Block& plaintext) \ + inline void decrypt_block<AES_## prefix, AES_OFB>( \ + const typename Types<AES_## prefix>::Block& ciphertext, \ + const typename Types<AES_## prefix>::RoundKeys& encryption_keys, \ + typename Types<AES_## prefix>::Block& iv, \ + typename Types<AES_## prefix>::Block& plaintext) \ { \ - plaintext = aesni_## prefix ##_decrypt_block_OFB(ciphertext, &encryption_keys, iv, &iv); \ + plaintext = aes_## prefix ##_decrypt_block_OFB(ciphertext, &encryption_keys, iv, &iv); \ } -#define AESNIXX_ENCRYPT_BLOCK_CTR(prefix) \ +#define AESXX_ENCRYPT_BLOCK_CTR(prefix) \ template <> \ - inline void encrypt_block<AESNI_## prefix, AESNI_CTR>( \ - const typename Types<AESNI_## prefix>::Block& plaintext, \ - const typename Types<AESNI_## prefix>::RoundKeys& encryption_keys, \ - typename Types<AESNI_## prefix>::Block& iv, \ - typename Types<AESNI_## prefix>::Block& ciphertext) \ + inline void encrypt_block<AES_## prefix, AES_CTR>( \ + const typename Types<AES_## prefix>::Block& plaintext, \ + const typename Types<AES_## prefix>::RoundKeys& encryption_keys, \ + typename Types<AES_## prefix>::Block& iv, \ + typename Types<AES_## prefix>::Block& ciphertext) \ { \ - ciphertext = aesni_## prefix ##_encrypt_block_CTR(plaintext, &encryption_keys, iv, &iv); \ + ciphertext = aes_## prefix ##_encrypt_block_CTR(plaintext, &encryption_keys, iv, &iv); \ } -#define AESNIXX_DECRYPT_BLOCK_CTR(prefix) \ +#define AESXX_DECRYPT_BLOCK_CTR(prefix) \ template <> \ - inline void decrypt_block<AESNI_## prefix, AESNI_CTR>( \ - const typename Types<AESNI_## prefix>::Block& ciphertext, \ - const typename Types<AESNI_## prefix>::RoundKeys& encryption_keys, \ - typename Types<AESNI_## prefix>::Block& iv, \ - typename Types<AESNI_## prefix>::Block& plaintext) \ + inline void decrypt_block<AES_## prefix, AES_CTR>( \ + const typename Types<AES_## prefix>::Block& ciphertext, \ + const typename Types<AES_## prefix>::RoundKeys& encryption_keys, \ + typename Types<AES_## prefix>::Block& iv, \ + typename Types<AES_## prefix>::Block& plaintext) \ { \ - plaintext = aesni_## prefix ##_decrypt_block_CTR(ciphertext, &encryption_keys, iv, &iv); \ + plaintext = aes_## prefix ##_decrypt_block_CTR(ciphertext, &encryption_keys, iv, &iv); \ } } diff --git a/include/aes/aes.h b/include/aes/aes.h index ea859a3..62a301b 100644 --- a/include/aes/aes.h +++ b/include/aes/aes.h @@ -19,415 +19,415 @@ extern "C" { #endif -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 AES_Block128 AES_AES_Block; +typedef AES_AES_Block AES_AES128_Block; +typedef AES_AES_Block AES_AES192_Block; +typedef AES_AES_Block AES_AES256_Block; typedef struct { - AesNI_AES_Block key; + AES_AES_Block key; } -AesNI_AES128_Key; +AES_AES128_Key; typedef struct { - AesNI_AES_Block hi; - AesNI_AES_Block lo; + AES_AES_Block hi; + AES_AES_Block lo; } -AesNI_AES192_Key; +AES_AES192_Key; typedef struct { - AesNI_AES_Block hi; - AesNI_AES_Block lo; + AES_AES_Block hi; + AES_AES_Block lo; } -AesNI_AES256_Key; +AES_AES256_Key; -static __inline void aesni_AES_make_block(AesNI_AES_Block* dest, int hi3, int hi2, int lo1, int lo0) +static __inline void aes_AES_make_block(AES_AES_Block* dest, int hi3, int hi2, int lo1, int lo0) { - *dest = aesni_make_block128(hi3, hi2, lo1, lo0); + *dest = aes_make_block128(hi3, hi2, lo1, lo0); } -static __inline void aesni_AES128_make_block(AesNI_AES128_Block* dest, int hi3, int hi2, int lo1, int lo0) +static __inline void aes_AES128_make_block(AES_AES128_Block* dest, int hi3, int hi2, int lo1, int lo0) { - aesni_AES_make_block(dest, hi3, hi2, lo1, lo0); + aes_AES_make_block(dest, hi3, hi2, lo1, lo0); } -static __inline void aesni_AES192_make_block(AesNI_AES192_Block* dest, int hi3, int hi2, int lo1, int lo0) +static __inline void aes_AES192_make_block(AES_AES192_Block* dest, int hi3, int hi2, int lo1, int lo0) { - aesni_AES_make_block(dest, hi3, hi2, lo1, lo0); + aes_AES_make_block(dest, hi3, hi2, lo1, lo0); } -static __inline void aesni_AES256_make_block(AesNI_AES256_Block* dest, int hi3, int hi2, int lo1, int lo0) +static __inline void aes_AES256_make_block(AES_AES256_Block* dest, int hi3, int hi2, int lo1, int lo0) { - aesni_AES_make_block(dest, hi3, hi2, lo1, lo0); + aes_AES_make_block(dest, 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 aes_AES128_make_key(AES_AES128_Key* dest, int hi3, int hi2, int lo1, int lo0) { - aesni_AES_make_block(&dest->key, hi3, hi2, lo1, lo0); + aes_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) +static __inline void aes_AES192_make_key(AES_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); + aes_AES_make_block(&dest->hi, 0, 0, hi5, hi4); + aes_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) +static __inline void aes_AES256_make_key(AES_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); + aes_AES_make_block(&dest->hi, hi7, hi6, hi5, hi4); + aes_AES_make_block(&dest->lo, lo3, lo2, lo1, lo0); } -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[33]; } AES_AES_BlockString; +typedef AES_AES_BlockString AES_AES128_BlockString; +typedef AES_AES_BlockString AES_AES192_BlockString; +typedef AES_AES_BlockString AES_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; +typedef struct { char str[49]; } AES_AES_BlockMatrixString; +typedef AES_AES_BlockMatrixString AES_AES128_BlockMatrixString; +typedef AES_AES_BlockMatrixString AES_AES192_BlockMatrixString; +typedef AES_AES_BlockMatrixString AES_AES256_BlockMatrixString; -AesNI_StatusCode aesni_AES_format_block( - AesNI_AES_BlockString*, - const AesNI_AES_Block*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES_format_block( + AES_AES_BlockString*, + const AES_AES_Block*, + AES_ErrorDetails*); -static __inline AesNI_StatusCode aesni_AES128_format_block( - AesNI_AES128_BlockString* dest, - const AesNI_AES128_Block* src, - AesNI_ErrorDetails* err_details) +static __inline AES_StatusCode aes_AES128_format_block( + AES_AES128_BlockString* dest, + const AES_AES128_Block* src, + AES_ErrorDetails* err_details) { - return aesni_AES_format_block(dest, src, err_details); + return aes_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) +static __inline AES_StatusCode aes_AES192_format_block( + AES_AES192_BlockString* dest, + const AES_AES192_Block* src, + AES_ErrorDetails* err_details) { - return aesni_AES_format_block(dest, src, err_details); + return aes_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) +static __inline AES_StatusCode aes_AES256_format_block( + AES_AES256_BlockString* dest, + const AES_AES256_Block* src, + AES_ErrorDetails* err_details) { - return aesni_AES_format_block(dest, src, err_details); + return aes_AES_format_block(dest, src, err_details); } -AesNI_StatusCode aesni_AES_format_block_as_matrix( - AesNI_AES_BlockMatrixString*, - const AesNI_AES_Block*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES_format_block_as_matrix( + AES_AES_BlockMatrixString*, + const AES_AES_Block*, + AES_ErrorDetails*); -static __inline AesNI_StatusCode aesni_AES128_format_block_as_matrix( - AesNI_AES128_BlockMatrixString* dest, - const AesNI_AES128_Block* src, - AesNI_ErrorDetails* err_details) +static __inline AES_StatusCode aes_AES128_format_block_as_matrix( + AES_AES128_BlockMatrixString* dest, + const AES_AES128_Block* src, + AES_ErrorDetails* err_details) { - return aesni_AES_format_block_as_matrix(dest, src, err_details); + return aes_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) +static __inline AES_StatusCode aes_AES192_format_block_as_matrix( + AES_AES192_BlockMatrixString* dest, + const AES_AES192_Block* src, + AES_ErrorDetails* err_details) { - return aesni_AES_format_block_as_matrix(dest, src, err_details); + return aes_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) +static __inline AES_StatusCode aes_AES256_format_block_as_matrix( + AES_AES256_BlockMatrixString* dest, + const AES_AES256_Block* src, + AES_ErrorDetails* err_details) { - return aesni_AES_format_block_as_matrix(dest, src, err_details); + return aes_AES_format_block_as_matrix(dest, src, err_details); } -AesNI_StatusCode aesni_AES_print_block( - const AesNI_AES_Block*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES_print_block( + const AES_AES_Block*, + AES_ErrorDetails*); -static __inline AesNI_StatusCode aesni_AES128_print_block( - const AesNI_AES128_Block* block, - AesNI_ErrorDetails* err_details) +static __inline AES_StatusCode aes_AES128_print_block( + const AES_AES128_Block* block, + AES_ErrorDetails* err_details) { - return aesni_AES_print_block(block, err_details); + return aes_AES_print_block(block, err_details); } -static __inline AesNI_StatusCode aesni_AES192_print_block( - const AesNI_AES192_Block* block, - AesNI_ErrorDetails* err_details) +static __inline AES_StatusCode aes_AES192_print_block( + const AES_AES192_Block* block, + AES_ErrorDetails* err_details) { - return aesni_AES_print_block(block, err_details); + return aes_AES_print_block(block, err_details); } -static __inline AesNI_StatusCode aesni_AES256_print_block( - const AesNI_AES256_Block* block, - AesNI_ErrorDetails* err_details) +static __inline AES_StatusCode aes_AES256_print_block( + const AES_AES256_Block* block, + AES_ErrorDetails* err_details) { - return aesni_AES_print_block(block, err_details); + return aes_AES_print_block(block, err_details); } -AesNI_StatusCode aesni_AES_print_block_as_matrix( - const AesNI_AES_Block*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES_print_block_as_matrix( + const AES_AES_Block*, + AES_ErrorDetails*); -static __inline AesNI_StatusCode aesni_AES128_print_block_as_matrix( - const AesNI_AES128_Block* block, - AesNI_ErrorDetails* err_details) +static __inline AES_StatusCode aes_AES128_print_block_as_matrix( + const AES_AES128_Block* block, + AES_ErrorDetails* err_details) { - return aesni_AES_print_block_as_matrix(block, err_details); + return aes_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) +static __inline AES_StatusCode aes_AES192_print_block_as_matrix( + const AES_AES192_Block* block, + AES_ErrorDetails* err_details) { - return aesni_AES_print_block_as_matrix(block, err_details); + return aes_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) +static __inline AES_StatusCode aes_AES256_print_block_as_matrix( + const AES_AES256_Block* block, + AES_ErrorDetails* err_details) { - return aesni_AES_print_block_as_matrix(block, err_details); + return aes_AES_print_block_as_matrix(block, err_details); } -AesNI_StatusCode aesni_AES_parse_block( - AesNI_AES_Block* dest, +AES_StatusCode aes_AES_parse_block( + AES_AES_Block* dest, const char* src, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); -static __inline AesNI_StatusCode aesni_AES128_parse_block( - AesNI_AES128_Block* dest, +static __inline AES_StatusCode aes_AES128_parse_block( + AES_AES128_Block* dest, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - return aesni_AES_parse_block(dest, src, err_details); + return aes_AES_parse_block(dest, src, err_details); } -static __inline AesNI_StatusCode aesni_AES192_parse_block( - AesNI_AES192_Block* dest, +static __inline AES_StatusCode aes_AES192_parse_block( + AES_AES192_Block* dest, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - return aesni_AES_parse_block(dest, src, err_details); + return aes_AES_parse_block(dest, src, err_details); } -static __inline AesNI_StatusCode aesni_AES256_parse_block( - AesNI_AES256_Block* dest, +static __inline AES_StatusCode aes_AES256_parse_block( + AES_AES256_Block* dest, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - return aesni_AES_parse_block(dest, src, err_details); + return aes_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; +typedef struct { char str[33]; } AES_AES128_KeyString; +typedef struct { char str[49]; } AES_AES192_KeyString; +typedef struct { char str[65]; } AES_AES256_KeyString; -AesNI_StatusCode aesni_AES128_format_key( - AesNI_AES128_KeyString*, - const AesNI_AES128_Key*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES128_format_key( + AES_AES128_KeyString*, + const AES_AES128_Key*, + AES_ErrorDetails*); -AesNI_StatusCode aesni_AES192_format_key( - AesNI_AES192_KeyString*, - const AesNI_AES192_Key*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES192_format_key( + AES_AES192_KeyString*, + const AES_AES192_Key*, + AES_ErrorDetails*); -AesNI_StatusCode aesni_AES256_format_key( - AesNI_AES256_KeyString*, - const AesNI_AES256_Key*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES256_format_key( + AES_AES256_KeyString*, + const AES_AES256_Key*, + AES_ErrorDetails*); -AesNI_StatusCode aesni_AES128_print_key( - const AesNI_AES128_Key*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES128_print_key( + const AES_AES128_Key*, + AES_ErrorDetails*); -AesNI_StatusCode aesni_AES192_print_key( - const AesNI_AES192_Key*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES192_print_key( + const AES_AES192_Key*, + AES_ErrorDetails*); -AesNI_StatusCode aesni_AES256_print_key( - const AesNI_AES256_Key*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES256_print_key( + const AES_AES256_Key*, + AES_ErrorDetails*); -AesNI_StatusCode aesni_AES128_parse_key( - AesNI_AES128_Key* dest, +AES_StatusCode aes_AES128_parse_key( + AES_AES128_Key* dest, const char* src, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_AES192_parse_key( - AesNI_AES192_Key* dest, +AES_StatusCode aes_AES192_parse_key( + AES_AES192_Key* dest, const char* src, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_AES256_parse_key( - AesNI_AES256_Key* dest, +AES_StatusCode aes_AES256_parse_key( + AES_AES256_Key* dest, const char* src, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); typedef struct { - AesNI_AES_Block keys[11]; + AES_AES_Block keys[11]; } -AesNI_AES128_RoundKeys; +AES_AES128_RoundKeys; typedef struct { - AesNI_AES_Block keys[13]; + AES_AES_Block keys[13]; } -AesNI_AES192_RoundKeys; +AES_AES192_RoundKeys; typedef struct { - AesNI_AES_Block keys[15]; + AES_AES_Block keys[15]; } -AesNI_AES256_RoundKeys; +AES_AES256_RoundKeys; -void __fastcall aesni_AES128_expand_key_( - AesNI_AES_Block key, - AesNI_AES128_RoundKeys* encryption_keys); +void __fastcall aes_AES128_expand_key_( + AES_AES_Block key, + AES_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 aes_AES192_expand_key_( + AES_AES_Block key_lo, + AES_AES_Block key_hi, + AES_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 aes_AES256_expand_key_( + AES_AES_Block key_lo, + AES_AES_Block key_hi, + AES_AES256_RoundKeys* encryption_keys); -void __fastcall aesni_AES128_derive_decryption_keys_( - const AesNI_AES128_RoundKeys* encryption_keys, - AesNI_AES128_RoundKeys* decryption_keys); +void __fastcall aes_AES128_derive_decryption_keys_( + const AES_AES128_RoundKeys* encryption_keys, + AES_AES128_RoundKeys* decryption_keys); -void __fastcall aesni_AES192_derive_decryption_keys_( - const AesNI_AES192_RoundKeys* encryption_keys, - AesNI_AES192_RoundKeys* decryption_keys); +void __fastcall aes_AES192_derive_decryption_keys_( + const AES_AES192_RoundKeys* encryption_keys, + AES_AES192_RoundKeys* decryption_keys); -void __fastcall aesni_AES256_derive_decryption_keys_( - const AesNI_AES256_RoundKeys* encryption_keys, - AesNI_AES256_RoundKeys* decryption_keys); +void __fastcall aes_AES256_derive_decryption_keys_( + const AES_AES256_RoundKeys* encryption_keys, + AES_AES256_RoundKeys* decryption_keys); -AesNI_AES_Block __fastcall aesni_AES128_encrypt_block_( - AesNI_AES_Block plaintext, - const AesNI_AES128_RoundKeys*); +AES_AES_Block __fastcall aes_AES128_encrypt_block_( + AES_AES_Block plaintext, + const AES_AES128_RoundKeys*); -AesNI_AES_Block __fastcall aesni_AES192_encrypt_block_( - AesNI_AES_Block plaintext, - const AesNI_AES192_RoundKeys*); +AES_AES_Block __fastcall aes_AES192_encrypt_block_( + AES_AES_Block plaintext, + const AES_AES192_RoundKeys*); -AesNI_AES_Block __fastcall aesni_AES256_encrypt_block_( - AesNI_AES_Block plaintext, - const AesNI_AES256_RoundKeys*); +AES_AES_Block __fastcall aes_AES256_encrypt_block_( + AES_AES_Block plaintext, + const AES_AES256_RoundKeys*); -AesNI_AES_Block __fastcall aesni_AES128_decrypt_block_( - AesNI_AES_Block ciphertext, - const AesNI_AES128_RoundKeys*); +AES_AES_Block __fastcall aes_AES128_decrypt_block_( + AES_AES_Block ciphertext, + const AES_AES128_RoundKeys*); -AesNI_AES_Block __fastcall aesni_AES192_decrypt_block_( - AesNI_AES_Block ciphertext, - const AesNI_AES192_RoundKeys*); +AES_AES_Block __fastcall aes_AES192_decrypt_block_( + AES_AES_Block ciphertext, + const AES_AES192_RoundKeys*); -AesNI_AES_Block __fastcall aesni_AES256_decrypt_block_( - AesNI_AES_Block ciphertext, - const AesNI_AES256_RoundKeys*); +AES_AES_Block __fastcall aes_AES256_decrypt_block_( + AES_AES_Block ciphertext, + const AES_AES256_RoundKeys*); -static __inline AesNI_AES_Block __fastcall aesni_AES_xor_blocks( - AesNI_AES_Block a, - AesNI_AES_Block b) +static __inline AES_AES_Block __fastcall aes_AES_xor_blocks( + AES_AES_Block a, + AES_AES_Block b) { - return aesni_xor_block128(a, b); + return aes_xor_block128(a, b); } -static __inline AesNI_AES_Block __fastcall aesni_AES128_xor_blocks( - AesNI_AES128_Block a, - AesNI_AES128_Block b) +static __inline AES_AES_Block __fastcall aes_AES128_xor_blocks( + AES_AES128_Block a, + AES_AES128_Block b) { - return aesni_AES_xor_blocks(a, b); + return aes_AES_xor_blocks(a, b); } -static __inline AesNI_AES_Block __fastcall aesni_AES192_xor_blocks( - AesNI_AES192_Block a, - AesNI_AES192_Block b) +static __inline AES_AES_Block __fastcall aes_AES192_xor_blocks( + AES_AES192_Block a, + AES_AES192_Block b) { - return aesni_AES_xor_blocks(a, b); + return aes_AES_xor_blocks(a, b); } -static __inline AesNI_AES_Block __fastcall aesni_AES256_xor_blocks( - AesNI_AES256_Block a, - AesNI_AES256_Block b) +static __inline AES_AES_Block __fastcall aes_AES256_xor_blocks( + AES_AES256_Block a, + AES_AES256_Block b) { - return aesni_AES_xor_blocks(a, b); + return aes_AES_xor_blocks(a, b); } -static __inline AesNI_AES_Block __fastcall aesni_AES_inc_block( - AesNI_AES_Block block) +static __inline AES_AES_Block __fastcall aes_AES_inc_block( + AES_AES_Block block) { - block = aesni_reverse_byte_order_block128(block); - block = aesni_inc_block128(block); - return aesni_reverse_byte_order_block128(block); + block = aes_reverse_byte_order_block128(block); + block = aes_inc_block128(block); + return aes_reverse_byte_order_block128(block); } -static __inline AesNI_AES_Block __fastcall aesni_AES128_inc_block( - AesNI_AES128_Block block) +static __inline AES_AES_Block __fastcall aes_AES128_inc_block( + AES_AES128_Block block) { - return aesni_AES_inc_block(block); + return aes_AES_inc_block(block); } -static __inline AesNI_AES_Block __fastcall aesni_AES192_inc_block( - AesNI_AES192_Block block) +static __inline AES_AES_Block __fastcall aes_AES192_inc_block( + AES_AES192_Block block) { - return aesni_AES_inc_block(block); + return aes_AES_inc_block(block); } -static __inline AesNI_AES_Block __fastcall aesni_AES256_inc_block( - AesNI_AES256_Block block) +static __inline AES_AES_Block __fastcall aes_AES256_inc_block( + AES_AES256_Block block) { - return aesni_AES_inc_block(block); + return aes_AES_inc_block(block); } -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); +AES_ENCRYPT_BLOCK_ECB(AES128); +AES_DECRYPT_BLOCK_ECB(AES128); +AES_ENCRYPT_BLOCK_CBC(AES128); +AES_DECRYPT_BLOCK_CBC(AES128); +AES_ENCRYPT_BLOCK_CFB(AES128); +AES_DECRYPT_BLOCK_CFB(AES128); +AES_ENCRYPT_BLOCK_OFB(AES128); +AES_DECRYPT_BLOCK_OFB(AES128); +AES_ENCRYPT_BLOCK_CTR(AES128); +AES_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); +AES_ENCRYPT_BLOCK_ECB(AES192); +AES_DECRYPT_BLOCK_ECB(AES192); +AES_ENCRYPT_BLOCK_CBC(AES192); +AES_DECRYPT_BLOCK_CBC(AES192); +AES_ENCRYPT_BLOCK_CFB(AES192); +AES_DECRYPT_BLOCK_CFB(AES192); +AES_ENCRYPT_BLOCK_OFB(AES192); +AES_DECRYPT_BLOCK_OFB(AES192); +AES_ENCRYPT_BLOCK_CTR(AES192); +AES_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); +AES_ENCRYPT_BLOCK_ECB(AES256); +AES_DECRYPT_BLOCK_ECB(AES256); +AES_ENCRYPT_BLOCK_CBC(AES256); +AES_DECRYPT_BLOCK_CBC(AES256); +AES_ENCRYPT_BLOCK_CFB(AES256); +AES_DECRYPT_BLOCK_CFB(AES256); +AES_ENCRYPT_BLOCK_OFB(AES256); +AES_DECRYPT_BLOCK_OFB(AES256); +AES_ENCRYPT_BLOCK_CTR(AES256); +AES_DECRYPT_BLOCK_CTR(AES256); /** * \brief Expands an AES-128 key into 10 encryption round keys. @@ -435,13 +435,13 @@ AESNI_DECRYPT_BLOCK_CTR(AES256); * \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 aes_AES128_expand_key( + const AES_AES128_Key* key, + AES_AES128_RoundKeys* encryption_keys) { assert(encryption_keys); - aesni_AES128_expand_key_(key->key, encryption_keys); + aes_AES128_expand_key_(key->key, encryption_keys); } /** @@ -450,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 aes_AES128_derive_decryption_keys( + const AES_AES128_RoundKeys* encryption_keys, + AES_AES128_RoundKeys* decryption_keys) { assert(encryption_keys); assert(decryption_keys); - aesni_AES128_derive_decryption_keys_(encryption_keys, decryption_keys); + aes_AES128_derive_decryption_keys_(encryption_keys, decryption_keys); } /** @@ -466,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 aes_AES192_expand_key( + const AES_AES192_Key* key, + AES_AES192_RoundKeys* encryption_keys) { assert(key); assert(encryption_keys); - aesni_AES192_expand_key_(key->lo, key->hi, encryption_keys); + aes_AES192_expand_key_(key->lo, key->hi, encryption_keys); } /** @@ -482,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 aes_AES192_derive_decryption_keys( + const AES_AES192_RoundKeys* encryption_keys, + AES_AES192_RoundKeys* decryption_keys) { assert(encryption_keys); assert(decryption_keys); - aesni_AES192_derive_decryption_keys_(encryption_keys, decryption_keys); + aes_AES192_derive_decryption_keys_(encryption_keys, decryption_keys); } /** @@ -498,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 aes_AES256_expand_key( + const AES_AES256_Key* key, + AES_AES256_RoundKeys* encryption_keys) { assert(key); assert(encryption_keys); - aesni_AES256_expand_key_(key->lo, key->hi, encryption_keys); + aes_AES256_expand_key_(key->lo, key->hi, encryption_keys); } /** @@ -514,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 aes_AES256_derive_decryption_keys( + const AES_AES256_RoundKeys* encryption_keys, + AES_AES256_RoundKeys* decryption_keys) { assert(encryption_keys); assert(decryption_keys); - aesni_AES256_derive_decryption_keys_(encryption_keys, decryption_keys); + aes_AES256_derive_decryption_keys_(encryption_keys, decryption_keys); } #ifdef __cplusplus diff --git a/include/aes/algorithm.h b/include/aes/algorithm.h index a73b412..61b211d 100644 --- a/include/aes/algorithm.h +++ b/include/aes/algorithm.h @@ -15,11 +15,11 @@ extern "C" typedef enum { - AESNI_AES128, - AESNI_AES192, - AESNI_AES256, + AES_AES128, + AES_AES192, + AES_AES256, } -AesNI_Algorithm; +AES_Algorithm; #ifdef __cplusplus } diff --git a/include/aes/all.h b/include/aes/all.h index bbea6f9..363a9a8 100644 --- a/include/aes/all.h +++ b/include/aes/all.h @@ -12,7 +12,7 @@ #pragma once /** - * \defgroup aesni AesNI + * \defgroup aes AES */ #include "aes.h" diff --git a/include/aes/box.h b/include/aes/box.h index 58517e1..dc5bc50 100644 --- a/include/aes/box.h +++ b/include/aes/box.h @@ -19,65 +19,65 @@ extern "C" { #endif -AesNI_StatusCode aesni_box_init( - AesNI_Box* box, - AesNI_Algorithm algorithm, - const AesNI_BoxKey* box_key, - AesNI_Mode mode, - const AesNI_BoxBlock* iv, - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_box_init( + AES_Box* box, + AES_Algorithm algorithm, + const AES_BoxKey* box_key, + AES_Mode mode, + const AES_BoxBlock* iv, + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_box_parse_key( - AesNI_BoxKey* dest, - AesNI_Algorithm algorithm, +AES_StatusCode aes_box_parse_key( + AES_BoxKey* dest, + AES_Algorithm algorithm, const char* src, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_box_parse_block( - AesNI_BoxBlock* dest, - AesNI_Algorithm algorithm, +AES_StatusCode aes_box_parse_block( + AES_BoxBlock* dest, + AES_Algorithm algorithm, const char* src, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_box_format_key( - AesNI_BoxKeyString* dest, - AesNI_Algorithm algorithm, - const AesNI_BoxKey* src, - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_box_format_key( + AES_BoxKeyString* dest, + AES_Algorithm algorithm, + const AES_BoxKey* src, + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_box_format_block( - AesNI_BoxBlockString* dest, - AesNI_Algorithm algorithm, - const AesNI_BoxBlock* src, - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_box_format_block( + AES_BoxBlockString* dest, + AES_Algorithm algorithm, + const AES_BoxBlock* src, + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_box_encrypt_block( - AesNI_Box* box, - const AesNI_BoxBlock* plaintext, - AesNI_BoxBlock* ciphertext, - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_box_encrypt_block( + AES_Box* box, + const AES_BoxBlock* plaintext, + AES_BoxBlock* ciphertext, + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_box_decrypt_block( - AesNI_Box* box, - const AesNI_BoxBlock* ciphertext, - AesNI_BoxBlock* plaintext, - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_box_decrypt_block( + AES_Box* box, + const AES_BoxBlock* ciphertext, + AES_BoxBlock* plaintext, + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_box_encrypt_buffer( - AesNI_Box* box, +AES_StatusCode aes_box_encrypt_buffer( + AES_Box* box, const void* src, size_t src_size, void* dest, size_t* dest_size, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_box_decrypt_buffer( - AesNI_Box* box, +AES_StatusCode aes_box_decrypt_buffer( + AES_Box* box, const void* src, size_t src_size, void* dest, size_t* dest_size, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); #ifdef __cplusplus } diff --git a/include/aes/box_aes.h b/include/aes/box_aes.h index 3d7faec..e13b39a 100644 --- a/include/aes/box_aes.h +++ b/include/aes/box_aes.h @@ -15,9 +15,9 @@ extern "C" { #endif -extern AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes128; -extern AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes192; -extern AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes256; +extern AES_BoxAlgorithmInterface aes_box_algorithm_aes128; +extern AES_BoxAlgorithmInterface aes_box_algorithm_aes192; +extern AES_BoxAlgorithmInterface aes_box_algorithm_aes256; #ifdef __cplusplus } diff --git a/include/aes/box_data.h b/include/aes/box_data.h index 888c7c0..bd970eb 100644 --- a/include/aes/box_data.h +++ b/include/aes/box_data.h @@ -21,135 +21,135 @@ extern "C" typedef union { - AesNI_AES128_Key aes128_key; - AesNI_AES192_Key aes192_key; - AesNI_AES256_Key aes256_key; + AES_AES128_Key aes128_key; + AES_AES192_Key aes192_key; + AES_AES256_Key aes256_key; } -AesNI_BoxKey; +AES_BoxKey; typedef union { - AesNI_AES128_RoundKeys aes128_encryption_keys; - AesNI_AES192_RoundKeys aes192_encryption_keys; - AesNI_AES256_RoundKeys aes256_encryption_keys; + AES_AES128_RoundKeys aes128_encryption_keys; + AES_AES192_RoundKeys aes192_encryption_keys; + AES_AES256_RoundKeys aes256_encryption_keys; } -AesNI_BoxEncryptionRoundKeys; +AES_BoxEncryptionRoundKeys; typedef union { - AesNI_AES128_RoundKeys aes128_decryption_keys; - AesNI_AES192_RoundKeys aes192_decryption_keys; - AesNI_AES256_RoundKeys aes256_decryption_keys; + AES_AES128_RoundKeys aes128_decryption_keys; + AES_AES192_RoundKeys aes192_decryption_keys; + AES_AES256_RoundKeys aes256_decryption_keys; } -AesNI_BoxDecryptionRoundKeys; +AES_BoxDecryptionRoundKeys; typedef union { - AesNI_AES128_KeyString aes128; - AesNI_AES192_KeyString aes192; - AesNI_AES256_KeyString aes256; + AES_AES128_KeyString aes128; + AES_AES192_KeyString aes192; + AES_AES256_KeyString aes256; } -AesNI_BoxKeyString; +AES_BoxKeyString; typedef union { - AesNI_AES_Block aes_block; + AES_AES_Block aes_block; } -AesNI_BoxBlock; +AES_BoxBlock; typedef union { - AesNI_AES_BlockString aes; + AES_AES_BlockString aes; } -AesNI_BoxBlockString; +AES_BoxBlockString; -typedef AesNI_StatusCode (*AesNI_BoxCalculateRoundKeys)( - const AesNI_BoxKey* params, - AesNI_BoxEncryptionRoundKeys*, - AesNI_BoxDecryptionRoundKeys*, - AesNI_ErrorDetails* err_details); +typedef AES_StatusCode (*AES_BoxCalculateRoundKeys)( + const AES_BoxKey* params, + AES_BoxEncryptionRoundKeys*, + AES_BoxDecryptionRoundKeys*, + AES_ErrorDetails* err_details); -typedef AesNI_StatusCode (*AesNI_BoxParseBlock)( - AesNI_BoxBlock* dest, +typedef AES_StatusCode (*AES_BoxParseBlock)( + AES_BoxBlock* dest, const char* src, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); -typedef AesNI_StatusCode (*AesNI_BoxParseKey)( - AesNI_BoxKey* dest, +typedef AES_StatusCode (*AES_BoxParseKey)( + AES_BoxKey* dest, const char* src, - AesNI_ErrorDetails* err_details); - -typedef AesNI_StatusCode (*AesNI_BoxFormatBlock)( - AesNI_BoxBlockString* dest, - const AesNI_BoxBlock* src, - AesNI_ErrorDetails* err_details); - -typedef AesNI_StatusCode (*AesNI_BoxFormatKey)( - AesNI_BoxKeyString* dest, - const AesNI_BoxKey* src, - AesNI_ErrorDetails* err_details); - -typedef AesNI_StatusCode (*AesNI_BoxEncryptBlock)( - const AesNI_BoxBlock* plaintext, - const AesNI_BoxEncryptionRoundKeys* params, - AesNI_BoxBlock* ciphertext, - AesNI_ErrorDetails* err_details); - -typedef AesNI_StatusCode (*AesNI_BoxDecryptBlock)( - const AesNI_BoxBlock* ciphertext, - const AesNI_BoxDecryptionRoundKeys* params, - AesNI_BoxBlock* plaintext, - AesNI_ErrorDetails* err_details); - -typedef AesNI_StatusCode (*AesNI_BoxXorBlock)( - AesNI_BoxBlock*, - const AesNI_BoxBlock*, - AesNI_ErrorDetails*); - -typedef AesNI_StatusCode (*AesNI_BoxIncBlock)( - AesNI_BoxBlock*, - AesNI_ErrorDetails*); - -typedef AesNI_StatusCode (*AesNI_BoxGetBlockSize)( + AES_ErrorDetails* err_details); + +typedef AES_StatusCode (*AES_BoxFormatBlock)( + AES_BoxBlockString* dest, + const AES_BoxBlock* src, + AES_ErrorDetails* err_details); + +typedef AES_StatusCode (*AES_BoxFormatKey)( + AES_BoxKeyString* dest, + const AES_BoxKey* src, + AES_ErrorDetails* err_details); + +typedef AES_StatusCode (*AES_BoxEncryptBlock)( + const AES_BoxBlock* plaintext, + const AES_BoxEncryptionRoundKeys* params, + AES_BoxBlock* ciphertext, + AES_ErrorDetails* err_details); + +typedef AES_StatusCode (*AES_BoxDecryptBlock)( + const AES_BoxBlock* ciphertext, + const AES_BoxDecryptionRoundKeys* params, + AES_BoxBlock* plaintext, + AES_ErrorDetails* err_details); + +typedef AES_StatusCode (*AES_BoxXorBlock)( + AES_BoxBlock*, + const AES_BoxBlock*, + AES_ErrorDetails*); + +typedef AES_StatusCode (*AES_BoxIncBlock)( + AES_BoxBlock*, + AES_ErrorDetails*); + +typedef AES_StatusCode (*AES_BoxGetBlockSize)( size_t*, - AesNI_ErrorDetails*); + AES_ErrorDetails*); -typedef AesNI_StatusCode (*AesNI_BoxStoreBlock)( +typedef AES_StatusCode (*AES_BoxStoreBlock)( void*, - const AesNI_BoxBlock*, - AesNI_ErrorDetails*); + const AES_BoxBlock*, + AES_ErrorDetails*); -typedef AesNI_StatusCode (*AesNI_BoxLoadBlock)( - AesNI_BoxBlock*, +typedef AES_StatusCode (*AES_BoxLoadBlock)( + AES_BoxBlock*, const void*, - AesNI_ErrorDetails*); + AES_ErrorDetails*); typedef struct { - AesNI_BoxCalculateRoundKeys calc_round_keys; - AesNI_BoxParseBlock parse_block; - AesNI_BoxParseKey parse_key; - AesNI_BoxFormatBlock format_block; - AesNI_BoxFormatKey format_key; - AesNI_BoxEncryptBlock encrypt_block; - AesNI_BoxDecryptBlock decrypt_block; - AesNI_BoxXorBlock xor_block; - AesNI_BoxIncBlock inc_block; - AesNI_BoxGetBlockSize get_block_size; - AesNI_BoxStoreBlock store_block; - AesNI_BoxLoadBlock load_block; + AES_BoxCalculateRoundKeys calc_round_keys; + AES_BoxParseBlock parse_block; + AES_BoxParseKey parse_key; + AES_BoxFormatBlock format_block; + AES_BoxFormatKey format_key; + AES_BoxEncryptBlock encrypt_block; + AES_BoxDecryptBlock decrypt_block; + AES_BoxXorBlock xor_block; + AES_BoxIncBlock inc_block; + AES_BoxGetBlockSize get_block_size; + AES_BoxStoreBlock store_block; + AES_BoxLoadBlock load_block; } -AesNI_BoxAlgorithmInterface; +AES_BoxAlgorithmInterface; typedef struct { - const AesNI_BoxAlgorithmInterface* algorithm; - AesNI_BoxEncryptionRoundKeys encryption_keys; - AesNI_BoxDecryptionRoundKeys decryption_keys; - AesNI_Mode mode; - AesNI_BoxBlock iv; + const AES_BoxAlgorithmInterface* algorithm; + AES_BoxEncryptionRoundKeys encryption_keys; + AES_BoxDecryptionRoundKeys decryption_keys; + AES_Mode mode; + AES_BoxBlock iv; } -AesNI_Box; +AES_Box; #ifdef __cplusplus } diff --git a/include/aes/data.h b/include/aes/data.h index 94cff2c..e8391cc 100644 --- a/include/aes/data.h +++ b/include/aes/data.h @@ -19,7 +19,7 @@ extern "C" /** * \brief Represents a 128-bit block. */ -typedef __m128i AesNI_Block128; +typedef __m128i AES_Block128; /** * \brief Loads a 128-bit block from a memory location. @@ -28,9 +28,9 @@ typedef __m128i AesNI_Block128; * * \return The loaded 128-bit block. */ -static __inline AesNI_Block128 aesni_load_block128(const void* src) +static __inline AES_Block128 aes_load_block128(const void* src) { - return _mm_loadu_si128((AesNI_Block128*) src); + return _mm_loadu_si128((AES_Block128*) src); } /** @@ -40,9 +40,9 @@ static __inline AesNI_Block128 aesni_load_block128(const void* src) * * \return The loaded 128-bit block. */ -static __inline AesNI_Block128 aesni_load_block128_aligned(const void* src) +static __inline AES_Block128 aes_load_block128_aligned(const void* src) { - return _mm_load_si128((AesNI_Block128*) src); + return _mm_load_si128((AES_Block128*) src); } /** @@ -52,11 +52,11 @@ static __inline AesNI_Block128 aesni_load_block128_aligned(const void* src) * * \param[in] block The block to be stored. */ -static __inline void __fastcall aesni_store_block128( +static __inline void __fastcall aes_store_block128( void* dest, - AesNI_Block128 block) + AES_Block128 block) { - _mm_storeu_si128((AesNI_Block128*) dest, block); + _mm_storeu_si128((AES_Block128*) dest, block); } /** @@ -66,11 +66,11 @@ static __inline void __fastcall aesni_store_block128( * * \param[in] block The block to be stored. */ -static __inline void __fastcall aesni_store_block128_aligned( +static __inline void __fastcall aes_store_block128_aligned( void* dest, - AesNI_Block128 block) + AES_Block128 block) { - _mm_store_si128((AesNI_Block128*) dest, block); + _mm_store_si128((AES_Block128*) dest, block); } /** @@ -81,9 +81,9 @@ static __inline void __fastcall aesni_store_block128_aligned( * * \return `a^b`. */ -static __inline AesNI_Block128 __fastcall aesni_xor_block128( - AesNI_Block128 a, - AesNI_Block128 b) +static __inline AES_Block128 __fastcall aes_xor_block128( + AES_Block128 a, + AES_Block128 b) { return _mm_xor_si128(a, b); } @@ -105,19 +105,19 @@ static __inline AesNI_Block128 __fastcall aesni_xor_block128( * * \return The built 128-bit block. */ -static __inline AesNI_Block128 __fastcall aesni_make_block128(int hi3, int hi2, int lo1, int lo0) +static __inline AES_Block128 __fastcall aes_make_block128(int hi3, int hi2, int lo1, int lo0) { return _mm_set_epi32(hi3, hi2, lo1, lo0); } -static __inline AesNI_Block128 __fastcall aesni_reverse_byte_order_block128(AesNI_Block128 block) +static __inline AES_Block128 __fastcall aes_reverse_byte_order_block128(AES_Block128 block) { - return _mm_shuffle_epi8(block, aesni_make_block128(0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f)); + return _mm_shuffle_epi8(block, aes_make_block128(0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f)); } -static __inline AesNI_Block128 __fastcall aesni_inc_block128(AesNI_Block128 x) +static __inline AES_Block128 __fastcall aes_inc_block128(AES_Block128 x) { - return _mm_add_epi32(x, aesni_make_block128(0, 0, 0, 1)); + return _mm_add_epi32(x, aes_make_block128(0, 0, 0, 1)); } #ifdef __cplusplus diff --git a/include/aes/error.h b/include/aes/error.h index a51284f..a92f17b 100644 --- a/include/aes/error.h +++ b/include/aes/error.h @@ -9,14 +9,14 @@ #pragma once /** - * \defgroup aesni_error_handling Error handling - * \ingroup aesni + * \defgroup aes_error_handling Error handling + * \ingroup aes * \brief Error data structures and formatting functions. * * Some library functions cannot fail, which is simple. * Other functions return an error code. * You can check if a function exited with an error by passing the returned - * error code to aesni_is_error(). + * error code to aes_is_error(). * * Some possibly-may-fail functions accept a pointer to an "error details" * structure. @@ -42,19 +42,19 @@ extern "C" */ typedef enum { - AESNI_SUCCESS, ///< Everything went fine - AESNI_NULL_ARGUMENT_ERROR, ///< Invalid argument value NULL - AESNI_PARSE_ERROR, ///< Couldn't parse - AESNI_INVALID_PKCS7_PADDING_ERROR, ///< Invalid PKCS7 padding while decrypting - AESNI_NOT_IMPLEMENTED_ERROR, ///< Not implemented - AESNI_MISSING_PADDING_ERROR, - AESNI_MEMORY_ALLOCATION_ERROR, + AES_SUCCESS, ///< Everything went fine + AES_NULL_ARGUMENT_ERROR, ///< Invalid argument value NULL + AES_PARSE_ERROR, ///< Couldn't parse + AES_INVALID_PKCS7_PADDING_ERROR, ///< Invalid PKCS7 padding while decrypting + AES_NOT_IMPLEMENTED_ERROR, ///< Not implemented + AES_MISSING_PADDING_ERROR, + AES_MEMORY_ALLOCATION_ERROR, } -AesNI_StatusCode; +AES_StatusCode; -static __inline int aesni_is_error(AesNI_StatusCode ec) +static __inline int aes_is_error(AES_StatusCode ec) { - return ec != AESNI_SUCCESS; + return ec != AES_SUCCESS; } /** @@ -62,7 +62,7 @@ static __inline int aesni_is_error(AesNI_StatusCode ec) * * For example, * \code{.c} - * printf("%s\n", aesni_strerror(AESNI_NULL_ARGUMENT_ERROR)); + * printf("%s\n", aes_strerror(AES_NULL_ARGUMENT_ERROR)); * \endcode * would print * \code @@ -72,16 +72,16 @@ static __inline int aesni_is_error(AesNI_StatusCode ec) * \param[in] ec The error code. * \return A pointer to a statically-allocated C string. */ -const char* aesni_strerror(AesNI_StatusCode ec); +const char* aes_strerror(AES_StatusCode ec); -#define AESNI_MAX_CALL_STACK_LENGTH 32 +#define AES_MAX_CALL_STACK_LENGTH 32 /** * \brief Stores error details: error code & possibly a few parameters. */ typedef struct { - AesNI_StatusCode ec; ///< Error code + AES_StatusCode ec; ///< Error code union { @@ -96,10 +96,10 @@ typedef struct } params; - void* call_stack[AESNI_MAX_CALL_STACK_LENGTH]; + void* call_stack[AES_MAX_CALL_STACK_LENGTH]; size_t call_stack_size; } -AesNI_ErrorDetails; +AES_ErrorDetails; /** * \brief Extracts an error code from error details. @@ -107,8 +107,8 @@ AesNI_ErrorDetails; * \param[in] err_details The error details structure. Must not be `NULL`. * \return The error code stored in the error details. */ -static __inline AesNI_StatusCode aesni_get_error_code( - const AesNI_ErrorDetails* err_details) +static __inline AES_StatusCode aes_get_error_code( + const AES_ErrorDetails* err_details) { return err_details->ec; } @@ -123,8 +123,8 @@ static __inline AesNI_StatusCode aesni_get_error_code( * error message, and the number of characters written (excluding the * terminating '\0' character) otherwise. */ -size_t aesni_format_error( - const AesNI_ErrorDetails* err_details, +size_t aes_format_error( + const AES_ErrorDetails* err_details, char* dest, size_t dest_size); @@ -133,8 +133,8 @@ size_t aesni_format_error( * * \param[out] err_details The error details structure to fill. */ -AesNI_StatusCode aesni_success( - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_success( + AES_ErrorDetails* err_details); /** * \brief Builds error details from a `NULL` argument error. @@ -142,8 +142,8 @@ AesNI_StatusCode aesni_success( * \param[out] err_details The error details structure to fill. * \param[in] param_name The parameter name. Must not be `NULL`. */ -AesNI_StatusCode aesni_error_null_argument( - AesNI_ErrorDetails* err_details, +AES_StatusCode aes_error_null_argument( + AES_ErrorDetails* err_details, const char* param_name); /** @@ -152,8 +152,8 @@ AesNI_StatusCode aesni_error_null_argument( * \param[out] err_details The error details structure to fill. * \param[in] src The string that failed to be parsed. */ -AesNI_StatusCode aesni_error_parse( - AesNI_ErrorDetails* err_details, +AES_StatusCode aes_error_parse( + AES_ErrorDetails* err_details, const char* src, const char* what); @@ -162,18 +162,18 @@ AesNI_StatusCode aesni_error_parse( * * \param[out] err_details The error details structure to fill. */ -AesNI_StatusCode aesni_error_invalid_pkcs7_padding( - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_error_invalid_pkcs7_padding( + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_error_not_implemented( - AesNI_ErrorDetails* err_details, +AES_StatusCode aes_error_not_implemented( + AES_ErrorDetails* err_details, const char* what); -AesNI_StatusCode aesni_error_missing_padding( - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_error_missing_padding( + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_error_memory_allocation( - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_error_memory_allocation( + AES_ErrorDetails* err_details); #ifdef __cplusplus } diff --git a/include/aes/mode.h b/include/aes/mode.h index 7650ec0..dccfc43 100644 --- a/include/aes/mode.h +++ b/include/aes/mode.h @@ -17,150 +17,150 @@ extern "C" typedef enum { - AESNI_ECB, - AESNI_CBC, - AESNI_CFB, - AESNI_OFB, - AESNI_CTR, + AES_ECB, + AES_CBC, + AES_CFB, + AES_OFB, + AES_CTR, } -AesNI_Mode; +AES_Mode; -#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) \ +#define AES_ENCRYPT_BLOCK_ECB(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_encrypt_block_ECB( \ + AES_## prefix ##_Block plaintext, \ + const AES_## prefix ##_RoundKeys* encryption_keys) \ { \ assert(encryption_keys); \ \ - return aesni_## prefix ##_encrypt_block_(plaintext, encryption_keys); \ + return aes_## prefix ##_encrypt_block_(plaintext, encryption_keys); \ } -#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) \ +#define AES_DECRYPT_BLOCK_ECB(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_decrypt_block_ECB( \ + AES_## prefix ##_Block ciphertext, \ + const AES_## prefix ##_RoundKeys* decryption_keys) \ { \ assert(decryption_keys); \ \ - return aesni_## prefix ##_decrypt_block_(ciphertext, decryption_keys); \ + return aes_## prefix ##_decrypt_block_(ciphertext, decryption_keys); \ } -#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) \ +#define AES_ENCRYPT_BLOCK_CBC(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_encrypt_block_CBC( \ + AES_## prefix ##_Block plaintext, \ + const AES_## prefix ##_RoundKeys* encryption_keys, \ + AES_## prefix ##_Block init_vector, \ + AES_## prefix ##_Block* next_init_vector) \ { \ assert(encryption_keys); \ assert(next_init_vector); \ \ - return *next_init_vector = aesni_## prefix ##_encrypt_block_( \ - aesni_## prefix ##_xor_blocks(plaintext, init_vector), encryption_keys); \ + return *next_init_vector = aes_## prefix ##_encrypt_block_( \ + aes_## prefix ##_xor_blocks(plaintext, init_vector), encryption_keys); \ } -#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) \ +#define AES_DECRYPT_BLOCK_CBC(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_decrypt_block_CBC( \ + AES_## prefix ##_Block ciphertext, \ + const AES_## prefix ##_RoundKeys* decryption_keys, \ + AES_## prefix ##_Block init_vector, \ + AES_## prefix ##_Block* next_init_vector) \ { \ assert(decryption_keys); \ assert(next_init_vector); \ \ - AesNI_## prefix ##_Block plaintext = aesni_## prefix ##_xor_blocks( \ - aesni_## prefix ##_decrypt_block_(ciphertext, decryption_keys), init_vector); \ + AES_## prefix ##_Block plaintext = aes_## prefix ##_xor_blocks( \ + aes_## prefix ##_decrypt_block_(ciphertext, decryption_keys), init_vector); \ *next_init_vector = ciphertext; \ return plaintext; \ } -#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) \ +#define AES_ENCRYPT_BLOCK_CFB(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_encrypt_block_CFB( \ + AES_## prefix ##_Block plaintext, \ + const AES_## prefix ##_RoundKeys* encryption_keys, \ + AES_## prefix ##_Block init_vector, \ + AES_## prefix ##_Block* next_init_vector) \ { \ assert(encryption_keys); \ assert(next_init_vector); \ \ - return *next_init_vector = aesni_## prefix ##_xor_blocks( \ - aesni_## prefix ##_encrypt_block_(init_vector, encryption_keys), plaintext); \ + return *next_init_vector = aes_## prefix ##_xor_blocks( \ + aes_## prefix ##_encrypt_block_(init_vector, encryption_keys), plaintext); \ } -#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) \ +#define AES_DECRYPT_BLOCK_CFB(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_decrypt_block_CFB( \ + AES_## prefix ##_Block ciphertext, \ + const AES_## prefix ##_RoundKeys* encryption_keys, \ + AES_## prefix ##_Block init_vector, \ + AES_## prefix ##_Block* next_init_vector) \ { \ assert(encryption_keys); \ assert(next_init_vector); \ \ - AesNI_## prefix ##_Block plaintext = aesni_## prefix ##_xor_blocks( \ - aesni_## prefix ##_encrypt_block_(init_vector, encryption_keys), ciphertext); \ + AES_## prefix ##_Block plaintext = aes_## prefix ##_xor_blocks( \ + aes_## prefix ##_encrypt_block_(init_vector, encryption_keys), ciphertext); \ *next_init_vector = ciphertext; \ return plaintext; \ } -#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) \ +#define AES_ENCRYPT_BLOCK_OFB(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_encrypt_block_OFB( \ + AES_## prefix ##_Block plaintext, \ + const AES_## prefix ##_RoundKeys* encryption_keys, \ + AES_## prefix ##_Block init_vector, \ + AES_## prefix ##_Block* next_init_vector) \ { \ assert(encryption_keys); \ assert(next_init_vector); \ \ - AesNI_## prefix ##_Block tmp = aesni_## prefix ##_encrypt_block_(init_vector, encryption_keys); \ + AES_## prefix ##_Block tmp = aes_## prefix ##_encrypt_block_(init_vector, encryption_keys); \ *next_init_vector = tmp; \ - return aesni_## prefix ##_xor_blocks(tmp, plaintext); \ + return aes_## prefix ##_xor_blocks(tmp, plaintext); \ } -#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) \ +#define AES_DECRYPT_BLOCK_OFB(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_decrypt_block_OFB( \ + AES_## prefix ##_Block ciphertext, \ + const AES_## prefix ##_RoundKeys* encryption_keys, \ + AES_## prefix ##_Block init_vector, \ + AES_## prefix ##_Block* next_init_vector) \ { \ assert(encryption_keys); \ assert(next_init_vector); \ \ - return aesni_## prefix ##_encrypt_block_OFB( \ + return aes_## prefix ##_encrypt_block_OFB( \ ciphertext, encryption_keys, init_vector, 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) \ +#define AES_ENCRYPT_BLOCK_CTR(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_encrypt_block_CTR( \ + AES_## prefix ##_Block plaintext, \ + const AES_## prefix ##_RoundKeys* encryption_keys, \ + AES_## prefix ##_Block init_vector, \ + AES_## prefix ##_Block* next_init_vector) \ { \ assert(encryption_keys); \ assert(next_init_vector); \ \ - 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); \ + AES_## prefix ##_Block ciphertext = aes_## prefix ##_xor_blocks( \ + plaintext, aes_## prefix ##_encrypt_block_(init_vector, encryption_keys)); \ + *next_init_vector = aes_## prefix ##_inc_block(init_vector); \ return ciphertext; \ } -#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) \ +#define AES_DECRYPT_BLOCK_CTR(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_decrypt_block_CTR( \ + AES_## prefix ##_Block ciphertext, \ + const AES_## prefix ##_RoundKeys* encryption_keys, \ + AES_## prefix ##_Block init_vector, \ + AES_## prefix ##_Block* next_init_vector) \ { \ assert(encryption_keys); \ assert(next_init_vector); \ \ - return aesni_## prefix ##_encrypt_block_CTR( \ + return aes_## prefix ##_encrypt_block_CTR( \ ciphertext, encryption_keys, init_vector, next_init_vector); \ } diff --git a/include/aes/padding.h b/include/aes/padding.h index 7f19b18..7f0db65 100644 --- a/include/aes/padding.h +++ b/include/aes/padding.h @@ -19,22 +19,22 @@ extern "C" typedef enum { - AESNI_PADDING_PKCS7, + AES_PADDING_PKCS7, } -AesNI_PaddingMethod; +AES_PaddingMethod; -AesNI_StatusCode aesni_extract_padding_size( - AesNI_PaddingMethod, +AES_StatusCode aes_extract_padding_size( + AES_PaddingMethod, const void* src, size_t src_size, size_t* padding_size, - AesNI_ErrorDetails*); + AES_ErrorDetails*); -AesNI_StatusCode aesni_fill_with_padding( - AesNI_PaddingMethod, +AES_StatusCode aes_fill_with_padding( + AES_PaddingMethod, void* dest, size_t padding_size, - AesNI_ErrorDetails*); + AES_ErrorDetails*); #ifdef __cplusplus } @@ -12,48 +12,48 @@ #include <stdio.h> #include <string.h> -AesNI_StatusCode aesni_AES_format_block( - AesNI_AES_BlockString* str, - const AesNI_AES_Block* block, - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_AES_format_block( + AES_AES_BlockString* str, + const AES_AES_Block* block, + AES_ErrorDetails* err_details) { assert(str); assert(block); if (str == NULL) - return aesni_error_null_argument(err_details, "str"); + return aes_error_null_argument(err_details, "str"); if (block == NULL) - return aesni_error_null_argument(err_details, "block"); + return aes_error_null_argument(err_details, "block"); char* cursor = str->str; __declspec(align(16)) unsigned char bytes[16]; - aesni_store_block128_aligned(bytes, *block); + aes_store_block128_aligned(bytes, *block); for (int i = 0; i < 16; ++i, cursor += 2) sprintf(cursor, "%02x", bytes[i]); *cursor = '\0'; - return AESNI_SUCCESS; + return AES_SUCCESS; } -AesNI_StatusCode aesni_AES_format_block_as_matrix( - AesNI_AES_BlockMatrixString* str, - const AesNI_AES_Block* block, - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_AES_format_block_as_matrix( + AES_AES_BlockMatrixString* str, + const AES_AES_Block* block, + AES_ErrorDetails* err_details) { assert(str); assert(block); if (str == NULL) - return aesni_error_null_argument(err_details, "str"); + return aes_error_null_argument(err_details, "str"); if (block == NULL) - return aesni_error_null_argument(err_details, "block"); + return aes_error_null_argument(err_details, "block"); char* cursor = str->str; __declspec(align(16)) unsigned char bytes[4][4]; - aesni_store_block128_aligned(bytes, *block); + aes_store_block128_aligned(bytes, *block); for (int i = 0; i < 4; ++i, cursor += 3) { @@ -63,59 +63,59 @@ AesNI_StatusCode aesni_AES_format_block_as_matrix( } *cursor = '\0'; - return AESNI_SUCCESS; + return AES_SUCCESS; } -AesNI_StatusCode aesni_AES_print_block( - const AesNI_AES_Block* block, - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_AES_print_block( + const AES_AES_Block* block, + AES_ErrorDetails* err_details) { assert(block); if (block == NULL) - return aesni_error_null_argument(err_details, "block"); + return aes_error_null_argument(err_details, "block"); - AesNI_StatusCode ec = AESNI_SUCCESS; - AesNI_AES_BlockString str; + AES_StatusCode ec = AES_SUCCESS; + AES_AES_BlockString str; - if (aesni_is_error(ec = aesni_AES_format_block(&str, block, err_details))) + if (aes_is_error(ec = aes_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_ErrorDetails* err_details) +AES_StatusCode aes_AES_print_block_as_matrix( + const AES_AES_Block* block, + AES_ErrorDetails* err_details) { assert(block); if (block == NULL) - return aesni_error_null_argument(err_details, "block"); + return aes_error_null_argument(err_details, "block"); - AesNI_StatusCode ec = AESNI_SUCCESS; - AesNI_AES_BlockMatrixString str; + AES_StatusCode ec = AES_SUCCESS; + AES_AES_BlockMatrixString str; - if (aesni_is_error(ec = aesni_AES_format_block_as_matrix(&str, block, err_details))) + if (aes_is_error(ec = aes_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, +AES_StatusCode aes_AES_parse_block( + AES_AES_Block* dest, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { assert(dest); assert(src); if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); if (src == NULL) - return aesni_error_null_argument(err_details, "src"); + return aes_error_null_argument(err_details, "src"); const char* cursor = src; @@ -126,58 +126,58 @@ AesNI_StatusCode aesni_AES_parse_block( int n; unsigned int byte; if (sscanf(cursor, "%2x%n", &byte, &n) != 1) - return aesni_error_parse(err_details, src, "a 128-bit block"); + return aes_error_parse(err_details, src, "a 128-bit block"); bytes[i] = (unsigned char) byte; cursor += n; } - *dest = aesni_load_block128_aligned(bytes); - return AESNI_SUCCESS; + *dest = aes_load_block128_aligned(bytes); + return AES_SUCCESS; } -AesNI_StatusCode aesni_AES128_format_key( - AesNI_AES128_KeyString* str, - const AesNI_AES128_Key* key, - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_AES128_format_key( + AES_AES128_KeyString* str, + const AES_AES128_Key* key, + AES_ErrorDetails* err_details) { assert(str); assert(key); if (str == NULL) - return aesni_error_null_argument(err_details, "str"); + return aes_error_null_argument(err_details, "str"); if (key == NULL) - return aesni_error_null_argument(err_details, "key"); + return aes_error_null_argument(err_details, "key"); char* cursor = str->str; __declspec(align(16)) unsigned char bytes[16]; - aesni_store_block128_aligned(bytes, key->key); + aes_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; + return AES_SUCCESS; } -AesNI_StatusCode aesni_AES192_format_key( - AesNI_AES192_KeyString* str, - const AesNI_AES192_Key* key, - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_AES192_format_key( + AES_AES192_KeyString* str, + const AES_AES192_Key* key, + AES_ErrorDetails* err_details) { assert(str); assert(key); if (str == NULL) - return aesni_error_null_argument(err_details, "str"); + return aes_error_null_argument(err_details, "str"); if (key == NULL) - return aesni_error_null_argument(err_details, "key"); + return aes_error_null_argument(err_details, "key"); char* cursor = str->str; { __declspec(align(16)) unsigned char bytes[16]; - aesni_store_block128_aligned(bytes, key->lo); + aes_store_block128_aligned(bytes, key->lo); for (int i = 0; i < 16; ++i, cursor += 2) sprintf(cursor, "%02x", bytes[i]); @@ -185,34 +185,34 @@ AesNI_StatusCode aesni_AES192_format_key( { __declspec(align(16)) unsigned char bytes[16]; - aesni_store_block128_aligned(bytes, key->hi); + aes_store_block128_aligned(bytes, key->hi); for (int i = 0; i < 8; ++i, cursor += 2) sprintf(cursor, "%02x", bytes[i]); } *cursor = '\0'; - return AESNI_SUCCESS; + return AES_SUCCESS; } -AesNI_StatusCode aesni_AES256_format_key( - AesNI_AES256_KeyString* str, - const AesNI_AES256_Key* key, - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_AES256_format_key( + AES_AES256_KeyString* str, + const AES_AES256_Key* key, + AES_ErrorDetails* err_details) { assert(str); assert(key); if (str == NULL) - return aesni_error_null_argument(err_details, "str"); + return aes_error_null_argument(err_details, "str"); if (key == NULL) - return aesni_error_null_argument(err_details, "key"); + return aes_error_null_argument(err_details, "key"); char* cursor = str->str; { __declspec(align(16)) unsigned char bytes[16]; - aesni_store_block128_aligned(bytes, key->lo); + aes_store_block128_aligned(bytes, key->lo); for (int i = 0; i < 16; ++i, cursor += 2) sprintf(cursor, "%02x", bytes[i]); @@ -220,81 +220,81 @@ AesNI_StatusCode aesni_AES256_format_key( { __declspec(align(16)) unsigned char bytes[16]; - aesni_store_block128_aligned(bytes, key->hi); + aes_store_block128_aligned(bytes, key->hi); for (int i = 0; i < 16; ++i, cursor += 2) sprintf(cursor, "%02x", bytes[i]); } *cursor = '\0'; - return AESNI_SUCCESS; + return AES_SUCCESS; } -AesNI_StatusCode aesni_AES128_print_key( - const AesNI_AES128_Key* key, - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_AES128_print_key( + const AES_AES128_Key* key, + AES_ErrorDetails* err_details) { - return aesni_AES_print_block(&key->key, err_details); + return aes_AES_print_block(&key->key, err_details); } -AesNI_StatusCode aesni_AES192_print_key( - const AesNI_AES192_Key* key, - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_AES192_print_key( + const AES_AES192_Key* key, + AES_ErrorDetails* err_details) { assert(key); if (key == NULL) - return aesni_error_null_argument(err_details, "key"); + return aes_error_null_argument(err_details, "key"); - AesNI_StatusCode ec = AESNI_SUCCESS; - AesNI_AES192_KeyString str; + AES_StatusCode ec = AES_SUCCESS; + AES_AES192_KeyString str; - if (aesni_is_error(ec = aesni_AES192_format_key(&str, key, err_details))) + if (aes_is_error(ec = aes_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_ErrorDetails* err_details) +AES_StatusCode aes_AES256_print_key( + const AES_AES256_Key* key, + AES_ErrorDetails* err_details) { assert(key); if (key == NULL) - return aesni_error_null_argument(err_details, "key"); + return aes_error_null_argument(err_details, "key"); - AesNI_StatusCode ec = AESNI_SUCCESS; - AesNI_AES256_KeyString str; + AES_StatusCode ec = AES_SUCCESS; + AES_AES256_KeyString str; - if (aesni_is_error(ec = aesni_AES256_format_key(&str, key, err_details))) + if (aes_is_error(ec = aes_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, +AES_StatusCode aes_AES128_parse_key( + AES_AES128_Key* dest, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - return aesni_AES_parse_block(&dest->key, src, err_details); + return aes_AES_parse_block(&dest->key, src, err_details); } -AesNI_StatusCode aesni_AES192_parse_key( - AesNI_AES192_Key* dest, +AES_StatusCode aes_AES192_parse_key( + AES_AES192_Key* dest, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { assert(dest); assert(src); if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); if (src == NULL) - return aesni_error_null_argument(err_details, "src"); + return aes_error_null_argument(err_details, "src"); const char* cursor = src; @@ -306,12 +306,12 @@ AesNI_StatusCode aesni_AES192_parse_key( int n; unsigned int byte; if (sscanf(cursor, "%2x%n", &byte, &n) != 1) - return aesni_error_parse(err_details, src, "a 192-bit block"); + return aes_error_parse(err_details, src, "a 192-bit block"); bytes[i] = (unsigned char) byte; cursor += n; } - dest->lo = aesni_load_block128_aligned(bytes); + dest->lo = aes_load_block128_aligned(bytes); } { @@ -322,30 +322,30 @@ AesNI_StatusCode aesni_AES192_parse_key( int n; unsigned int byte; if (sscanf(cursor, "%2x%n", &byte, &n) != 1) - return aesni_error_parse(err_details, src, "a 192-bit block"); + return aes_error_parse(err_details, src, "a 192-bit block"); bytes[i] = (unsigned char) byte; cursor += n; } memset(bytes + 8, 0x00, 8); - dest->hi = aesni_load_block128_aligned(bytes); + dest->hi = aes_load_block128_aligned(bytes); } - return AESNI_SUCCESS; + return AES_SUCCESS; } -AesNI_StatusCode aesni_AES256_parse_key( - AesNI_AES256_Key* dest, +AES_StatusCode aes_AES256_parse_key( + AES_AES256_Key* dest, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { assert(dest); assert(src); if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); if (src == NULL) - return aesni_error_null_argument(err_details, "src"); + return aes_error_null_argument(err_details, "src"); const char* cursor = src; @@ -357,12 +357,12 @@ AesNI_StatusCode aesni_AES256_parse_key( int n; unsigned int byte; if (sscanf(cursor, "%2x%n", &byte, &n) != 1) - return aesni_error_parse(err_details, src, "a 256-bit block"); + return aes_error_parse(err_details, src, "a 256-bit block"); bytes[i] = (unsigned char) byte; cursor += n; } - dest->lo = aesni_load_block128_aligned(bytes); + dest->lo = aes_load_block128_aligned(bytes); } { @@ -373,13 +373,13 @@ AesNI_StatusCode aesni_AES256_parse_key( int n; unsigned int byte; if (sscanf(cursor, "%2x%n", &byte, &n) != 1) - return aesni_error_parse(err_details, src, "a 256-bit block"); + return aes_error_parse(err_details, src, "a 256-bit block"); bytes[i] = (unsigned char) byte; cursor += n; } - dest->hi = aesni_load_block128_aligned(bytes); + dest->hi = aes_load_block128_aligned(bytes); } - return AESNI_SUCCESS; + return AES_SUCCESS; } diff --git a/src/asm/aes128.asm b/src/asm/aes128.asm index af9c839..106e82b 100644 --- a/src/asm/aes128.asm +++ b/src/asm/aes128.asm @@ -8,7 +8,7 @@ .code -@aesni_AES128_encrypt_block_@20 proc +@aes_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 +@aes_AES128_encrypt_block_@20 endp -@aesni_AES128_decrypt_block_@20 proc +@aes_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 +@aes_AES128_decrypt_block_@20 endp -@aesni_AES128_expand_key_@20 proc +@aes_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 +@aes_AES128_expand_key_@20 endp -@aesni_AES128_derive_decryption_keys_@8 proc +@aes_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 +@aes_AES128_derive_decryption_keys_@8 endp end diff --git a/src/asm/aes192.asm b/src/asm/aes192.asm index 05e4f08..c90f55a 100644 --- a/src/asm/aes192.asm +++ b/src/asm/aes192.asm @@ -8,7 +8,7 @@ .code -@aesni_AES192_encrypt_block_@20 proc +@aes_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 +@aes_AES192_encrypt_block_@20 endp -@aesni_AES192_decrypt_block_@20 proc +@aes_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 +@aes_AES192_decrypt_block_@20 endp -@aesni_AES192_expand_key_@36 proc +@aes_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 +@aes_AES192_expand_key_@36 endp -@aesni_AES192_derive_decryption_keys_@8 proc +@aes_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 +@aes_AES192_derive_decryption_keys_@8 endp end diff --git a/src/asm/aes256.asm b/src/asm/aes256.asm index 0d19c26..143dd5b 100644 --- a/src/asm/aes256.asm +++ b/src/asm/aes256.asm @@ -8,7 +8,7 @@ .code -@aesni_AES256_encrypt_block_@20 proc +@aes_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 +@aes_AES256_encrypt_block_@20 endp -@aesni_AES256_decrypt_block_@20 proc +@aes_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 +@aes_AES256_decrypt_block_@20 endp -@aesni_AES256_expand_key_@36 proc +@aes_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 +@aes_AES256_expand_key_@36 endp -@aesni_AES256_derive_decryption_keys_@8 proc +@aes_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 +@aes_AES256_derive_decryption_keys_@8 endp end @@ -11,26 +11,26 @@ #include <stdlib.h> #include <string.h> -static const AesNI_BoxAlgorithmInterface* aesni_box_algorithms[] = +static const AES_BoxAlgorithmInterface* aes_box_algorithms[] = { - &aesni_box_algorithm_aes128, - &aesni_box_algorithm_aes192, - &aesni_box_algorithm_aes256, + &aes_box_algorithm_aes128, + &aes_box_algorithm_aes192, + &aes_box_algorithm_aes256, }; -AesNI_StatusCode aesni_box_init( - AesNI_Box* box, - AesNI_Algorithm algorithm, - const AesNI_BoxKey* box_key, - AesNI_Mode mode, - const AesNI_BoxBlock* iv, - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_box_init( + AES_Box* box, + AES_Algorithm algorithm, + const AES_BoxKey* box_key, + AES_Mode mode, + const AES_BoxBlock* iv, + AES_ErrorDetails* err_details) { - AesNI_StatusCode status = AESNI_SUCCESS; + AES_StatusCode status = AES_SUCCESS; - box->algorithm = aesni_box_algorithms[algorithm]; + box->algorithm = aes_box_algorithms[algorithm]; - if (aesni_is_error(status = box->algorithm->calc_round_keys( + if (aes_is_error(status = box->algorithm->calc_round_keys( box_key, &box->encryption_keys, &box->decryption_keys, @@ -44,30 +44,30 @@ AesNI_StatusCode aesni_box_init( return status; } -static AesNI_StatusCode aesni_box_encrypt_block_ecb( - AesNI_Box* box, - const AesNI_BoxBlock* input, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_encrypt_block_ecb( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { return box->algorithm->encrypt_block( input, &box->encryption_keys, output, err_details); } -static AesNI_StatusCode aesni_box_encrypt_block_cbc( - AesNI_Box* box, - const AesNI_BoxBlock* input, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_encrypt_block_cbc( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { - AesNI_StatusCode status = AESNI_SUCCESS; - AesNI_BoxBlock xored_input = *input; + AES_StatusCode status = AES_SUCCESS; + AES_BoxBlock xored_input = *input; - if (aesni_is_error(status = box->algorithm->xor_block( + if (aes_is_error(status = box->algorithm->xor_block( &xored_input, &box->iv, err_details))) return status; - if (aesni_is_error(status = box->algorithm->encrypt_block( + if (aes_is_error(status = box->algorithm->encrypt_block( &xored_input, &box->encryption_keys, output, err_details))) return status; @@ -75,19 +75,19 @@ static AesNI_StatusCode aesni_box_encrypt_block_cbc( return status; } -static AesNI_StatusCode aesni_box_encrypt_block_cfb( - AesNI_Box* box, - const AesNI_BoxBlock* input, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_encrypt_block_cfb( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { - AesNI_StatusCode status = AESNI_SUCCESS; + AES_StatusCode status = AES_SUCCESS; - if (aesni_is_error(status = box->algorithm->encrypt_block( + if (aes_is_error(status = box->algorithm->encrypt_block( &box->iv, &box->encryption_keys, output, err_details))) return status; - if (aesni_is_error(status = box->algorithm->xor_block( + if (aes_is_error(status = box->algorithm->xor_block( output, input, err_details))) return status; @@ -95,98 +95,98 @@ static AesNI_StatusCode aesni_box_encrypt_block_cfb( return status; } -static AesNI_StatusCode aesni_box_encrypt_block_ofb( - AesNI_Box* box, - const AesNI_BoxBlock* input, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_encrypt_block_ofb( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { - AesNI_StatusCode status = AESNI_SUCCESS; + AES_StatusCode status = AES_SUCCESS; - if (aesni_is_error(status = box->algorithm->encrypt_block( + if (aes_is_error(status = box->algorithm->encrypt_block( &box->iv, &box->encryption_keys, &box->iv, err_details))) return status; *output = box->iv; - if (aesni_is_error(status = box->algorithm->xor_block( + if (aes_is_error(status = box->algorithm->xor_block( output, input, err_details))) return status; return status; } -static AesNI_StatusCode aesni_box_encrypt_block_ctr( - AesNI_Box* box, - const AesNI_BoxBlock* input, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_encrypt_block_ctr( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { - AesNI_StatusCode status = AESNI_SUCCESS; + AES_StatusCode status = AES_SUCCESS; - if (aesni_is_error(status = box->algorithm->encrypt_block( + if (aes_is_error(status = box->algorithm->encrypt_block( &box->iv, &box->encryption_keys, output, err_details))) return status; - if (aesni_is_error(status = box->algorithm->xor_block( + if (aes_is_error(status = box->algorithm->xor_block( output, input, err_details))) return status; - if (aesni_is_error(status = box->algorithm->inc_block( + if (aes_is_error(status = box->algorithm->inc_block( &box->iv, err_details))) return status; return status; } -typedef AesNI_StatusCode (*AesNI_BoxEncryptBlockInMode)( - AesNI_Box*, - const AesNI_BoxBlock*, - AesNI_BoxBlock*, - AesNI_ErrorDetails*); +typedef AES_StatusCode (*AES_BoxEncryptBlockInMode)( + AES_Box*, + const AES_BoxBlock*, + AES_BoxBlock*, + AES_ErrorDetails*); -static AesNI_BoxEncryptBlockInMode aesni_box_encrypt_block_in_mode[] = +static AES_BoxEncryptBlockInMode aes_box_encrypt_block_in_mode[] = { - &aesni_box_encrypt_block_ecb, - &aesni_box_encrypt_block_cbc, - &aesni_box_encrypt_block_cfb, - &aesni_box_encrypt_block_ofb, - &aesni_box_encrypt_block_ctr, + &aes_box_encrypt_block_ecb, + &aes_box_encrypt_block_cbc, + &aes_box_encrypt_block_cfb, + &aes_box_encrypt_block_ofb, + &aes_box_encrypt_block_ctr, }; -AesNI_StatusCode aesni_box_encrypt_block( - AesNI_Box* box, - const AesNI_BoxBlock* input, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_box_encrypt_block( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { - return aesni_box_encrypt_block_in_mode[box->mode]( + return aes_box_encrypt_block_in_mode[box->mode]( box, input, output, err_details); } -static AesNI_StatusCode aesni_box_decrypt_block_ecb( - AesNI_Box* box, - const AesNI_BoxBlock* input, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_decrypt_block_ecb( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { return box->algorithm->decrypt_block( input, &box->decryption_keys, output, err_details); } -static AesNI_StatusCode aesni_box_decrypt_block_cbc( - AesNI_Box* box, - const AesNI_BoxBlock* input, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_decrypt_block_cbc( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { - AesNI_StatusCode status = AESNI_SUCCESS; + AES_StatusCode status = AES_SUCCESS; - if (aesni_is_error(status = box->algorithm->decrypt_block( + if (aes_is_error(status = box->algorithm->decrypt_block( input, &box->decryption_keys, output, err_details))) return status; - if (aesni_is_error(status = box->algorithm->xor_block( + if (aes_is_error(status = box->algorithm->xor_block( output, &box->iv, err_details))) return status; @@ -194,19 +194,19 @@ static AesNI_StatusCode aesni_box_decrypt_block_cbc( return status; } -static AesNI_StatusCode aesni_box_decrypt_block_cfb( - AesNI_Box* box, - const AesNI_BoxBlock* input, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_decrypt_block_cfb( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { - AesNI_StatusCode status = AESNI_SUCCESS; + AES_StatusCode status = AES_SUCCESS; - if (aesni_is_error(status = box->algorithm->encrypt_block( + if (aes_is_error(status = box->algorithm->encrypt_block( &box->iv, &box->encryption_keys, output, err_details))) return status; - if (aesni_is_error(status = box->algorithm->xor_block( + if (aes_is_error(status = box->algorithm->xor_block( output, input, err_details))) return status; @@ -214,44 +214,44 @@ static AesNI_StatusCode aesni_box_decrypt_block_cfb( return status; } -typedef AesNI_BoxEncryptBlockInMode AesNI_BoxDecryptBlockInMode; +typedef AES_BoxEncryptBlockInMode AES_BoxDecryptBlockInMode; -static AesNI_BoxDecryptBlockInMode aesni_box_decrypt_block_in_mode[] = +static AES_BoxDecryptBlockInMode aes_box_decrypt_block_in_mode[] = { - &aesni_box_decrypt_block_ecb, - &aesni_box_decrypt_block_cbc, - &aesni_box_decrypt_block_cfb, - &aesni_box_encrypt_block_ofb, - &aesni_box_encrypt_block_ctr, + &aes_box_decrypt_block_ecb, + &aes_box_decrypt_block_cbc, + &aes_box_decrypt_block_cfb, + &aes_box_encrypt_block_ofb, + &aes_box_encrypt_block_ctr, }; -AesNI_StatusCode aesni_box_decrypt_block( - AesNI_Box* box, - const AesNI_BoxBlock* input, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_box_decrypt_block( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { - return aesni_box_decrypt_block_in_mode[box->mode]( + return aes_box_decrypt_block_in_mode[box->mode]( box, input, output, err_details); } -static AesNI_StatusCode aesni_box_get_encrypted_buffer_size( - AesNI_Box* box, +static AES_StatusCode aes_box_get_encrypted_buffer_size( + AES_Box* box, size_t src_size, size_t* dest_size, size_t* padding_size, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - AesNI_StatusCode status = AESNI_SUCCESS; + AES_StatusCode status = AES_SUCCESS; switch (box->mode) { - case AESNI_ECB: - case AESNI_CBC: + case AES_ECB: + case AES_CBC: { size_t block_size; - if (aesni_is_error(status = box->algorithm->get_block_size( + if (aes_is_error(status = box->algorithm->get_block_size( &block_size, err_details))) return status; @@ -260,77 +260,77 @@ static AesNI_StatusCode aesni_box_get_encrypted_buffer_size( return status; } - case AESNI_CFB: - case AESNI_OFB: - case AESNI_CTR: + case AES_CFB: + case AES_OFB: + case AES_CTR: *dest_size = src_size; *padding_size = 0; return status; default: - return aesni_error_not_implemented( + return aes_error_not_implemented( err_details, "unsupported mode of operation"); } } -static AesNI_StatusCode aesni_box_encrypt_buffer_block( - AesNI_Box* box, +static AES_StatusCode aes_box_encrypt_buffer_block( + AES_Box* box, const void* src, void* dest, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - AesNI_StatusCode status = AESNI_SUCCESS; + AES_StatusCode status = AES_SUCCESS; - AesNI_BoxBlock plaintext; + AES_BoxBlock plaintext; - if (aesni_is_error(status = box->algorithm->load_block( + if (aes_is_error(status = box->algorithm->load_block( &plaintext, src, err_details))) return status; - AesNI_BoxBlock ciphertext; + AES_BoxBlock ciphertext; - if (aesni_is_error(status = aesni_box_encrypt_block( + if (aes_is_error(status = aes_box_encrypt_block( box, &plaintext, &ciphertext, err_details))) return status; - if (aesni_is_error(status = box->algorithm->store_block( + if (aes_is_error(status = box->algorithm->store_block( dest, &ciphertext, err_details))) return status; return status; } -static AesNI_StatusCode aesni_box_encrypt_buffer_partial_block_with_padding( - AesNI_Box* box, +static AES_StatusCode aes_box_encrypt_buffer_partial_block_with_padding( + AES_Box* box, const void* src, size_t src_size, void* dest, size_t padding_size, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - AesNI_StatusCode status = AESNI_SUCCESS; + AES_StatusCode status = AES_SUCCESS; size_t block_size; - if (aesni_is_error(status = box->algorithm->get_block_size( + if (aes_is_error(status = box->algorithm->get_block_size( &block_size, err_details))) return status; void* plaintext_buf = malloc(block_size); if (plaintext_buf == NULL) - return status = aesni_error_memory_allocation(err_details); + return status = aes_error_memory_allocation(err_details); memcpy(plaintext_buf, src, src_size); - if (aesni_is_error(status = aesni_fill_with_padding( - AESNI_PADDING_PKCS7, + if (aes_is_error(status = aes_fill_with_padding( + AES_PADDING_PKCS7, (char*) plaintext_buf + src_size, padding_size, err_details))) goto FREE_PLAINTEXT_BUF; - if (aesni_is_error(status = aesni_box_encrypt_buffer_block( + if (aes_is_error(status = aes_box_encrypt_buffer_block( box, plaintext_buf, dest, err_details))) goto FREE_PLAINTEXT_BUF; @@ -340,28 +340,28 @@ FREE_PLAINTEXT_BUF: return status; } -static AesNI_StatusCode aesni_box_encrypt_buffer_partial_block( - AesNI_Box* box, +static AES_StatusCode aes_box_encrypt_buffer_partial_block( + AES_Box* box, const void* src, size_t src_size, void* dest, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - AesNI_StatusCode status = AESNI_SUCCESS; + AES_StatusCode status = AES_SUCCESS; if (src_size == 0) return status; size_t block_size; - if (aesni_is_error(status = box->algorithm->get_block_size( + if (aes_is_error(status = box->algorithm->get_block_size( &block_size, err_details))) return status; void* plaintext_buf = malloc(block_size); if (plaintext_buf == NULL) - return status = aesni_error_memory_allocation(err_details); + return status = aes_error_memory_allocation(err_details); memset(plaintext_buf, 0x00, block_size); memcpy(plaintext_buf, src, src_size); @@ -370,11 +370,11 @@ static AesNI_StatusCode aesni_box_encrypt_buffer_partial_block( if (ciphertext_buf == NULL) { - status = aesni_error_memory_allocation(err_details); + status = aes_error_memory_allocation(err_details); goto FREE_PLAINTEXT_BUF; } - if (aesni_is_error(status = aesni_box_encrypt_buffer_block( + if (aes_is_error(status = aes_box_encrypt_buffer_block( box, plaintext_buf, ciphertext_buf, err_details))) goto FREE_CIPHERTEXT_BUF; @@ -389,35 +389,35 @@ FREE_PLAINTEXT_BUF: return status; } -AesNI_StatusCode aesni_box_encrypt_buffer( - AesNI_Box* box, +AES_StatusCode aes_box_encrypt_buffer( + AES_Box* box, const void* src, size_t src_size, void* dest, size_t* dest_size, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - AesNI_StatusCode status = AESNI_SUCCESS; + AES_StatusCode status = AES_SUCCESS; if (box == NULL) - return aesni_error_null_argument(err_details, "box"); + return aes_error_null_argument(err_details, "box"); if (dest_size == NULL) - return aesni_error_null_argument(err_details, "dest_size"); + return aes_error_null_argument(err_details, "dest_size"); size_t padding_size = 0; - if (aesni_is_error(status = aesni_box_get_encrypted_buffer_size( + if (aes_is_error(status = aes_box_get_encrypted_buffer_size( box, src_size, dest_size, &padding_size, err_details))) return status; if (dest == NULL) - return AESNI_SUCCESS; + return AES_SUCCESS; if (src == NULL && src_size != 0) - return aesni_error_null_argument(err_details, "src"); + return aes_error_null_argument(err_details, "src"); size_t block_size; - if (aesni_is_error(status = box->algorithm->get_block_size( + if (aes_is_error(status = box->algorithm->get_block_size( &block_size, err_details))) return status; @@ -425,7 +425,7 @@ AesNI_StatusCode aesni_box_encrypt_buffer( for (size_t i = 0; i < src_len; ++i) { - if (aesni_is_error(status = aesni_box_encrypt_buffer_block( + if (aes_is_error(status = aes_box_encrypt_buffer_block( box, src, dest, err_details))) return status; @@ -433,103 +433,103 @@ AesNI_StatusCode aesni_box_encrypt_buffer( } if (padding_size == 0) - return aesni_box_encrypt_buffer_partial_block( + return aes_box_encrypt_buffer_partial_block( box, src, src_size % block_size, dest, err_details); else - return aesni_box_encrypt_buffer_partial_block_with_padding( + return aes_box_encrypt_buffer_partial_block_with_padding( box, src, src_size % block_size, dest, padding_size, err_details); } -static AesNI_StatusCode aesni_box_get_decrypted_buffer_size( - AesNI_Box* box, +static AES_StatusCode aes_box_get_decrypted_buffer_size( + AES_Box* box, size_t src_size, size_t* dest_size, size_t* max_padding_size, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - AesNI_StatusCode status = AESNI_SUCCESS; + AES_StatusCode status = AES_SUCCESS; switch (box->mode) { - case AESNI_ECB: - case AESNI_CBC: + case AES_ECB: + case AES_CBC: { size_t block_size; - if (aesni_is_error(status = box->algorithm->get_block_size( + if (aes_is_error(status = box->algorithm->get_block_size( &block_size, err_details))) return status; if (src_size == 0 || src_size % block_size != 0) - return aesni_error_missing_padding(err_details); + return aes_error_missing_padding(err_details); *dest_size = src_size; *max_padding_size = block_size; return status; } - case AESNI_CFB: - case AESNI_OFB: - case AESNI_CTR: + case AES_CFB: + case AES_OFB: + case AES_CTR: *dest_size = src_size; *max_padding_size = 0; return status; default: - return aesni_error_not_implemented( + return aes_error_not_implemented( err_details, "unsupported mode of operation"); } } -static AesNI_StatusCode aesni_box_decrypt_buffer_block( - AesNI_Box* box, +static AES_StatusCode aes_box_decrypt_buffer_block( + AES_Box* box, const void* src, void* dest, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - AesNI_StatusCode status = AESNI_SUCCESS; + AES_StatusCode status = AES_SUCCESS; - AesNI_BoxBlock ciphertext; + AES_BoxBlock ciphertext; - if (aesni_is_error(status = box->algorithm->load_block( + if (aes_is_error(status = box->algorithm->load_block( &ciphertext, src, err_details))) return status; - AesNI_BoxBlock plaintext; + AES_BoxBlock plaintext; - if (aesni_is_error(status = aesni_box_decrypt_block( + if (aes_is_error(status = aes_box_decrypt_block( box, &ciphertext, &plaintext, err_details))) return status; - if (aesni_is_error(status = box->algorithm->store_block( + if (aes_is_error(status = box->algorithm->store_block( dest, &plaintext, err_details))) return status; return status; } -static AesNI_StatusCode aesni_box_decrypt_buffer_partial_block( - AesNI_Box* box, +static AES_StatusCode aes_box_decrypt_buffer_partial_block( + AES_Box* box, const void* src, size_t src_size, void* dest, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - AesNI_StatusCode status = AESNI_SUCCESS; + AES_StatusCode status = AES_SUCCESS; if (src_size == 0) return status; size_t block_size; - if (aesni_is_error(status = box->algorithm->get_block_size( + if (aes_is_error(status = box->algorithm->get_block_size( &block_size, err_details))) return status; void* ciphertext_buf = malloc(block_size); if (ciphertext_buf == NULL) - return status = aesni_error_memory_allocation(err_details); + return status = aes_error_memory_allocation(err_details); memset(ciphertext_buf, 0x00, block_size); memcpy(ciphertext_buf, src, src_size); @@ -538,11 +538,11 @@ static AesNI_StatusCode aesni_box_decrypt_buffer_partial_block( if (plaintext_buf == NULL) { - status = aesni_error_memory_allocation(err_details); + status = aes_error_memory_allocation(err_details); goto FREE_CIPHERTEXT_BUF; } - if (aesni_is_error(status = aesni_box_decrypt_buffer_block( + if (aes_is_error(status = aes_box_decrypt_buffer_block( box, ciphertext_buf, plaintext_buf, err_details))) goto FREE_PLAINTEXT_BUF; @@ -557,34 +557,34 @@ FREE_CIPHERTEXT_BUF: return status; } -AesNI_StatusCode aesni_box_decrypt_buffer( - AesNI_Box* box, +AES_StatusCode aes_box_decrypt_buffer( + AES_Box* box, const void* src, size_t src_size, void* dest, size_t* dest_size, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { if (box == NULL) - return aesni_error_null_argument(err_details, "box"); + return aes_error_null_argument(err_details, "box"); if (dest_size == NULL) - return aesni_error_null_argument(err_details, "dest_size"); + return aes_error_null_argument(err_details, "dest_size"); - AesNI_StatusCode status = AESNI_SUCCESS; + AES_StatusCode status = AES_SUCCESS; size_t max_padding_size = 0; - if (aesni_is_error(status = aesni_box_get_decrypted_buffer_size( + if (aes_is_error(status = aes_box_get_decrypted_buffer_size( box, src_size, dest_size, &max_padding_size, err_details))) return status; if (dest == NULL) - return AESNI_SUCCESS; + return AES_SUCCESS; if (src == NULL) - return aesni_error_null_argument(err_details, "src"); + return aes_error_null_argument(err_details, "src"); size_t block_size; - if (aesni_is_error(status = box->algorithm->get_block_size( + if (aes_is_error(status = box->algorithm->get_block_size( &block_size, err_details))) return status; @@ -592,7 +592,7 @@ AesNI_StatusCode aesni_box_decrypt_buffer( for (size_t i = 0; i < src_len; ++i) { - if (aesni_is_error(status = aesni_box_decrypt_buffer_block( + if (aes_is_error(status = aes_box_decrypt_buffer_block( box, src, dest, err_details))) return status; @@ -601,15 +601,15 @@ AesNI_StatusCode aesni_box_decrypt_buffer( if (max_padding_size == 0) { - return aesni_box_decrypt_buffer_partial_block( + return aes_box_decrypt_buffer_partial_block( box, src, src_size % block_size, dest, err_details); } else { size_t padding_size; - if (aesni_is_error(status = aesni_extract_padding_size( - AESNI_PADDING_PKCS7, + if (aes_is_error(status = aes_extract_padding_size( + AES_PADDING_PKCS7, (char*) dest - block_size, block_size, &padding_size, @@ -621,62 +621,62 @@ AesNI_StatusCode aesni_box_decrypt_buffer( } } -AesNI_StatusCode aesni_box_parse_block( - AesNI_BoxBlock* dest, - AesNI_Algorithm algorithm, +AES_StatusCode aes_box_parse_block( + AES_BoxBlock* dest, + AES_Algorithm algorithm, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); if (src == NULL) - return aesni_error_null_argument(err_details, "src"); + return aes_error_null_argument(err_details, "src"); - return aesni_box_algorithms[algorithm]->parse_block( + return aes_box_algorithms[algorithm]->parse_block( dest, src, err_details); } -AesNI_StatusCode aesni_box_parse_key( - AesNI_BoxKey* dest, - AesNI_Algorithm algorithm, +AES_StatusCode aes_box_parse_key( + AES_BoxKey* dest, + AES_Algorithm algorithm, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); if (src == NULL) - return aesni_error_null_argument(err_details, "src"); + return aes_error_null_argument(err_details, "src"); - return aesni_box_algorithms[algorithm]->parse_key( + return aes_box_algorithms[algorithm]->parse_key( dest, src, err_details); } -AesNI_StatusCode aesni_box_format_block( - AesNI_BoxBlockString* dest, - AesNI_Algorithm algorithm, - const AesNI_BoxBlock* src, - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_box_format_block( + AES_BoxBlockString* dest, + AES_Algorithm algorithm, + const AES_BoxBlock* src, + AES_ErrorDetails* err_details) { if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); if (src == NULL) - return aesni_error_null_argument(err_details, "src"); + return aes_error_null_argument(err_details, "src"); - return aesni_box_algorithms[algorithm]->format_block( + return aes_box_algorithms[algorithm]->format_block( dest, src, err_details); } -AesNI_StatusCode aesni_box_format_key( - AesNI_BoxKeyString* dest, - AesNI_Algorithm algorithm, - const AesNI_BoxKey* src, - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_box_format_key( + AES_BoxKeyString* dest, + AES_Algorithm algorithm, + const AES_BoxKey* src, + AES_ErrorDetails* err_details) { if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); if (src == NULL) - return aesni_error_null_argument(err_details, "src"); + return aes_error_null_argument(err_details, "src"); - return aesni_box_algorithms[algorithm]->format_key( + return aes_box_algorithms[algorithm]->format_key( dest, src, err_details); } diff --git a/src/box_aes.c b/src/box_aes.c index 66eacae..b79f3cc 100644 --- a/src/box_aes.c +++ b/src/box_aes.c @@ -11,309 +11,309 @@ #include <stdlib.h> #include <string.h> -static AesNI_StatusCode aesni_box_derive_params_aes128( - const AesNI_BoxKey* box_key, - AesNI_BoxEncryptionRoundKeys* encryption_keys, - AesNI_BoxDecryptionRoundKeys* decryption_keys, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_derive_params_aes128( + const AES_BoxKey* box_key, + AES_BoxEncryptionRoundKeys* encryption_keys, + AES_BoxDecryptionRoundKeys* decryption_keys, + AES_ErrorDetails* err_details) { - aesni_AES128_expand_key_( + aes_AES128_expand_key_( box_key->aes128_key.key, &encryption_keys->aes128_encryption_keys); - aesni_AES128_derive_decryption_keys_( + aes_AES128_derive_decryption_keys_( &encryption_keys->aes128_encryption_keys, &decryption_keys->aes128_decryption_keys); - return AESNI_SUCCESS; + return AES_SUCCESS; } -static AesNI_StatusCode aesni_box_derive_params_aes192( - const AesNI_BoxKey* box_key, - AesNI_BoxEncryptionRoundKeys* encryption_keys, - AesNI_BoxDecryptionRoundKeys* decryption_keys, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_derive_params_aes192( + const AES_BoxKey* box_key, + AES_BoxEncryptionRoundKeys* encryption_keys, + AES_BoxDecryptionRoundKeys* decryption_keys, + AES_ErrorDetails* err_details) { - aesni_AES192_expand_key_( + aes_AES192_expand_key_( box_key->aes192_key.lo, box_key->aes192_key.hi, &encryption_keys->aes192_encryption_keys); - aesni_AES192_derive_decryption_keys_( + aes_AES192_derive_decryption_keys_( &encryption_keys->aes192_encryption_keys, &decryption_keys->aes192_decryption_keys); - return AESNI_SUCCESS; + return AES_SUCCESS; } -static AesNI_StatusCode aesni_box_derive_params_aes256( - const AesNI_BoxKey* box_key, - AesNI_BoxEncryptionRoundKeys* encryption_keys, - AesNI_BoxDecryptionRoundKeys* decryption_keys, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_derive_params_aes256( + const AES_BoxKey* box_key, + AES_BoxEncryptionRoundKeys* encryption_keys, + AES_BoxDecryptionRoundKeys* decryption_keys, + AES_ErrorDetails* err_details) { - aesni_AES256_expand_key_( + aes_AES256_expand_key_( box_key->aes256_key.lo, box_key->aes256_key.hi, &encryption_keys->aes256_encryption_keys); - aesni_AES256_derive_decryption_keys_( + aes_AES256_derive_decryption_keys_( &encryption_keys->aes256_encryption_keys, &decryption_keys->aes256_decryption_keys); - return AESNI_SUCCESS; + return AES_SUCCESS; } -static AesNI_StatusCode aesni_box_parse_block_aes( - AesNI_BoxBlock* dest, +static AES_StatusCode aes_box_parse_block_aes( + AES_BoxBlock* dest, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); - return aesni_AES_parse_block(&dest->aes_block, src, err_details); + return aes_AES_parse_block(&dest->aes_block, src, err_details); } -static AesNI_StatusCode aesni_box_parse_key_aes128( - AesNI_BoxKey* dest, +static AES_StatusCode aes_box_parse_key_aes128( + AES_BoxKey* dest, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); - return aesni_AES128_parse_key(&dest->aes128_key, src, err_details); + return aes_AES128_parse_key(&dest->aes128_key, src, err_details); } -static AesNI_StatusCode aesni_box_parse_key_aes192( - AesNI_BoxKey* dest, +static AES_StatusCode aes_box_parse_key_aes192( + AES_BoxKey* dest, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); - return aesni_AES192_parse_key(&dest->aes192_key, src, err_details); + return aes_AES192_parse_key(&dest->aes192_key, src, err_details); } -static AesNI_StatusCode aesni_box_parse_key_aes256( - AesNI_BoxKey* dest, +static AES_StatusCode aes_box_parse_key_aes256( + AES_BoxKey* dest, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); - return aesni_AES256_parse_key(&dest->aes256_key, src, err_details); + return aes_AES256_parse_key(&dest->aes256_key, src, err_details); } -static AesNI_StatusCode aesni_box_format_block_aes( - AesNI_BoxBlockString* dest, - const AesNI_BoxBlock* src, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_format_block_aes( + AES_BoxBlockString* dest, + const AES_BoxBlock* src, + AES_ErrorDetails* err_details) { if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); if (src == NULL) - return aesni_error_null_argument(err_details, "src"); + return aes_error_null_argument(err_details, "src"); - return aesni_AES128_format_block(&dest->aes, &src->aes_block, err_details); + return aes_AES128_format_block(&dest->aes, &src->aes_block, err_details); } -static AesNI_StatusCode aesni_box_format_key_aes128( - AesNI_BoxKeyString* dest, - const AesNI_BoxKey* src, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_format_key_aes128( + AES_BoxKeyString* dest, + const AES_BoxKey* src, + AES_ErrorDetails* err_details) { if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); if (src == NULL) - return aesni_error_null_argument(err_details, "src"); + return aes_error_null_argument(err_details, "src"); - return aesni_AES128_format_key(&dest->aes128, &src->aes128_key, err_details); + return aes_AES128_format_key(&dest->aes128, &src->aes128_key, err_details); } -static AesNI_StatusCode aesni_box_format_key_aes192( - AesNI_BoxKeyString* dest, - const AesNI_BoxKey* src, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_format_key_aes192( + AES_BoxKeyString* dest, + const AES_BoxKey* src, + AES_ErrorDetails* err_details) { if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); if (src == NULL) - return aesni_error_null_argument(err_details, "src"); + return aes_error_null_argument(err_details, "src"); - return aesni_AES192_format_key(&dest->aes192, &src->aes192_key, err_details); + return aes_AES192_format_key(&dest->aes192, &src->aes192_key, err_details); } -static AesNI_StatusCode aesni_box_format_key_aes256( - AesNI_BoxKeyString* dest, - const AesNI_BoxKey* src, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_format_key_aes256( + AES_BoxKeyString* dest, + const AES_BoxKey* src, + AES_ErrorDetails* err_details) { if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); if (src == NULL) - return aesni_error_null_argument(err_details, "src"); + return aes_error_null_argument(err_details, "src"); - return aesni_AES256_format_key(&dest->aes256, &src->aes256_key, err_details); + return aes_AES256_format_key(&dest->aes256, &src->aes256_key, err_details); } -static AesNI_StatusCode aesni_box_xor_block_aes( - AesNI_BoxBlock* dest, - const AesNI_BoxBlock* src, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_xor_block_aes( + AES_BoxBlock* dest, + const AES_BoxBlock* src, + AES_ErrorDetails* err_details) { - dest->aes_block = aesni_AES_xor_blocks(dest->aes_block, src->aes_block); - return AESNI_SUCCESS; + dest->aes_block = aes_AES_xor_blocks(dest->aes_block, src->aes_block); + return AES_SUCCESS; } -static AesNI_StatusCode aesni_box_inc_block_aes( - AesNI_BoxBlock* ctr, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_inc_block_aes( + AES_BoxBlock* ctr, + AES_ErrorDetails* err_details) { - ctr->aes_block = aesni_AES_inc_block(ctr->aes_block); - return AESNI_SUCCESS; + ctr->aes_block = aes_AES_inc_block(ctr->aes_block); + return AES_SUCCESS; } -static AesNI_StatusCode aesni_box_get_block_size_aes( +static AES_StatusCode aes_box_get_block_size_aes( size_t* block_size, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { *block_size = 16; - return AESNI_SUCCESS; + return AES_SUCCESS; } -static AesNI_StatusCode aesni_box_store_block_aes( +static AES_StatusCode aes_box_store_block_aes( void* dest, - const AesNI_BoxBlock* src, - AesNI_ErrorDetails* err_details) + const AES_BoxBlock* src, + AES_ErrorDetails* err_details) { - aesni_store_block128(dest, src->aes_block); - return AESNI_SUCCESS; + aes_store_block128(dest, src->aes_block); + return AES_SUCCESS; } -static AesNI_StatusCode aesni_box_load_block_aes( - AesNI_BoxBlock* dest, +static AES_StatusCode aes_box_load_block_aes( + AES_BoxBlock* dest, const void* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - dest->aes_block = aesni_load_block128(src); - return AESNI_SUCCESS; + dest->aes_block = aes_load_block128(src); + return AES_SUCCESS; } -static AesNI_StatusCode aesni_box_encrypt_block_aes128( - const AesNI_BoxBlock* input, - const AesNI_BoxEncryptionRoundKeys* params, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_encrypt_block_aes128( + const AES_BoxBlock* input, + const AES_BoxEncryptionRoundKeys* params, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { - output->aes_block = aesni_AES128_encrypt_block_( + output->aes_block = aes_AES128_encrypt_block_( input->aes_block, ¶ms->aes128_encryption_keys); - return AESNI_SUCCESS; + return AES_SUCCESS; } -static AesNI_StatusCode aesni_box_decrypt_block_aes128( - const AesNI_BoxBlock* input, - const AesNI_BoxDecryptionRoundKeys* params, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_decrypt_block_aes128( + const AES_BoxBlock* input, + const AES_BoxDecryptionRoundKeys* params, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { - output->aes_block = aesni_AES128_decrypt_block_( + output->aes_block = aes_AES128_decrypt_block_( input->aes_block, ¶ms->aes128_decryption_keys); - return AESNI_SUCCESS; + return AES_SUCCESS; } -static AesNI_StatusCode aesni_box_encrypt_block_aes192( - const AesNI_BoxBlock* input, - const AesNI_BoxEncryptionRoundKeys* params, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_encrypt_block_aes192( + const AES_BoxBlock* input, + const AES_BoxEncryptionRoundKeys* params, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { - output->aes_block = aesni_AES192_encrypt_block_( + output->aes_block = aes_AES192_encrypt_block_( input->aes_block, ¶ms->aes192_encryption_keys); - return AESNI_SUCCESS; + return AES_SUCCESS; } -static AesNI_StatusCode aesni_box_decrypt_block_aes192( - const AesNI_BoxBlock* input, - const AesNI_BoxDecryptionRoundKeys* params, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_decrypt_block_aes192( + const AES_BoxBlock* input, + const AES_BoxDecryptionRoundKeys* params, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { - output->aes_block = aesni_AES192_decrypt_block_( + output->aes_block = aes_AES192_decrypt_block_( input->aes_block, ¶ms->aes192_decryption_keys); - return AESNI_SUCCESS; + return AES_SUCCESS; } -static AesNI_StatusCode aesni_box_encrypt_block_aes256( - const AesNI_BoxBlock* input, - const AesNI_BoxEncryptionRoundKeys* params, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_encrypt_block_aes256( + const AES_BoxBlock* input, + const AES_BoxEncryptionRoundKeys* params, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { - output->aes_block = aesni_AES256_encrypt_block_( + output->aes_block = aes_AES256_encrypt_block_( input->aes_block, ¶ms->aes256_encryption_keys); - return AESNI_SUCCESS; + return AES_SUCCESS; } -static AesNI_StatusCode aesni_box_decrypt_block_aes256( - const AesNI_BoxBlock* input, - const AesNI_BoxDecryptionRoundKeys* params, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) +static AES_StatusCode aes_box_decrypt_block_aes256( + const AES_BoxBlock* input, + const AES_BoxDecryptionRoundKeys* params, + AES_BoxBlock* output, + AES_ErrorDetails* err_details) { - output->aes_block = aesni_AES256_decrypt_block_( + output->aes_block = aes_AES256_decrypt_block_( input->aes_block, ¶ms->aes256_decryption_keys); - return AESNI_SUCCESS; + return AES_SUCCESS; } -AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes128 = +AES_BoxAlgorithmInterface aes_box_algorithm_aes128 = { - &aesni_box_derive_params_aes128, - &aesni_box_parse_block_aes, - &aesni_box_parse_key_aes128, - &aesni_box_format_block_aes, - &aesni_box_format_key_aes128, - &aesni_box_encrypt_block_aes128, - &aesni_box_decrypt_block_aes128, - &aesni_box_xor_block_aes, - &aesni_box_inc_block_aes, - &aesni_box_get_block_size_aes, - &aesni_box_store_block_aes, - &aesni_box_load_block_aes, + &aes_box_derive_params_aes128, + &aes_box_parse_block_aes, + &aes_box_parse_key_aes128, + &aes_box_format_block_aes, + &aes_box_format_key_aes128, + &aes_box_encrypt_block_aes128, + &aes_box_decrypt_block_aes128, + &aes_box_xor_block_aes, + &aes_box_inc_block_aes, + &aes_box_get_block_size_aes, + &aes_box_store_block_aes, + &aes_box_load_block_aes, }; -AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes192 = +AES_BoxAlgorithmInterface aes_box_algorithm_aes192 = { - &aesni_box_derive_params_aes192, - &aesni_box_parse_block_aes, - &aesni_box_parse_key_aes192, - &aesni_box_format_block_aes, - &aesni_box_format_key_aes192, - &aesni_box_encrypt_block_aes192, - &aesni_box_decrypt_block_aes192, - &aesni_box_xor_block_aes, - &aesni_box_inc_block_aes, - &aesni_box_get_block_size_aes, - &aesni_box_store_block_aes, - &aesni_box_load_block_aes, + &aes_box_derive_params_aes192, + &aes_box_parse_block_aes, + &aes_box_parse_key_aes192, + &aes_box_format_block_aes, + &aes_box_format_key_aes192, + &aes_box_encrypt_block_aes192, + &aes_box_decrypt_block_aes192, + &aes_box_xor_block_aes, + &aes_box_inc_block_aes, + &aes_box_get_block_size_aes, + &aes_box_store_block_aes, + &aes_box_load_block_aes, }; -AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes256 = +AES_BoxAlgorithmInterface aes_box_algorithm_aes256 = { - &aesni_box_derive_params_aes256, - &aesni_box_parse_block_aes, - &aesni_box_parse_key_aes256, - &aesni_box_format_block_aes, - &aesni_box_format_key_aes256, - &aesni_box_encrypt_block_aes256, - &aesni_box_decrypt_block_aes256, - &aesni_box_xor_block_aes, - &aesni_box_inc_block_aes, - &aesni_box_get_block_size_aes, - &aesni_box_store_block_aes, - &aesni_box_load_block_aes, + &aes_box_derive_params_aes256, + &aes_box_parse_block_aes, + &aes_box_parse_key_aes256, + &aes_box_format_block_aes, + &aes_box_format_key_aes256, + &aes_box_encrypt_block_aes256, + &aes_box_decrypt_block_aes256, + &aes_box_xor_block_aes, + &aes_box_inc_block_aes, + &aes_box_get_block_size_aes, + &aes_box_store_block_aes, + &aes_box_load_block_aes, }; diff --git a/src/c/aes128.c b/src/c/aes128.c index 94e8a05..3a797a9 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) +AES_AES_Block __fastcall aes_AES128_encrypt_block_( + AES_AES_Block plaintext, + const AES_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) +AES_AES_Block __fastcall aes_AES128_decrypt_block_( + AES_AES_Block ciphertext, + const AES_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 AES_AES_Block __fastcall aes_aes128_expand_key_assist( + AES_AES_Block prev, + AES_AES_Block hwgen) { - AesNI_AES_Block tmp = prev; + AES_AES_Block tmp = prev; tmp = _mm_slli_si128(tmp, 4); prev = _mm_xor_si128(prev, tmp); @@ -64,26 +64,26 @@ 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 aes_AES128_expand_key_( + AES_AES_Block key, + AES_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)); - prev = encryption_keys->keys[2] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x02)); - prev = encryption_keys->keys[3] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x04)); - prev = encryption_keys->keys[4] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x08)); - prev = encryption_keys->keys[5] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x10)); - prev = encryption_keys->keys[6] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x20)); - prev = encryption_keys->keys[7] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x40)); - prev = encryption_keys->keys[8] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x80)); - prev = encryption_keys->keys[9] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x1b)); - prev = encryption_keys->keys[10] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x36)); + AES_Block128 prev = encryption_keys->keys[0] = key; + prev = encryption_keys->keys[1] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x01)); + prev = encryption_keys->keys[2] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x02)); + prev = encryption_keys->keys[3] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x04)); + prev = encryption_keys->keys[4] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x08)); + prev = encryption_keys->keys[5] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x10)); + prev = encryption_keys->keys[6] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x20)); + prev = encryption_keys->keys[7] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x40)); + prev = encryption_keys->keys[8] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x80)); + prev = encryption_keys->keys[9] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x1b)); + prev = encryption_keys->keys[10] = aes_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 aes_AES128_derive_decryption_keys_( + const AES_AES128_RoundKeys* encryption_keys, + AES_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 570ab0e..4c2d4f4 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) +AES_AES_Block __fastcall aes_AES192_encrypt_block_( + AES_AES_Block plaintext, + const AES_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) +AES_AES_Block __fastcall aes_AES192_decrypt_block_( + AES_AES_Block ciphertext, + const AES_AES192_RoundKeys* decryption_keys) { ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]); ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[1]); @@ -49,12 +49,12 @@ AesNI_AES_Block __fastcall aesni_AES192_decrypt_block_( return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[12]); } -static void __fastcall aesni_aes192_expand_key_assist( - AesNI_AES_Block* prev_lo, - AesNI_AES_Block* prev_hi, - AesNI_AES_Block hwgen) +static void __fastcall aes_aes192_expand_key_assist( + AES_AES_Block* prev_lo, + AES_AES_Block* prev_hi, + AES_AES_Block hwgen) { - AesNI_AES_Block tmp = *prev_lo; + AES_AES_Block tmp = *prev_lo; tmp = _mm_slli_si128(tmp, 4); *prev_lo = _mm_xor_si128(*prev_lo, tmp); @@ -74,49 +74,49 @@ 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 aes_AES192_expand_key_( + AES_AES_Block key_lo, + AES_AES_Block key_hi, + AES_AES192_RoundKeys* encryption_keys) { encryption_keys->keys[0] = key_lo; encryption_keys->keys[1] = key_hi; - aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x01)); + aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x01)); encryption_keys->keys[1] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[1]), _mm_castsi128_pd(key_lo), 0)); encryption_keys->keys[2] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); - aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x02)); + aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x02)); encryption_keys->keys[3] = key_lo; encryption_keys->keys[4] = key_hi; - aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x04)); + aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x04)); encryption_keys->keys[4] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[4]), _mm_castsi128_pd(key_lo), 0)); encryption_keys->keys[5] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); - aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x08)); + aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x08)); encryption_keys->keys[6] = key_lo; encryption_keys->keys[7] = key_hi; - aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x10)); + aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x10)); encryption_keys->keys[7] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[7]), _mm_castsi128_pd(key_lo), 0)); encryption_keys->keys[8] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); - aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x20)); + aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x20)); encryption_keys->keys[9] = key_lo; encryption_keys->keys[10] = key_hi; - aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x40)); + aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x40)); encryption_keys->keys[10] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[10]), _mm_castsi128_pd(key_lo), 0)); encryption_keys->keys[11] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); - aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x80)); + aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x80)); 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 aes_AES192_derive_decryption_keys_( + const AES_AES192_RoundKeys* encryption_keys, + AES_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 23ac9ca..da81f7a 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) +AES_AES_Block __fastcall aes_AES256_encrypt_block_( + AES_AES_Block plaintext, + const AES_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) +AES_AES_Block __fastcall aes_AES256_decrypt_block_( + AES_AES_Block ciphertext, + const AES_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 AES_AES_Block __fastcall aes_aes256_expand_key_assist( + AES_AES_Block* prev_lo, + AES_AES_Block* prev_hi, + AES_AES_Block hwgen) { - AesNI_AES_Block tmp = *prev_lo; + AES_AES_Block tmp = *prev_lo; tmp = _mm_slli_si128(tmp, 4); *prev_lo = _mm_xor_si128(*prev_lo, tmp); @@ -76,73 +76,73 @@ 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 aes_AES256_expand_key_( + AES_AES_Block key_lo, + AES_AES_Block key_hi, + AES_AES256_RoundKeys* encryption_keys) { - AesNI_AES_Block prev_lo, prev_hi; - AesNI_AES_Block hwgen; + AES_AES_Block prev_lo, prev_hi; + AES_AES_Block hwgen; prev_lo = encryption_keys->keys[0] = key_lo; prev_hi = encryption_keys->keys[1] = key_hi; hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x01); hwgen = _mm_shuffle_epi32(hwgen, 0xff); - encryption_keys->keys[2] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[2] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0); hwgen = _mm_shuffle_epi32(hwgen, 0xaa); - encryption_keys->keys[3] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[3] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x02); hwgen = _mm_shuffle_epi32(hwgen, 0xff); - encryption_keys->keys[4] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[4] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0); hwgen = _mm_shuffle_epi32(hwgen, 0xaa); - encryption_keys->keys[5] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[5] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x04); hwgen = _mm_shuffle_epi32(hwgen, 0xff); - encryption_keys->keys[6] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[6] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0); hwgen = _mm_shuffle_epi32(hwgen, 0xaa); - encryption_keys->keys[7] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[7] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x08); hwgen = _mm_shuffle_epi32(hwgen, 0xff); - encryption_keys->keys[8] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[8] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0); hwgen = _mm_shuffle_epi32(hwgen, 0xaa); - encryption_keys->keys[9] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[9] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x10); hwgen = _mm_shuffle_epi32(hwgen, 0xff); - encryption_keys->keys[10] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[10] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0); hwgen = _mm_shuffle_epi32(hwgen, 0xaa); - encryption_keys->keys[11] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[11] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x20); hwgen = _mm_shuffle_epi32(hwgen, 0xff); - encryption_keys->keys[12] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[12] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0); hwgen = _mm_shuffle_epi32(hwgen, 0xaa); - encryption_keys->keys[13] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[13] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x40); hwgen = _mm_shuffle_epi32(hwgen, 0xff); - encryption_keys->keys[14] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[14] = aes_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 aes_AES256_derive_decryption_keys_( + const AES_AES256_RoundKeys* encryption_keys, + AES_AES256_RoundKeys* decryption_keys) { decryption_keys->keys[0] = encryption_keys->keys[14]; decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[13]); diff --git a/src/error.c b/src/error.c index 49d8c72..15b2aeb 100644 --- a/src/error.c +++ b/src/error.c @@ -13,13 +13,13 @@ #include <stdlib.h> #include <string.h> -static void aesni_fill_string(char* dest, size_t dest_size, const char* src) +static void aes_fill_string(char* dest, size_t dest_size, const char* src) { strncpy(dest, src, dest_size); dest[dest_size - 1] = '\0'; } -static const char* aesni_strerror_messages[] = +static const char* aes_strerror_messages[] = { "Success", "Invalid argument value NULL", @@ -30,28 +30,28 @@ static const char* aesni_strerror_messages[] = "Couldn't allocate memory", }; -const char* aesni_strerror(AesNI_StatusCode ec) +const char* aes_strerror(AES_StatusCode ec) { - return aesni_strerror_messages[ec]; + return aes_strerror_messages[ec]; } -static size_t aesni_format_error_strerror( - const AesNI_ErrorDetails* err_details,\ +static size_t aes_format_error_strerror( + const AES_ErrorDetails* err_details,\ char* dest, size_t dest_size) { - const AesNI_StatusCode ec = aesni_get_error_code(err_details); - const char* const msg = aesni_strerror(ec); + const AES_StatusCode ec = aes_get_error_code(err_details); + const char* const msg = aes_strerror(ec); if (dest == NULL) return strlen(msg) + 1; - aesni_fill_string(dest, dest_size, msg); + aes_fill_string(dest, dest_size, msg); return strlen(dest); } -static size_t aesni_format_null_argument_error( - const AesNI_ErrorDetails* err_details, +static size_t aes_format_null_argument_error( + const AES_ErrorDetails* err_details, char* dest, size_t dest_size) { @@ -65,8 +65,8 @@ static size_t aesni_format_null_argument_error( return strlen(dest); } -static size_t aesni_format_parse_error( - const AesNI_ErrorDetails* err_details, +static size_t aes_format_parse_error( + const AES_ErrorDetails* err_details, char* dest, size_t dest_size) { @@ -81,8 +81,8 @@ static size_t aesni_format_parse_error( return strlen(dest); } -static size_t aesni_format_not_implemented_error( - const AesNI_ErrorDetails* err_details, +static size_t aes_format_not_implemented_error( + const AES_ErrorDetails* err_details, char* dest, size_t dest_size) { @@ -96,21 +96,21 @@ static size_t aesni_format_not_implemented_error( return strlen(dest); } -typedef size_t (*AesNI_ErrorFormatter)(const AesNI_ErrorDetails*, char*, size_t); +typedef size_t (*AES_ErrorFormatter)(const AES_ErrorDetails*, char*, size_t); -static AesNI_ErrorFormatter err_formatters[] = +static AES_ErrorFormatter err_formatters[] = { - &aesni_format_error_strerror, - &aesni_format_null_argument_error, - &aesni_format_parse_error, - &aesni_format_error_strerror, - &aesni_format_not_implemented_error, - &aesni_format_error_strerror, - &aesni_format_error_strerror, + &aes_format_error_strerror, + &aes_format_null_argument_error, + &aes_format_parse_error, + &aes_format_error_strerror, + &aes_format_not_implemented_error, + &aes_format_error_strerror, + &aes_format_error_strerror, }; -size_t aesni_format_error( - const AesNI_ErrorDetails* err_details, +size_t aes_format_error( + const AES_ErrorDetails* err_details, char* dest, size_t dest_size) { @@ -122,63 +122,63 @@ size_t aesni_format_error( #ifdef WIN32 #include <Windows.h> -static void aesni_collect_call_stack(AesNI_ErrorDetails* err_details) +static void aes_collect_call_stack(AES_ErrorDetails* err_details) { - err_details->call_stack_size = CaptureStackBackTrace(1, AESNI_MAX_CALL_STACK_LENGTH, err_details->call_stack, NULL); + err_details->call_stack_size = CaptureStackBackTrace(1, AES_MAX_CALL_STACK_LENGTH, err_details->call_stack, NULL); } #else -static void aesni_collect_call_stack(AesNI_ErrorDetails* err_details) +static void aes_collect_call_stack(AES_ErrorDetails* err_details) { err_details->call_stack_size = 0; } #endif -static AesNI_StatusCode aesni_make_error( - AesNI_ErrorDetails* err_details, - AesNI_StatusCode ec) +static AES_StatusCode aes_make_error( + AES_ErrorDetails* err_details, + AES_StatusCode ec) { if (err_details == NULL) return ec; - if (aesni_is_error(ec)) - aesni_collect_call_stack(err_details); + if (aes_is_error(ec)) + aes_collect_call_stack(err_details); return err_details->ec = ec; } -AesNI_StatusCode aesni_success( - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_success( + AES_ErrorDetails* err_details) { - return aesni_make_error(err_details, AESNI_SUCCESS); + return aes_make_error(err_details, AES_SUCCESS); } -AesNI_StatusCode aesni_error_null_argument( - AesNI_ErrorDetails* err_details, +AES_StatusCode aes_error_null_argument( + AES_ErrorDetails* err_details, const char* param_name) { - AesNI_StatusCode status = aesni_make_error(err_details, AESNI_NULL_ARGUMENT_ERROR); + AES_StatusCode status = aes_make_error(err_details, AES_NULL_ARGUMENT_ERROR); if (err_details != NULL) - aesni_fill_string( + aes_fill_string( err_details->params.null_arg.param_name, sizeof(err_details->params.null_arg.param_name), param_name); return status; } -AesNI_StatusCode aesni_error_parse( - AesNI_ErrorDetails* err_details, +AES_StatusCode aes_error_parse( + AES_ErrorDetails* err_details, const char* src, const char* what) { - AesNI_StatusCode status = aesni_make_error(err_details, AESNI_PARSE_ERROR); + AES_StatusCode status = aes_make_error(err_details, AES_PARSE_ERROR); if (err_details != NULL) { - aesni_fill_string( + aes_fill_string( err_details->params.parse_error.src, sizeof(err_details->params.parse_error.src), src); - aesni_fill_string( + aes_fill_string( err_details->params.parse_error.what, sizeof(err_details->params.parse_error.what), what); } @@ -186,34 +186,34 @@ AesNI_StatusCode aesni_error_parse( return status; } -AesNI_StatusCode aesni_error_invalid_pkcs7_padding( - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_error_invalid_pkcs7_padding( + AES_ErrorDetails* err_details) { - return aesni_make_error(err_details, AESNI_INVALID_PKCS7_PADDING_ERROR); + return aes_make_error(err_details, AES_INVALID_PKCS7_PADDING_ERROR); } -AesNI_StatusCode aesni_error_not_implemented( - AesNI_ErrorDetails* err_details, +AES_StatusCode aes_error_not_implemented( + AES_ErrorDetails* err_details, const char* what) { - AesNI_StatusCode status = aesni_make_error(err_details, AESNI_NOT_IMPLEMENTED_ERROR); + AES_StatusCode status = aes_make_error(err_details, AES_NOT_IMPLEMENTED_ERROR); if (err_details != NULL) - aesni_fill_string( + aes_fill_string( err_details->params.not_implemented.what, sizeof(err_details->params.not_implemented.what), what); return status; } -AesNI_StatusCode aesni_error_missing_padding( - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_error_missing_padding( + AES_ErrorDetails* err_details) { - return aesni_make_error(err_details, AESNI_MISSING_PADDING_ERROR); + return aes_make_error(err_details, AES_MISSING_PADDING_ERROR); } -AesNI_StatusCode aesni_error_memory_allocation( - AesNI_ErrorDetails* err_details) +AES_StatusCode aes_error_memory_allocation( + AES_ErrorDetails* err_details) { - return aesni_make_error(err_details, AESNI_MEMORY_ALLOCATION_ERROR); + return aes_make_error(err_details, AES_MEMORY_ALLOCATION_ERROR); } diff --git a/src/padding.c b/src/padding.c index f76e7ca..1bbe7f2 100644 --- a/src/padding.c +++ b/src/padding.c @@ -11,77 +11,77 @@ #include <stdlib.h> #include <string.h> -static AesNI_StatusCode aesni_extract_padding_size_pkcs7( +static AES_StatusCode aes_extract_padding_size_pkcs7( const void* src, size_t src_size, size_t* padding_size, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { const unsigned char* cursor = (const unsigned char*) src + src_size - 1; *padding_size = *cursor; for (size_t i = 1; i < *padding_size; ++i) if (cursor[0 - i] != *padding_size) - return aesni_error_invalid_pkcs7_padding(err_details); + return aes_error_invalid_pkcs7_padding(err_details); - return AESNI_SUCCESS; + return AES_SUCCESS; } -AesNI_StatusCode aesni_extract_padding_size( - AesNI_PaddingMethod method, +AES_StatusCode aes_extract_padding_size( + AES_PaddingMethod method, const void* src, size_t src_size, size_t* padding_size, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { assert(src); assert(padding_size); if (src == NULL) - return aesni_error_null_argument(err_details, "src"); + return aes_error_null_argument(err_details, "src"); if (padding_size == NULL) - return aesni_error_null_argument(err_details, "padding_size"); + return aes_error_null_argument(err_details, "padding_size"); switch (method) { - case AESNI_PADDING_PKCS7: - return aesni_extract_padding_size_pkcs7( + case AES_PADDING_PKCS7: + return aes_extract_padding_size_pkcs7( src, src_size, padding_size, err_details); default: - return aesni_error_not_implemented( + return aes_error_not_implemented( err_details, "unsupported padding method"); } } -static AesNI_StatusCode aesni_fill_with_padding_pkcs7( +static AES_StatusCode aes_fill_with_padding_pkcs7( void* dest, size_t padding_size, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { memset(dest, padding_size, padding_size); - return AESNI_SUCCESS; + return AES_SUCCESS; } -AesNI_StatusCode aesni_fill_with_padding( - AesNI_PaddingMethod method, +AES_StatusCode aes_fill_with_padding( + AES_PaddingMethod method, void* dest, size_t padding_size, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { assert(dest); if (dest == NULL) - return aesni_error_null_argument(err_details, "dest"); + return aes_error_null_argument(err_details, "dest"); switch (method) { - case AESNI_PADDING_PKCS7: - return aesni_fill_with_padding_pkcs7( + case AES_PADDING_PKCS7: + return aes_fill_with_padding_pkcs7( dest, padding_size, err_details); default: - return aesni_error_not_implemented( + return aes_error_not_implemented( err_details, "unsupported padding method"); } } diff --git a/utils/block_cmd_parser.hpp b/utils/block_cmd_parser.hpp index db6da84..c343152 100644 --- a/utils/block_cmd_parser.hpp +++ b/utils/block_cmd_parser.hpp @@ -30,15 +30,15 @@ namespace class Settings { public: - aesni::Algorithm get_algorithm() const { return algorithm; } - aesni::Mode get_mode() const { return mode; } + aes::Algorithm get_algorithm() const { return algorithm; } + aes::Mode get_mode() const { return mode; } bool use_boxes() const { return use_boxes_flag; } bool verbose() const { return verbose_flag; } private: - aesni::Algorithm algorithm; - aesni::Mode mode; + aes::Algorithm algorithm; + aes::Mode mode; bool use_boxes_flag = false; bool verbose_flag = false; @@ -61,8 +61,8 @@ namespace options.add_options() ("help,h", "show this message and exit") ("use-boxes,b", po::bool_switch(&settings.use_boxes_flag)->default_value(false), "use the \"boxes\" interface") - ("mode,m", po::value<aesni::Mode>(&settings.mode)->required(), "set mode of operation") - ("algorithm,a", po::value<aesni::Algorithm>(&settings.algorithm)->required(), "set algorithm") + ("mode,m", po::value<aes::Mode>(&settings.mode)->required(), "set mode of operation") + ("algorithm,a", po::value<aes::Algorithm>(&settings.algorithm)->required(), "set algorithm") ("verbose,v", po::bool_switch(&settings.verbose_flag)->default_value(false), "enable verbose output"); std::vector<std::string> args; @@ -112,7 +112,7 @@ namespace std::string iv_string; - if (aesni::mode_requires_initialization_vector(settings.get_mode())) + if (aes::mode_requires_initialization_vector(settings.get_mode())) { if (args.empty()) { @@ -137,7 +137,7 @@ namespace args.pop_front(); } - if (aesni::mode_requires_initialization_vector(settings.get_mode())) + if (aes::mode_requires_initialization_vector(settings.get_mode())) { inputs.emplace_back( std::move(key_string), diff --git a/utils/block_dumper.hpp b/utils/block_dumper.hpp index f41018d..d2b76bf 100644 --- a/utils/block_dumper.hpp +++ b/utils/block_dumper.hpp @@ -17,92 +17,92 @@ namespace { - template <aesni::Algorithm algorithm> - void dump_block(const char* name, const typename aesni::Types<algorithm>::Block& block) + template <aes::Algorithm algorithm> + void dump_block(const char* name, const typename aes::Types<algorithm>::Block& block) { - std::cout << name << ": " << aesni::to_string<algorithm>(block) << "\n" << aesni::to_matrix_string<algorithm>(block) << "\n"; + std::cout << name << ": " << aes::to_string<algorithm>(block) << "\n" << aes::to_matrix_string<algorithm>(block) << "\n"; } - template <aesni::Algorithm algorithm> - void dump_plaintext(const typename aesni::Types<algorithm>::Block& block) + template <aes::Algorithm algorithm> + void dump_plaintext(const typename aes::Types<algorithm>::Block& block) { dump_block<algorithm>("Plaintext", block); } - template <aesni::Algorithm algorithm> - void dump_key(const typename aesni::Types<algorithm>::Key& key) + template <aes::Algorithm algorithm> + void dump_key(const typename aes::Types<algorithm>::Key& key) { - std::cout << "Key: " << aesni::to_string<algorithm>(key) << "\n\n"; + std::cout << "Key: " << aes::to_string<algorithm>(key) << "\n\n"; } - template <aesni::Algorithm algorithm> - void dump_ciphertext(const typename aesni::Types<algorithm>::Block& ciphertext) + template <aes::Algorithm algorithm> + void dump_ciphertext(const typename aes::Types<algorithm>::Block& ciphertext) { dump_block<algorithm>("Ciphertext", ciphertext); } - template <aesni::Algorithm algorithm> - void dump_iv(const typename aesni::Types<algorithm>::Block& iv) + template <aes::Algorithm algorithm> + void dump_iv(const typename aes::Types<algorithm>::Block& iv) { dump_block<algorithm>("Initialization vector", iv); } - template <aesni::Algorithm algorithm> - void dump_round_keys(const char* name, const typename aesni::Types<algorithm>::RoundKeys& round_keys) + template <aes::Algorithm algorithm> + void dump_round_keys(const char* name, const typename aes::Types<algorithm>::RoundKeys& round_keys) { std::cout << name << ":\n"; - for (std::size_t i = 0; i < aesni::get_number_of_rounds<algorithm>(); ++i) - std::cout << "\t[" << i << "]: " << aesni::to_string<algorithm>(round_keys.keys[i]) << "\n"; + for (std::size_t i = 0; i < aes::get_number_of_rounds<algorithm>(); ++i) + std::cout << "\t[" << i << "]: " << aes::to_string<algorithm>(round_keys.keys[i]) << "\n"; std::cout << "\n"; } - template <aesni::Algorithm algorithm> - void dump_encryption_keys(const typename aesni::Types<algorithm>::RoundKeys& round_keys) + template <aes::Algorithm algorithm> + void dump_encryption_keys(const typename aes::Types<algorithm>::RoundKeys& round_keys) { dump_round_keys<algorithm>("Encryption round keys", round_keys); } - template <aesni::Algorithm algorithm> - void dump_decryption_keys(const typename aesni::Types<algorithm>::RoundKeys& round_keys) + template <aes::Algorithm algorithm> + void dump_decryption_keys(const typename aes::Types<algorithm>::RoundKeys& round_keys) { dump_round_keys<algorithm>("Decryption round keys", round_keys); } - template <aesni::Algorithm algorithm, aesni::Mode mode> + template <aes::Algorithm algorithm, aes::Mode mode> void dump_wrapper( - const aesni::EncryptWrapper<algorithm, mode>& wrapper) + const aes::EncryptWrapper<algorithm, mode>& wrapper) { dump_encryption_keys<algorithm>(wrapper.encryption_keys); } - template <aesni::Algorithm algorithm, aesni::Mode mode> + template <aes::Algorithm algorithm, aes::Mode mode> void dump_wrapper( - const aesni::DecryptWrapper<algorithm, mode>& wrapper) + const aes::DecryptWrapper<algorithm, mode>& wrapper) { dump_decryption_keys<algorithm>(wrapper.decryption_keys); } - template <aesni::Algorithm algorithm, aesni::Mode mode, typename std::enable_if<aesni::ModeRequiresInitializationVector<mode>::value>::type* = 0> + template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<aes::ModeRequiresInitializationVector<mode>::value>::type* = 0> void dump_next_iv( - const aesni::EncryptWrapper<algorithm, mode>& wrapper) + const aes::EncryptWrapper<algorithm, mode>& wrapper) { dump_block<algorithm>("Next initialization vector", wrapper.iv); } - template <aesni::Algorithm algorithm, aesni::Mode mode, typename std::enable_if<!aesni::ModeRequiresInitializationVector<mode>::value>::type* = 0> + template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<!aes::ModeRequiresInitializationVector<mode>::value>::type* = 0> void dump_next_iv( - const aesni::EncryptWrapper<algorithm, mode>&) + const aes::EncryptWrapper<algorithm, mode>&) { } - template <aesni::Algorithm algorithm, aesni::Mode mode, typename std::enable_if<aesni::ModeRequiresInitializationVector<mode>::value>::type* = 0> + template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<aes::ModeRequiresInitializationVector<mode>::value>::type* = 0> void dump_next_iv( - const aesni::DecryptWrapper<algorithm, mode>& wrapper) + const aes::DecryptWrapper<algorithm, mode>& wrapper) { dump_block<algorithm>("Next initialization vector", wrapper.iv); } - template <aesni::Algorithm algorithm, aesni::Mode mode, typename std::enable_if<!aesni::ModeRequiresInitializationVector<mode>::value>::type* = 0> + template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<!aes::ModeRequiresInitializationVector<mode>::value>::type* = 0> void dump_next_iv( - const aesni::DecryptWrapper<algorithm, mode>&) + const aes::DecryptWrapper<algorithm, mode>&) { } } diff --git a/utils/data_parsers.hpp b/utils/data_parsers.hpp index d081659..815a499 100644 --- a/utils/data_parsers.hpp +++ b/utils/data_parsers.hpp @@ -17,20 +17,20 @@ #include <map> #include <string> -static std::istream& operator>>(std::istream& is, aesni::Mode& dest) +static std::istream& operator>>(std::istream& is, aes::Mode& dest) { static const char* const argument_name = "mode"; std::string src; is >> src; - static std::map<std::string, aesni::Mode> lookup_table = + static std::map<std::string, aes::Mode> lookup_table = { - { "ecb", AESNI_ECB }, - { "cbc", AESNI_CBC }, - { "cfb", AESNI_CFB }, - { "ofb", AESNI_OFB }, - { "ctr", AESNI_CTR }, + { "ecb", AES_ECB }, + { "cbc", AES_CBC }, + { "cfb", AES_CFB }, + { "ofb", AES_OFB }, + { "ctr", AES_CTR }, }; const auto it = lookup_table.find(boost::algorithm::to_lower_copy(src)); @@ -42,18 +42,18 @@ static std::istream& operator>>(std::istream& is, aesni::Mode& dest) return is; } -static std::istream& operator>>(std::istream& is, aesni::Algorithm& dest) +static std::istream& operator>>(std::istream& is, aes::Algorithm& dest) { static const char* const argument_name = "algorithm"; std::string src; is >> src; - static std::map<std::string, aesni::Algorithm> lookup_table = + static std::map<std::string, aes::Algorithm> lookup_table = { - { "aes128", AESNI_AES128 }, - { "aes192", AESNI_AES192 }, - { "aes256", AESNI_AES256 }, + { "aes128", AES_AES128 }, + { "aes192", AES_AES192 }, + { "aes256", AES_AES256 }, }; const auto it = lookup_table.find(boost::algorithm::to_lower_copy(src)); diff --git a/utils/decrypt_block.cpp b/utils/decrypt_block.cpp index 7369052..2029669 100644 --- a/utils/decrypt_block.cpp +++ b/utils/decrypt_block.cpp @@ -21,33 +21,33 @@ namespace { - template <aesni::Algorithm algorithm, aesni::Mode mode> + template <aes::Algorithm algorithm, aes::Mode mode> void decrypt_with_mode( const Input& input, bool verbose = false) { - typename aesni::Types<algorithm>::Block iv; + typename aes::Types<algorithm>::Block iv; - if (aesni::ModeRequiresInitializationVector<mode>()) + if (aes::ModeRequiresInitializationVector<mode>()) { - aesni::from_string<algorithm>(iv, input.get_iv_string()); + aes::from_string<algorithm>(iv, input.get_iv_string()); if (verbose) dump_iv<algorithm>(iv); } - typename aesni::Types<algorithm>::Key key; - aesni::from_string<algorithm>(key, input.get_key_string()); + typename aes::Types<algorithm>::Key key; + aes::from_string<algorithm>(key, input.get_key_string()); if (verbose) dump_key<algorithm>(key); - aesni::DecryptWrapper<algorithm, mode> decrypt(key, iv); + aes::DecryptWrapper<algorithm, mode> decrypt(key, iv); if (verbose) dump_wrapper<algorithm, mode>(decrypt); for (const auto& input_block_string : input.get_input_block_strings()) { - typename aesni::Types<algorithm>::Block ciphertext, plaintext; - aesni::from_string<algorithm>(ciphertext, input_block_string); + typename aes::Types<algorithm>::Block ciphertext, plaintext; + aes::from_string<algorithm>(ciphertext, input_block_string); decrypt.decrypt_block(ciphertext, plaintext); @@ -59,37 +59,37 @@ namespace } else { - std::cout << aesni::to_string<algorithm>(plaintext) << '\n'; + std::cout << aes::to_string<algorithm>(plaintext) << '\n'; } } } - template <aesni::Algorithm algorithm> + template <aes::Algorithm algorithm> void decrypt_with_algorithm( - aesni::Mode mode, + aes::Mode mode, const Input& input, bool verbose = false) { switch (mode) { - case AESNI_ECB: - decrypt_with_mode<algorithm, AESNI_ECB>(input, verbose); + case AES_ECB: + decrypt_with_mode<algorithm, AES_ECB>(input, verbose); break; - case AESNI_CBC: - decrypt_with_mode<algorithm, AESNI_CBC>(input, verbose); + case AES_CBC: + decrypt_with_mode<algorithm, AES_CBC>(input, verbose); break; - case AESNI_CFB: - decrypt_with_mode<algorithm, AESNI_CFB>(input, verbose); + case AES_CFB: + decrypt_with_mode<algorithm, AES_CFB>(input, verbose); break; - case AESNI_OFB: - decrypt_with_mode<algorithm, AESNI_OFB>(input, verbose); + case AES_OFB: + decrypt_with_mode<algorithm, AES_OFB>(input, verbose); break; - case AESNI_CTR: - decrypt_with_mode<algorithm, AESNI_CTR>(input, verbose); + case AES_CTR: + decrypt_with_mode<algorithm, AES_CTR>(input, verbose); break; default: @@ -99,23 +99,23 @@ namespace } void decrypt_using_cxx_api( - aesni::Algorithm algorithm, - aesni::Mode mode, + aes::Algorithm algorithm, + aes::Mode mode, const Input& input, bool verbose = false) { switch (algorithm) { - case AESNI_AES128: - decrypt_with_algorithm<AESNI_AES128>(mode, input, verbose); + case AES_AES128: + decrypt_with_algorithm<AES_AES128>(mode, input, verbose); break; - case AESNI_AES192: - decrypt_with_algorithm<AESNI_AES192>(mode, input, verbose); + case AES_AES192: + decrypt_with_algorithm<AES_AES192>(mode, input, verbose); break; - case AESNI_AES256: - decrypt_with_algorithm<AESNI_AES256>(mode, input, verbose); + case AES_AES256: + decrypt_with_algorithm<AES_AES256>(mode, input, verbose); break; default: @@ -125,41 +125,41 @@ namespace } void decrypt_using_particular_box( - aesni::Box& box, + aes::Box& box, const std::vector<std::string>& input_block_strings) { for (const auto& input_block_string : input_block_strings) { - aesni::Box::Block ciphertext; + aes::Box::Block ciphertext; box.parse_block(ciphertext, input_block_string); - aesni::Box::Block plaintext; + aes::Box::Block plaintext; box.decrypt_block(ciphertext, plaintext); std::cout << box.format_block(plaintext) << '\n'; } } void decrypt_using_boxes( - aesni::Algorithm algorithm, - aesni::Mode mode, + aes::Algorithm algorithm, + aes::Mode mode, const Input& input) { - aesni::Box::Key key; - aesni::Box::parse_key(key, algorithm, input.get_key_string()); + aes::Box::Key key; + aes::Box::parse_key(key, algorithm, input.get_key_string()); - if (aesni::mode_requires_initialization_vector(mode)) + if (aes::mode_requires_initialization_vector(mode)) { - aesni::Box::Block iv; - aesni::Box::parse_block(iv, algorithm, input.get_iv_string()); + aes::Box::Block iv; + aes::Box::parse_block(iv, algorithm, input.get_iv_string()); decrypt_using_particular_box( - aesni::Box(algorithm, key, mode, iv), + aes::Box(algorithm, key, mode, iv), input.get_input_block_strings()); } else { decrypt_using_particular_box( - aesni::Box(algorithm, key), + aes::Box(algorithm, key), input.get_input_block_strings()); } } @@ -209,7 +209,7 @@ int main(int argc, char** argv) std::cerr << cmd_parser; return 1; } - catch (const aesni::Error& e) + catch (const aes::Error& e) { std::cerr << e; return 1; diff --git a/utils/decrypt_bmp.cpp b/utils/decrypt_bmp.cpp index c1f36bf..f098017 100644 --- a/utils/decrypt_bmp.cpp +++ b/utils/decrypt_bmp.cpp @@ -61,7 +61,7 @@ namespace } void decrypt_bmp( - aesni::Box& box, + aes::Box& box, const std::string& ciphertext_path, const std::string& plaintext_path) { @@ -91,23 +91,23 @@ namespace const auto& ciphertext_path = settings.get_input_path(); const auto& plaintext_path = settings.get_output_path(); - aesni::Box::Key key; - aesni::Box::parse_key(key, algorithm, settings.get_key_string()); + aes::Box::Key key; + aes::Box::parse_key(key, algorithm, settings.get_key_string()); - if (aesni::mode_requires_initialization_vector(mode)) + if (aes::mode_requires_initialization_vector(mode)) { - aesni::Box::Block iv; - aesni::Box::parse_block(iv, algorithm, settings.get_iv_string()); + aes::Box::Block iv; + aes::Box::parse_block(iv, algorithm, settings.get_iv_string()); decrypt_bmp( - aesni::Box(algorithm, key, mode, iv), + aes::Box(algorithm, key, mode, iv), ciphertext_path, plaintext_path); } else { decrypt_bmp( - aesni::Box(algorithm, key), + aes::Box(algorithm, key), ciphertext_path, plaintext_path); } @@ -138,7 +138,7 @@ int main(int argc, char** argv) std::cerr << cmd_parser; return 1; } - catch (const aesni::Error& e) + catch (const aes::Error& e) { std::cerr << e; return 1; diff --git a/utils/decrypt_file.cpp b/utils/decrypt_file.cpp index ad7e9d0..33083b7 100644 --- a/utils/decrypt_file.cpp +++ b/utils/decrypt_file.cpp @@ -58,7 +58,7 @@ namespace } void decrypt_file( - aesni::Box& box, + aes::Box& box, const std::string& ciphertext_path, const std::string& plaintext_path) { @@ -76,23 +76,23 @@ namespace const auto& ciphertext_path = settings.get_input_path(); const auto& plaintext_path = settings.get_output_path(); - aesni::Box::Key key; - aesni::Box::parse_key(key, algorithm, settings.get_key_string()); + aes::Box::Key key; + aes::Box::parse_key(key, algorithm, settings.get_key_string()); - if (aesni::mode_requires_initialization_vector(mode)) + if (aes::mode_requires_initialization_vector(mode)) { - aesni::Box::Block iv; - aesni::Box::parse_block(iv, algorithm, settings.get_iv_string()); + aes::Box::Block iv; + aes::Box::parse_block(iv, algorithm, settings.get_iv_string()); decrypt_file( - aesni::Box(algorithm, key, mode, iv), + aes::Box(algorithm, key, mode, iv), ciphertext_path, plaintext_path); } else { decrypt_file( - aesni::Box(algorithm, key), + aes::Box(algorithm, key), ciphertext_path, plaintext_path); } @@ -123,7 +123,7 @@ int main(int argc, char** argv) std::cerr << cmd_parser; return 1; } - catch (const aesni::Error& e) + catch (const aes::Error& e) { std::cerr << e; return 1; diff --git a/utils/encrypt_block.cpp b/utils/encrypt_block.cpp index 34b6d84..ac6a45a 100644 --- a/utils/encrypt_block.cpp +++ b/utils/encrypt_block.cpp @@ -21,33 +21,33 @@ namespace { - template <aesni::Algorithm algorithm, aesni::Mode mode> + template <aes::Algorithm algorithm, aes::Mode mode> void encrypt_with_mode( const Input& input, bool verbose = false) { - typename aesni::Types<algorithm>::Block iv; + typename aes::Types<algorithm>::Block iv; - if (aesni::ModeRequiresInitializationVector<mode>::value) + if (aes::ModeRequiresInitializationVector<mode>::value) { - aesni::from_string<algorithm>(iv, input.get_iv_string()); + aes::from_string<algorithm>(iv, input.get_iv_string()); if (verbose) dump_iv<algorithm>(iv); } - typename aesni::Types<algorithm>::Key key; - aesni::from_string<algorithm>(key, input.get_key_string()); + typename aes::Types<algorithm>::Key key; + aes::from_string<algorithm>(key, input.get_key_string()); if (verbose) dump_key<algorithm>(key); - aesni::EncryptWrapper<algorithm, mode> encrypt(key, iv); + aes::EncryptWrapper<algorithm, mode> encrypt(key, iv); if (verbose) dump_wrapper<algorithm, mode>(encrypt); for (const auto& input_block_string : input.get_input_block_strings()) { - typename aesni::Types<algorithm>::Block plaintext, ciphertext; - aesni::from_string<algorithm>(plaintext, input_block_string); + typename aes::Types<algorithm>::Block plaintext, ciphertext; + aes::from_string<algorithm>(plaintext, input_block_string); encrypt.encrypt_block(plaintext, ciphertext); @@ -59,37 +59,37 @@ namespace } else { - std::cout << aesni::to_string<algorithm>(ciphertext) << '\n'; + std::cout << aes::to_string<algorithm>(ciphertext) << '\n'; } } } - template <aesni::Algorithm algorithm> + template <aes::Algorithm algorithm> void encrypt_with_algorithm( - aesni::Mode mode, + aes::Mode mode, const Input& input, bool verbose = false) { switch (mode) { - case AESNI_ECB: - encrypt_with_mode<algorithm, AESNI_ECB>(input, verbose); + case AES_ECB: + encrypt_with_mode<algorithm, AES_ECB>(input, verbose); break; - case AESNI_CBC: - encrypt_with_mode<algorithm, AESNI_CBC>(input, verbose); + case AES_CBC: + encrypt_with_mode<algorithm, AES_CBC>(input, verbose); break; - case AESNI_CFB: - encrypt_with_mode<algorithm, AESNI_CFB>(input, verbose); + case AES_CFB: + encrypt_with_mode<algorithm, AES_CFB>(input, verbose); break; - case AESNI_OFB: - encrypt_with_mode<algorithm, AESNI_OFB>(input, verbose); + case AES_OFB: + encrypt_with_mode<algorithm, AES_OFB>(input, verbose); break; - case AESNI_CTR: - encrypt_with_mode<algorithm, AESNI_CTR>(input, verbose); + case AES_CTR: + encrypt_with_mode<algorithm, AES_CTR>(input, verbose); break; default: @@ -99,23 +99,23 @@ namespace } void encrypt_using_cxx_api( - aesni::Algorithm algorithm, - aesni::Mode mode, + aes::Algorithm algorithm, + aes::Mode mode, const Input& input, bool verbose = false) { switch (algorithm) { - case AESNI_AES128: - encrypt_with_algorithm<AESNI_AES128>(mode, input, verbose); + case AES_AES128: + encrypt_with_algorithm<AES_AES128>(mode, input, verbose); break; - case AESNI_AES192: - encrypt_with_algorithm<AESNI_AES192>(mode, input, verbose); + case AES_AES192: + encrypt_with_algorithm<AES_AES192>(mode, input, verbose); break; - case AESNI_AES256: - encrypt_with_algorithm<AESNI_AES256>(mode, input, verbose); + case AES_AES256: + encrypt_with_algorithm<AES_AES256>(mode, input, verbose); break; default: @@ -125,40 +125,40 @@ namespace } void encrypt_using_particular_box( - aesni::Box& box, + aes::Box& box, const std::vector<std::string>& input_block_strings) { for (const auto& input_block_string : input_block_strings) { - aesni::Box::Block plaintext; + aes::Box::Block plaintext; box.parse_block(plaintext, input_block_string); - aesni::Box::Block ciphertext; + aes::Box::Block ciphertext; box.encrypt_block(plaintext, ciphertext); std::cout << box.format_block(ciphertext) << '\n'; } } void encrypt_using_boxes( - aesni::Algorithm algorithm, - aesni::Mode mode, + aes::Algorithm algorithm, + aes::Mode mode, const Input& input) { - aesni::Box::Key key; - aesni::Box::parse_key(key, algorithm, input.get_key_string()); + aes::Box::Key key; + aes::Box::parse_key(key, algorithm, input.get_key_string()); - if (aesni::mode_requires_initialization_vector(mode)) + if (aes::mode_requires_initialization_vector(mode)) { - aesni::Box::Block iv; - aesni::Box::parse_block(iv, algorithm, input.get_iv_string()); + aes::Box::Block iv; + aes::Box::parse_block(iv, algorithm, input.get_iv_string()); encrypt_using_particular_box( - aesni::Box(algorithm, key, mode, iv), input.get_input_block_strings()); + aes::Box(algorithm, key, mode, iv), input.get_input_block_strings()); } else { encrypt_using_particular_box( - aesni::Box(algorithm, key), input.get_input_block_strings()); + aes::Box(algorithm, key), input.get_input_block_strings()); } } } @@ -207,7 +207,7 @@ int main(int argc, char** argv) std::cerr << cmd_parser; return 1; } - catch (const aesni::Error& e) + catch (const aes::Error& e) { std::cerr << e; return 1; diff --git a/utils/encrypt_bmp.cpp b/utils/encrypt_bmp.cpp index ea498cb..086e14d 100644 --- a/utils/encrypt_bmp.cpp +++ b/utils/encrypt_bmp.cpp @@ -61,7 +61,7 @@ namespace } void encrypt_bmp( - aesni::Box& box, + aes::Box& box, const std::string& plaintext_path, const std::string& ciphertext_path) { @@ -91,23 +91,23 @@ namespace const auto& plaintext_path = settings.get_input_path(); const auto& ciphertext_path = settings.get_output_path(); - aesni::Box::Key key; - aesni::Box::parse_key(key, algorithm, settings.get_key_string()); + aes::Box::Key key; + aes::Box::parse_key(key, algorithm, settings.get_key_string()); - if (aesni::mode_requires_initialization_vector(mode)) + if (aes::mode_requires_initialization_vector(mode)) { - aesni::Box::Block iv; - aesni::Box::parse_block(iv, algorithm, settings.get_iv_string()); + aes::Box::Block iv; + aes::Box::parse_block(iv, algorithm, settings.get_iv_string()); encrypt_bmp( - aesni::Box(algorithm, key, mode, iv), + aes::Box(algorithm, key, mode, iv), plaintext_path, ciphertext_path); } else { encrypt_bmp( - aesni::Box(algorithm, key), + aes::Box(algorithm, key), plaintext_path, ciphertext_path); } @@ -138,7 +138,7 @@ int main(int argc, char** argv) std::cerr << cmd_parser; return 1; } - catch (const aesni::Error& e) + catch (const aes::Error& e) { std::cerr << e; return 1; diff --git a/utils/encrypt_file.cpp b/utils/encrypt_file.cpp index 3ae8744..9a3dda8 100644 --- a/utils/encrypt_file.cpp +++ b/utils/encrypt_file.cpp @@ -58,7 +58,7 @@ namespace } void encrypt_file( - aesni::Box& box, + aes::Box& box, const std::string& plaintext_path, const std::string& ciphertext_path) { @@ -76,23 +76,23 @@ namespace const auto& plaintext_path = settings.get_input_path(); const auto& ciphertext_path = settings.get_output_path(); - aesni::Box::Key key; - aesni::Box::parse_key(key, algorithm, settings.get_key_string()); + aes::Box::Key key; + aes::Box::parse_key(key, algorithm, settings.get_key_string()); - if (aesni::mode_requires_initialization_vector(mode)) + if (aes::mode_requires_initialization_vector(mode)) { - aesni::Box::Block iv; - aesni::Box::parse_block(iv, algorithm, settings.get_iv_string()); + aes::Box::Block iv; + aes::Box::parse_block(iv, algorithm, settings.get_iv_string()); encrypt_file( - aesni::Box(algorithm, key, mode, iv), + aes::Box(algorithm, key, mode, iv), plaintext_path, ciphertext_path); } else { encrypt_file( - aesni::Box(algorithm, key), + aes::Box(algorithm, key), plaintext_path, ciphertext_path); } @@ -123,7 +123,7 @@ int main(int argc, char** argv) std::cerr << cmd_parser; return 1; } - catch (const aesni::Error& e) + catch (const aes::Error& e) { std::cerr << e; return 1; diff --git a/utils/file_cmd_parser.hpp b/utils/file_cmd_parser.hpp index c8061fa..c59e05d 100644 --- a/utils/file_cmd_parser.hpp +++ b/utils/file_cmd_parser.hpp @@ -28,8 +28,8 @@ namespace public: Settings() = default; - aesni::Mode get_mode() const { return mode; } - aesni::Algorithm get_algorithm() const { return algorithm; } + aes::Mode get_mode() const { return mode; } + aes::Algorithm get_algorithm() const { return algorithm; } const std::string& get_input_path() const { return input_path; } const std::string& get_output_path() const { return output_path; } @@ -38,8 +38,8 @@ namespace const std::string& get_iv_string() const { return iv; } private: - aesni::Mode mode; - aesni::Algorithm algorithm; + aes::Mode mode; + aes::Algorithm algorithm; std::string input_path; std::string output_path; @@ -63,8 +63,8 @@ namespace options.add_options() ("help,h", "show this message and exit") - ("mode,m", po::value<aesni::Mode>(&settings.mode)->required(), "set mode of operation") - ("algorithm,a", po::value<aesni::Algorithm>(&settings.algorithm)->required(), "set algorithm") + ("mode,m", po::value<aes::Mode>(&settings.mode)->required(), "set mode of operation") + ("algorithm,a", po::value<aes::Algorithm>(&settings.algorithm)->required(), "set algorithm") ("input-path,i", po::value<std::string>(&settings.input_path)->required(), "set input file path") ("output-path,o", po::value<std::string>(&settings.output_path)->required(), "set output file path") ("key,k", po::value<std::string>(&settings.key)->required(), "set encryption key") @@ -81,7 +81,7 @@ namespace po::notify(vm); - if (aesni::mode_requires_initialization_vector(settings.get_mode())) + if (aes::mode_requires_initialization_vector(settings.get_mode())) { if (!vm.count("iv")) { |