diff options
61 files changed, 859 insertions, 913 deletions
diff --git a/cxx/include/aesnixx/aes.hpp b/cxx/include/aesnixx/aes.hpp new file mode 100644 index 0000000..d30fd60 --- /dev/null +++ b/cxx/include/aesnixx/aes.hpp @@ -0,0 +1,132 @@ +/** + * \file + * \author Egor Tensin <Egor.Tensin@gmail.com> + * \date 2015 + * \copyright This file is licensed under the terms of the MIT License. + * See LICENSE.txt for details. + */ + +#include "data.hpp" + +#include <aesni/all.h> + +#include <string> + +#pragma once + +namespace aesni +{ + namespace aes + { + typedef AesNI_Aes_Block Block; + + typedef AesNI_Aes128_Key Key128; + typedef AesNI_Aes192_Key Key192; + typedef AesNI_Aes256_Key Key256; + + inline void make_block(Block& dest, int hi3, int hi2, int lo1, int lo0) + { + aesni_aes_make_block(&dest, hi3, hi2, lo1, lo0); + } + + inline void make_key(Key128& dest, int hi3, int hi2, int lo1, int lo0) + { + aesni_aes128_make_key(&dest, hi3, hi2, lo1, lo0); + } + + inline void make_key(Key192& dest, int hi5, int hi4, int hi3, int lo2, int lo1, int lo0) + { + aesni_aes192_make_key(&dest, hi5, hi4, hi3, lo2, lo1, lo0); + } + + inline void make_key(Key256& dest, int hi7, int hi6, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0) + { + aesni_aes256_make_key(&dest, hi7, hi6, hi5, hi4, lo3, lo2, lo1, lo0); + } + + std::string to_string(const Block& block) + { + AesNI_Aes_BlockString str; + aesni_aes_format_block(&str, &block, ErrorDetailsThrowsInDestructor()); + return std::string(str.str); + } + + std::string to_matrix_string(const Block& block) + { + AesNI_Aes_BlockMatrixString str; + aesni_aes_format_block_as_matrix(&str, &block, ErrorDetailsThrowsInDestructor()); + return std::string(str.str); + } + + inline void from_string(Block& dest, const char* src) + { + aesni_aes_parse_block(&dest, src, ErrorDetailsThrowsInDestructor()); + } + + inline void from_string(Block& dest, const std::string& src) + { + from_string(dest, src.c_str()); + } + + std::string to_string(const Key128& block) + { + AesNI_Aes128_KeyString str; + aesni_aes128_format_key(&str, &block, ErrorDetailsThrowsInDestructor()); + return std::string(str.str); + } + + std::string to_string(const Key192& block) + { + AesNI_Aes192_KeyString str; + aesni_aes192_format_key(&str, &block, ErrorDetailsThrowsInDestructor()); + return std::string(str.str); + } + + std::string to_string(const Key256& block) + { + AesNI_Aes256_KeyString str; + aesni_aes256_format_key(&str, &block, ErrorDetailsThrowsInDestructor()); + return std::string(str.str); + } + + inline void from_string(Key128& dest, const char* src) + { + aesni_aes128_parse_key(&dest, src, ErrorDetailsThrowsInDestructor()); + } + + inline void from_string(Key192& dest, const char* src) + { + aesni_aes192_parse_key(&dest, src, ErrorDetailsThrowsInDestructor()); + } + + inline void from_string(Key256& dest, const char* src) + { + aesni_aes256_parse_key(&dest, src, ErrorDetailsThrowsInDestructor()); + } + + inline void from_string(Key128& dest, const std::string& src) + { + return from_string(dest, src.c_str()); + } + + inline void from_string(Key192& dest, const std::string& src) + { + return from_string(dest, src.c_str()); + } + + inline void from_string(Key256& dest, const std::string& src) + { + return from_string(dest, src.c_str()); + } + + typedef AesNI_Aes128_RoundKeys RoundKeys128; + typedef AesNI_Aes192_RoundKeys RoundKeys192; + typedef AesNI_Aes256_RoundKeys RoundKeys256; + + template <typename RoundKeysT> + inline std::size_t get_number_of_keys(const RoundKeysT& round_keys) + { + return sizeof(round_keys) / sizeof(Block128); + } + } +} diff --git a/cxx/include/aesnixx/all.hpp b/cxx/include/aesnixx/all.hpp index f105059..72ea262 100644 --- a/cxx/include/aesnixx/all.hpp +++ b/cxx/include/aesnixx/all.hpp @@ -8,5 +8,6 @@ #pragma once +#include "aes.hpp" #include "data.hpp" #include "error.hpp" diff --git a/cxx/include/aesnixx/data.hpp b/cxx/include/aesnixx/data.hpp index e620915..1eaac24 100644 --- a/cxx/include/aesnixx/data.hpp +++ b/cxx/include/aesnixx/data.hpp @@ -12,129 +12,12 @@ #include <aesni/all.h> -#include <cstdlib> - -#include <ostream> -#include <string> - namespace aesni { typedef AesNI_Block128 Block128; - typedef AesNI_Block192 Block192; - typedef AesNI_Block256 Block256; - - typedef AesNI_Aes128_RoundKeys KeySchedule128; - typedef AesNI_Aes192_RoundKeys KeySchedule192; - typedef AesNI_Aes256_RoundKeys KeySchedule256; - - template <typename KeyScheduleT> - inline std::size_t get_number_of_keys(const KeyScheduleT& round_keys) - { - return sizeof(round_keys) / sizeof(Block128); - } inline void make_block(Block128& dest, int hi3, int hi2, int lo1, int lo0) { dest = aesni_make_block128(hi3, hi2, lo1, lo0); } - - inline void make_block(Block192& dest, int hi5, int hi4, int hi3, int lo2, int lo1, int lo0) - { - dest = aesni_make_block192(hi5, hi4, hi3, lo2, lo1, lo0); - } - - inline void make_block(Block256& dest, int hi7, int hi6, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0) - { - dest = aesni_make_block256(hi7, hi6, hi5, hi4, lo3, lo2, lo1, lo0); - } - - std::string to_string(const Block128& block) - { - AesNI_BlockString128 str; - aesni_format_block128(&str, &block, ErrorDetailsThrowsInDestructor()); - return std::string(str.str); - } - - std::string to_string(const Block192& block) - { - AesNI_BlockString192 str; - aesni_format_block192(&str, &block, ErrorDetailsThrowsInDestructor()); - return std::string(str.str); - } - - std::string to_string(const Block256& block) - { - AesNI_BlockString256 str; - aesni_format_block256(&str, &block, ErrorDetailsThrowsInDestructor()); - return std::string(str.str); - } - - void from_string(Block128& dest, const char* src) - { - aesni_parse_block128(&dest, src, ErrorDetailsThrowsInDestructor()); - } - - void from_string(Block192& dest, const char* src) - { - aesni_parse_block192(&dest, src, ErrorDetailsThrowsInDestructor()); - } - - void from_string(Block256& dest, const char* src) - { - aesni_parse_block256(&dest, src, ErrorDetailsThrowsInDestructor()); - } - - void from_string(Block128& dest, const std::string& src) - { - return from_string(dest, src.c_str()); - } - - void from_string(Block192& dest, const std::string& src) - { - return from_string(dest, src.c_str()); - } - - void from_string(Block256& dest, const std::string& src) - { - return from_string(dest, src.c_str()); - } - - std::string to_matrix_string(const Block128& block) - { - AesNI_BlockMatrixString128 str; - aesni_format_block128_as_matrix(&str, &block, ErrorDetailsThrowsInDestructor()); - return std::string(str.str); - } - - std::string to_matrix_string(const Block192& block) - { - AesNI_BlockMatrixString192 str; - aesni_format_block192_as_matrix(&str, &block, ErrorDetailsThrowsInDestructor()); - return std::string(str.str); - } - - std::string to_matrix_string(const Block256& block) - { - AesNI_BlockMatrixString256 str; - aesni_format_block256_as_matrix(&str, &block, ErrorDetailsThrowsInDestructor()); - return std::string(str.str); - } -} - -namespace -{ - std::ostream& operator<<(std::ostream& os, const aesni::Block128& block) - { - return os << aesni::to_string(block); - } - - std::ostream& operator<<(std::ostream& os, const aesni::Block192& block) - { - return os << aesni::to_string(block); - } - - std::ostream& operator<<(std::ostream& os, const aesni::Block256& block) - { - return os << aesni::to_string(block); - } } diff --git a/examples/aes128cbc.cpp b/examples/aes128cbc.cpp index 5bb8c67..b6253e6 100644 --- a/examples/aes128cbc.cpp +++ b/examples/aes128cbc.cpp @@ -19,29 +19,29 @@ int main() { try { - aesni::Block128 plaintext; + aesni::aes::Block plaintext; make_default_plaintext(plaintext); - aesni::Block128 key; + aesni::aes::Key128 key; make_default_key(key); - aesni::Block128 iv; + aesni::aes::Block iv; make_default_iv(iv); - aesni::KeySchedule128 encryption_schedule; - aesni_aes128_expand_key(key, &encryption_schedule); + aesni::aes::RoundKeys128 encryption_schedule; + aesni_aes128_expand_key(&key, &encryption_schedule); dump_encryption_schedule(encryption_schedule); - aesni::Block128 next_iv; + aesni::aes::Block next_iv; const auto ciphertext = aesni_aes128_encrypt_block_cbc(plaintext, &encryption_schedule, iv, &next_iv); dump_ciphertext(ciphertext); dump_next_iv(next_iv); - aesni::KeySchedule128 decryption_schedule; + aesni::aes::RoundKeys128 decryption_schedule; aesni_aes128_derive_decryption_keys(&encryption_schedule, &decryption_schedule); dump_decryption_schedule(decryption_schedule); - aesni::Block128 decrypted = aesni_aes128_decrypt_block_cbc(ciphertext, &decryption_schedule, iv, &next_iv); + aesni::aes::Block decrypted = aesni_aes128_decrypt_block_cbc(ciphertext, &decryption_schedule, iv, &next_iv); dump_decrypted(decrypted); dump_next_iv(next_iv); diff --git a/examples/aes128cfb.cpp b/examples/aes128cfb.cpp index b5f78a7..472b0c3 100644 --- a/examples/aes128cfb.cpp +++ b/examples/aes128cfb.cpp @@ -19,20 +19,20 @@ int main() { try { - aesni::Block128 plaintext; + aesni::aes::Block plaintext; make_default_plaintext(plaintext); - aesni::Block128 key; + aesni::aes::Key128 key; make_default_key(key); - aesni::Block128 iv; + aesni::aes::Block iv; make_default_iv(iv); - aesni::KeySchedule128 encryption_schedule; - aesni_aes128_expand_key(key, &encryption_schedule); + aesni::aes::RoundKeys128 encryption_schedule; + aesni_aes128_expand_key(&key, &encryption_schedule); dump_encryption_schedule(encryption_schedule); - aesni::Block128 next_iv; + aesni::aes::Block next_iv; const auto ciphertext = aesni_aes128_encrypt_block_cfb(plaintext, &encryption_schedule, iv, &next_iv); dump_ciphertext(ciphertext); dump_next_iv(next_iv); diff --git a/examples/aes128ctr.cpp b/examples/aes128ctr.cpp index 0515336..3f64173 100644 --- a/examples/aes128ctr.cpp +++ b/examples/aes128ctr.cpp @@ -19,17 +19,17 @@ int main() { try { - aesni::Block128 plaintext; + aesni::aes::Block plaintext; make_default_plaintext(plaintext); - aesni::Block128 key; + aesni::aes::Key128 key; make_default_key(key); - aesni::Block128 iv; + aesni::aes::Block iv; make_default_iv(iv); - aesni::KeySchedule128 encryption_schedule; - aesni_aes128_expand_key(key, &encryption_schedule); + aesni::aes::RoundKeys128 encryption_schedule; + aesni_aes128_expand_key(&key, &encryption_schedule); dump_encryption_schedule(encryption_schedule); const auto ciphertext = aesni_aes128_encrypt_block_ctr(plaintext, &encryption_schedule, iv, 0); diff --git a/examples/aes128ecb.cpp b/examples/aes128ecb.cpp index b33c00a..cf0d033 100644 --- a/examples/aes128ecb.cpp +++ b/examples/aes128ecb.cpp @@ -19,20 +19,20 @@ int main() { try { - aesni::Block128 plaintext; + aesni::aes::Block plaintext; make_default_plaintext(plaintext); - aesni::Block128 key; + aesni::aes::Key128 key; make_default_key(key); - aesni::KeySchedule128 encryption_schedule; - aesni_aes128_expand_key(key, &encryption_schedule); + aesni::aes::RoundKeys128 encryption_schedule; + aesni_aes128_expand_key(&key, &encryption_schedule); dump_encryption_schedule(encryption_schedule); const auto ciphertext = aesni_aes128_encrypt_block_ecb(plaintext, &encryption_schedule); dump_ciphertext(ciphertext); - aesni::KeySchedule128 decryption_schedule; + aesni::aes::RoundKeys128 decryption_schedule; aesni_aes128_derive_decryption_keys(&encryption_schedule, &decryption_schedule); dump_decryption_schedule(decryption_schedule); diff --git a/examples/aes128ofb.cpp b/examples/aes128ofb.cpp index da3d750..d6a5c87 100644 --- a/examples/aes128ofb.cpp +++ b/examples/aes128ofb.cpp @@ -19,20 +19,20 @@ int main() { try { - aesni::Block128 plaintext; + aesni::aes::Block plaintext; make_default_plaintext(plaintext); - aesni::Block128 key; + aesni::aes::Key128 key; make_default_key(key); - aesni::Block128 iv; + aesni::aes::Block iv; make_default_iv(iv); - aesni::KeySchedule128 encryption_schedule; - aesni_aes128_expand_key(key, &encryption_schedule); + aesni::aes::RoundKeys128 encryption_schedule; + aesni_aes128_expand_key(&key, &encryption_schedule); dump_encryption_schedule(encryption_schedule); - aesni::Block128 next_iv; + aesni::aes::Block next_iv; const auto ciphertext = aesni_aes128_encrypt_block_ofb(plaintext, &encryption_schedule, iv, &next_iv); dump_ciphertext(ciphertext); dump_next_iv(next_iv); diff --git a/examples/aes192cbc.cpp b/examples/aes192cbc.cpp index 6d7ff74..2c18d34 100644 --- a/examples/aes192cbc.cpp +++ b/examples/aes192cbc.cpp @@ -19,25 +19,25 @@ int main() { try { - aesni::Block128 plaintext; + aesni::aes::Block plaintext; make_default_plaintext(plaintext); - aesni::Block192 key; + aesni::aes::Key192 key; make_default_key(key); - aesni::Block128 iv; + aesni::aes::Block iv; make_default_iv(iv); - aesni::KeySchedule192 encryption_schedule; + aesni::aes::RoundKeys192 encryption_schedule; aesni_aes192_expand_key(&key, &encryption_schedule); dump_encryption_schedule(encryption_schedule); - aesni::Block128 next_iv; + aesni::aes::Block next_iv; const auto ciphertext = aesni_aes192_encrypt_block_cbc(plaintext, &encryption_schedule, iv, &next_iv); dump_ciphertext(ciphertext); dump_next_iv(next_iv); - aesni::KeySchedule192 decryption_schedule; + aesni::aes::RoundKeys192 decryption_schedule; aesni_aes192_derive_decryption_keys(&encryption_schedule, &decryption_schedule); dump_decryption_schedule(decryption_schedule); diff --git a/examples/aes192cfb.cpp b/examples/aes192cfb.cpp index a8662ca..4deaf1c 100644 --- a/examples/aes192cfb.cpp +++ b/examples/aes192cfb.cpp @@ -19,20 +19,20 @@ int main() { try { - aesni::Block128 plaintext; + aesni::aes::Block plaintext; make_default_plaintext(plaintext); - aesni::Block192 key; + aesni::aes::Key192 key; make_default_key(key); - aesni::Block128 iv; + aesni::aes::Block iv; make_default_iv(iv); - aesni::KeySchedule192 encryption_schedule; + aesni::aes::RoundKeys192 encryption_schedule; aesni_aes192_expand_key(&key, &encryption_schedule); dump_encryption_schedule(encryption_schedule); - aesni::Block128 next_iv; + aesni::aes::Block next_iv; const auto ciphertext = aesni_aes192_encrypt_block_cfb(plaintext, &encryption_schedule, iv, &next_iv); dump_ciphertext(ciphertext); dump_next_iv(next_iv); diff --git a/examples/aes192ctr.cpp b/examples/aes192ctr.cpp index ef4dde6..022bc33 100644 --- a/examples/aes192ctr.cpp +++ b/examples/aes192ctr.cpp @@ -19,16 +19,16 @@ int main() { try { - aesni::Block128 plaintext; + aesni::aes::Block plaintext; make_default_plaintext(plaintext); - aesni::Block192 key; + aesni::aes::Key192 key; make_default_key(key); - aesni::Block128 iv; + aesni::aes::Block iv; make_default_iv(iv); - aesni::KeySchedule192 encryption_schedule; + aesni::aes::RoundKeys192 encryption_schedule; aesni_aes192_expand_key(&key, &encryption_schedule); dump_encryption_schedule(encryption_schedule); diff --git a/examples/aes192ecb.cpp b/examples/aes192ecb.cpp index 6faf96f..6de3e16 100644 --- a/examples/aes192ecb.cpp +++ b/examples/aes192ecb.cpp @@ -19,20 +19,20 @@ int main() { try { - aesni::Block128 plaintext; + aesni::aes::Block plaintext; make_default_plaintext(plaintext); - aesni::Block192 key; + aesni::aes::Key192 key; make_default_key(key); - aesni::KeySchedule192 encryption_schedule; + aesni::aes::RoundKeys192 encryption_schedule; aesni_aes192_expand_key(&key, &encryption_schedule); dump_encryption_schedule(encryption_schedule); const auto ciphertext = aesni_aes192_encrypt_block_ecb(plaintext, &encryption_schedule); dump_ciphertext(ciphertext); - aesni::KeySchedule192 decryption_schedule; + aesni::aes::RoundKeys192 decryption_schedule; aesni_aes192_derive_decryption_keys(&encryption_schedule, &decryption_schedule); dump_decryption_schedule(decryption_schedule); diff --git a/examples/aes192ofb.cpp b/examples/aes192ofb.cpp index e7de746..df907cd 100644 --- a/examples/aes192ofb.cpp +++ b/examples/aes192ofb.cpp @@ -19,20 +19,20 @@ int main() { try { - aesni::Block128 plaintext; + aesni::aes::Block plaintext; make_default_plaintext(plaintext); - aesni::Block192 key; + aesni::aes::Key192 key; make_default_key(key); - aesni::Block128 iv; + aesni::aes::Block iv; make_default_iv(iv); - aesni::KeySchedule192 encryption_schedule; + aesni::aes::RoundKeys192 encryption_schedule; aesni_aes192_expand_key(&key, &encryption_schedule); dump_encryption_schedule(encryption_schedule); - aesni::Block128 next_iv; + aesni::aes::Block next_iv; const auto ciphertext = aesni_aes192_encrypt_block_ofb(plaintext, &encryption_schedule, iv, &next_iv); dump_ciphertext(ciphertext); dump_next_iv(next_iv); diff --git a/examples/aes256cbc.cpp b/examples/aes256cbc.cpp index 66f7c38..9123c9b 100644 --- a/examples/aes256cbc.cpp +++ b/examples/aes256cbc.cpp @@ -19,25 +19,25 @@ int main() { try { - aesni::Block128 plaintext; + aesni::aes::Block plaintext; make_default_plaintext(plaintext); - aesni::Block256 key; + aesni::aes::Key256 key; make_default_key(key); - aesni::Block128 iv; + aesni::aes::Block iv; make_default_iv(iv); - aesni::KeySchedule256 encryption_schedule; + aesni::aes::RoundKeys256 encryption_schedule; aesni_aes256_expand_key(&key, &encryption_schedule); dump_encryption_schedule(encryption_schedule); - aesni::Block128 next_iv; + aesni::aes::Block next_iv; const auto ciphertext = aesni_aes256_encrypt_block_cbc(plaintext, &encryption_schedule, iv, &next_iv); dump_ciphertext(ciphertext); dump_next_iv(next_iv); - aesni::KeySchedule256 decryption_schedule; + aesni::aes::RoundKeys256 decryption_schedule; aesni_aes256_derive_decryption_keys(&encryption_schedule, &decryption_schedule); dump_decryption_schedule(decryption_schedule); diff --git a/examples/aes256cfb.cpp b/examples/aes256cfb.cpp index 8a23146..a6e8ba7 100644 --- a/examples/aes256cfb.cpp +++ b/examples/aes256cfb.cpp @@ -19,20 +19,20 @@ int main() { try { - aesni::Block128 plaintext; + aesni::aes::Block plaintext; make_default_plaintext(plaintext); - aesni::Block256 key; + aesni::aes::Key256 key; make_default_key(key); - aesni::Block128 iv; + aesni::aes::Block iv; make_default_iv(iv); - aesni::KeySchedule256 encryption_schedule; + aesni::aes::RoundKeys256 encryption_schedule; aesni_aes256_expand_key(&key, &encryption_schedule); dump_encryption_schedule(encryption_schedule); - aesni::Block128 next_iv; + aesni::aes::Block next_iv; const auto ciphertext = aesni_aes256_encrypt_block_cfb(plaintext, &encryption_schedule, iv, &next_iv); dump_ciphertext(ciphertext); dump_next_iv(next_iv); diff --git a/examples/aes256ctr.cpp b/examples/aes256ctr.cpp index b5e2ae7..3360c76 100644 --- a/examples/aes256ctr.cpp +++ b/examples/aes256ctr.cpp @@ -19,16 +19,16 @@ int main() { try { - aesni::Block128 plaintext; + aesni::aes::Block plaintext; make_default_plaintext(plaintext); - aesni::Block256 key; + aesni::aes::Key256 key; make_default_key(key); - aesni::Block128 iv; + aesni::aes::Block iv; make_default_iv(iv); - aesni::KeySchedule256 encryption_schedule; + aesni::aes::RoundKeys256 encryption_schedule; aesni_aes256_expand_key(&key, &encryption_schedule); dump_encryption_schedule(encryption_schedule); diff --git a/examples/aes256ecb.cpp b/examples/aes256ecb.cpp index aebd14b..d11aaa6 100644 --- a/examples/aes256ecb.cpp +++ b/examples/aes256ecb.cpp @@ -19,20 +19,20 @@ int main() { try { - aesni::Block128 plaintext; + aesni::aes::Block plaintext; make_default_plaintext(plaintext); - aesni::Block256 key; + aesni::aes::Key256 key; make_default_key(key); - aesni::KeySchedule256 encryption_schedule; + aesni::aes::RoundKeys256 encryption_schedule; aesni_aes256_expand_key(&key, &encryption_schedule); dump_encryption_schedule(encryption_schedule); const auto ciphertext = aesni_aes256_encrypt_block_ecb(plaintext, &encryption_schedule); dump_ciphertext(ciphertext); - aesni::KeySchedule256 decryption_schedule; + aesni::aes::RoundKeys256 decryption_schedule; aesni_aes256_derive_decryption_keys(&encryption_schedule, &decryption_schedule); dump_decryption_schedule(decryption_schedule); diff --git a/examples/aes256ofb.cpp b/examples/aes256ofb.cpp index cf1f1a0..b4f9a1f 100644 --- a/examples/aes256ofb.cpp +++ b/examples/aes256ofb.cpp @@ -19,20 +19,20 @@ int main() { try { - aesni::Block128 plaintext; + aesni::aes::Block plaintext; make_default_plaintext(plaintext); - aesni::Block256 key; + aesni::aes::Key256 key; make_default_key(key); - aesni::Block128 iv; + aesni::aes::Block iv; make_default_iv(iv); - aesni::KeySchedule256 encryption_schedule; + aesni::aes::RoundKeys256 encryption_schedule; aesni_aes256_expand_key(&key, &encryption_schedule); dump_encryption_schedule(encryption_schedule); - aesni::Block128 next_iv; + aesni::aes::Block next_iv; const auto ciphertext = aesni_aes256_encrypt_block_ofb(plaintext, &encryption_schedule, iv, &next_iv); dump_ciphertext(ciphertext); dump_next_iv(next_iv); diff --git a/examples/common.hpp b/examples/common.hpp index 0188352..d7b3394 100644 --- a/examples/common.hpp +++ b/examples/common.hpp @@ -16,68 +16,67 @@ namespace { - template <typename BlockT> - void dump_block(const char* name, const BlockT& block) + void dump_block(const char* name, const aesni::aes::Block& block) { - std::cout << name << ": " << block << "\n" << aesni::to_matrix_string(block) << "\n"; + std::cout << name << ": " << aesni::aes::to_string(block) << "\n" << aesni::aes::to_matrix_string(block) << "\n"; } - void dump_plaintext(const aesni::Block128& block) + void dump_plaintext(const aesni::aes::Block& block) { dump_block("Plaintext", block); } - template <typename BlockT> - void dump_key(const BlockT& key) + template <typename KeyT> + void dump_key(const KeyT& key) { - dump_block("Key", key); + std::cout << "Key: " << aesni::aes::to_string(key) << "\n"; } - void dump_ciphertext(const aesni::Block128& ciphertext) + void dump_ciphertext(const aesni::aes::Block& ciphertext) { dump_block("Ciphertext", ciphertext); } - void dump_iv(const aesni::Block128& iv) + void dump_iv(const aesni::aes::Block& iv) { dump_block("Initialization vector", iv); } - void dump_next_iv(const aesni::Block128& next_iv) + void dump_next_iv(const aesni::aes::Block& next_iv) { dump_block("Next initialization vector", next_iv); } - void dump_decrypted(const aesni::Block128& decrypted) + void dump_decrypted(const aesni::aes::Block& decrypted) { dump_block("Decrypted", decrypted); } - void make_default_plaintext(aesni::Block128& plaintext) + void make_default_plaintext(aesni::aes::Block& plaintext) { aesni::make_block(plaintext, 0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100); dump_plaintext(plaintext); } - void make_default_key(aesni::Block128& key) + void make_default_key(aesni::aes::Key128& key) { - aesni::make_block(key, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); + aesni::aes::make_key(key, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); dump_key(key); } - void make_default_key(aesni::Block192& key) + void make_default_key(aesni::aes::Key192& key) { - aesni::make_block(key, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); + aesni::aes::make_key(key, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); dump_key(key); } - void make_default_key(aesni::Block256& key) + void make_default_key(aesni::aes::Key256& key) { - aesni::make_block(key, 0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); + aesni::aes::make_key(key, 0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); dump_key(key); } - void make_default_iv(aesni::Block128& iv) + void make_default_iv(aesni::aes::Block& iv) { aesni::make_block(iv, 0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210); dump_iv(iv); @@ -87,8 +86,8 @@ namespace void dump_schedule(const char* name, const KeyScheduleT& schedule) { std::cout << name << ":\n"; - for (std::size_t i = 0; i < aesni::get_number_of_keys(schedule); ++i) - std::cout << "\t[" << i << "]: " << schedule.keys[i] << "\n"; + for (std::size_t i = 0; i < aesni::aes::get_number_of_keys(schedule); ++i) + std::cout << "\t[" << i << "]: " << aesni::aes::to_string(schedule.keys[i]) << "\n"; std::cout << "\n"; } diff --git a/include/aesni/aes.h b/include/aesni/aes.h index 6e11b0c..c4429eb 100644 --- a/include/aesni/aes.h +++ b/include/aesni/aes.h @@ -17,6 +17,122 @@ extern "C" { #endif +typedef AesNI_Block128 AesNI_Aes_Block; + +typedef struct +{ + AesNI_Aes_Block key; +} +AesNI_Aes128_Key; + +typedef struct +{ + AesNI_Aes_Block hi; + AesNI_Aes_Block lo; +} +AesNI_Aes192_Key; + +typedef struct +{ + AesNI_Aes_Block hi; + AesNI_Aes_Block lo; +} +AesNI_Aes256_Key; + +static __inline void aesni_aes_make_block(AesNI_Aes_Block* dest, int hi3, int hi2, int lo1, int lo0) +{ + *dest = aesni_make_block128(hi3, hi2, lo1, lo0); +} + +static __inline void aesni_aes128_make_key(AesNI_Aes128_Key* dest, int hi3, int hi2, int lo1, int lo0) +{ + dest->key = aesni_make_block128(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) +{ + dest->hi = aesni_make_block128(0, 0, hi5, hi4); + dest->lo = aesni_make_block128(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) +{ + dest->hi = aesni_make_block128(hi7, hi6, hi5, hi4); + dest->lo = aesni_make_block128(lo3, lo2, lo1, lo0); +} + +typedef struct { char str[33]; } AesNI_Aes_BlockString; +typedef struct { char str[49]; } AesNI_Aes_BlockMatrixString; + +AesNI_StatusCode aesni_aes_format_block( + AesNI_Aes_BlockString*, + const AesNI_Aes_Block*, + AesNI_ErrorDetails*); + +AesNI_StatusCode aesni_aes_format_block_as_matrix( + AesNI_Aes_BlockMatrixString*, + const AesNI_Aes_Block*, + AesNI_ErrorDetails*); + +AesNI_StatusCode aesni_aes_print_block( + const AesNI_Aes_Block*, + AesNI_ErrorDetails*); + +AesNI_StatusCode aesni_aes_print_block_as_matrix( + const AesNI_Aes_Block*, + AesNI_ErrorDetails*); + +AesNI_StatusCode aesni_aes_parse_block( + AesNI_Aes_Block* dest, + const char* src, + AesNI_ErrorDetails* err_details); + +typedef AesNI_Aes_BlockString AesNI_Aes128_KeyString; +typedef struct { char str[49]; } AesNI_Aes192_KeyString; +typedef struct { char str[65]; } AesNI_Aes256_KeyString; + +AesNI_StatusCode aesni_aes128_format_key( + AesNI_Aes128_KeyString*, + const AesNI_Aes128_Key*, + AesNI_ErrorDetails*); + +AesNI_StatusCode aesni_aes192_format_key( + AesNI_Aes192_KeyString*, + const AesNI_Aes192_Key*, + AesNI_ErrorDetails*); + +AesNI_StatusCode aesni_aes256_format_key( + AesNI_Aes256_KeyString*, + const AesNI_Aes256_Key*, + AesNI_ErrorDetails*); + +AesNI_StatusCode aesni_aes128_print_key( + const AesNI_Aes128_Key*, + AesNI_ErrorDetails*); + +AesNI_StatusCode aesni_aes192_print_key( + const AesNI_Aes192_Key*, + AesNI_ErrorDetails*); + +AesNI_StatusCode aesni_aes256_print_key( + const AesNI_Aes256_Key*, + AesNI_ErrorDetails*); + +AesNI_StatusCode aesni_aes128_parse_key( + AesNI_Aes128_Key* dest, + const char* src, + AesNI_ErrorDetails* err_details); + +AesNI_StatusCode aesni_aes192_parse_key( + AesNI_Aes192_Key* dest, + const char* src, + AesNI_ErrorDetails* err_details); + +AesNI_StatusCode aesni_aes256_parse_key( + AesNI_Aes256_Key* dest, + const char* src, + AesNI_ErrorDetails* err_details); + typedef struct { AesNI_Block128 keys[11]; @@ -36,17 +152,17 @@ typedef struct AesNI_Aes256_RoundKeys; void __fastcall aesni_aes128_expand_key_( - AesNI_Block128 key, + AesNI_Aes_Block key, AesNI_Aes128_RoundKeys* encryption_keys); void __fastcall aesni_aes192_expand_key_( - AesNI_Block128 key_lo, - AesNI_Block128 key_hi, + AesNI_Aes_Block key_lo, + AesNI_Aes_Block key_hi, AesNI_Aes192_RoundKeys* encryption_keys); void __fastcall aesni_aes256_expand_key_( - AesNI_Block128 key_lo, - AesNI_Block128 key_hi, + AesNI_Aes_Block key_lo, + AesNI_Aes_Block key_hi, AesNI_Aes256_RoundKeys* encryption_keys); void __fastcall aesni_aes128_derive_decryption_keys_( @@ -61,28 +177,28 @@ void __fastcall aesni_aes256_derive_decryption_keys_( const AesNI_Aes256_RoundKeys* encryption_keys, AesNI_Aes256_RoundKeys* decryption_keys); -AesNI_Block128 __fastcall aesni_aes128_encrypt_block_( - AesNI_Block128 plaintext, +AesNI_Aes_Block __fastcall aesni_aes128_encrypt_block_( + AesNI_Aes_Block plaintext, const AesNI_Aes128_RoundKeys*); -AesNI_Block128 __fastcall aesni_aes192_encrypt_block_( - AesNI_Block128 plaintext, +AesNI_Aes_Block __fastcall aesni_aes192_encrypt_block_( + AesNI_Aes_Block plaintext, const AesNI_Aes192_RoundKeys*); -AesNI_Block128 __fastcall aesni_aes256_encrypt_block_( - AesNI_Block128 plaintext, +AesNI_Aes_Block __fastcall aesni_aes256_encrypt_block_( + AesNI_Aes_Block plaintext, const AesNI_Aes256_RoundKeys*); -AesNI_Block128 __fastcall aesni_aes128_decrypt_block_( - AesNI_Block128 ciphertext, +AesNI_Aes_Block __fastcall aesni_aes128_decrypt_block_( + AesNI_Aes_Block ciphertext, const AesNI_Aes128_RoundKeys*); -AesNI_Block128 __fastcall aesni_aes192_decrypt_block_( - AesNI_Block128 ciphertext, +AesNI_Aes_Block __fastcall aesni_aes192_decrypt_block_( + AesNI_Aes_Block ciphertext, const AesNI_Aes192_RoundKeys*); -AesNI_Block128 __fastcall aesni_aes256_decrypt_block_( - AesNI_Block128 ciphertext, +AesNI_Aes_Block __fastcall aesni_aes256_decrypt_block_( + AesNI_Aes_Block ciphertext, const AesNI_Aes256_RoundKeys*); /** @@ -92,12 +208,12 @@ AesNI_Block128 __fastcall aesni_aes256_decrypt_block_( * \param[out] encryption_keys The AES-128 encryption round keys. Must not be `NULL`. */ static __inline void __fastcall aesni_aes128_expand_key( - AesNI_Block128 key, + const AesNI_Aes128_Key* key, AesNI_Aes128_RoundKeys* encryption_keys) { assert(encryption_keys); - aesni_aes128_expand_key_(key, encryption_keys); + aesni_aes128_expand_key_(key->key, encryption_keys); } /** @@ -124,8 +240,8 @@ static __inline void __fastcall aesni_aes128_derive_decryption_keys( * * \return The encrypted 128-bit ciphertext. */ -static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_ecb( - AesNI_Block128 plaintext, +static __inline AesNI_Aes_Block __fastcall aesni_aes128_encrypt_block_ecb( + AesNI_Aes_Block plaintext, const AesNI_Aes128_RoundKeys* encryption_keys) { assert(encryption_keys); @@ -141,8 +257,8 @@ static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_ecb( * * \return The decrypted 128-bit plaintext. */ -static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_ecb( - AesNI_Block128 ciphertext, +static __inline AesNI_Aes_Block __fastcall aesni_aes128_decrypt_block_ecb( + AesNI_Aes_Block ciphertext, const AesNI_Aes128_RoundKeys* decryption_keys) { assert(decryption_keys); @@ -160,16 +276,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_ecb( * * \return The encrypted 128-bit ciphertext. */ -static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_cbc( - AesNI_Block128 plaintext, +static __inline AesNI_Aes_Block __fastcall aesni_aes128_encrypt_block_cbc( + AesNI_Aes_Block plaintext, const AesNI_Aes128_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(encryption_keys); assert(next_init_vector); - AesNI_Block128 ciphertext = aesni_aes128_encrypt_block_(aesni_xor_block128(plaintext, init_vector), encryption_keys); + AesNI_Aes_Block ciphertext = aesni_aes128_encrypt_block_(aesni_xor_block128(plaintext, init_vector), encryption_keys); *next_init_vector = ciphertext; return ciphertext; } @@ -184,16 +300,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_cbc( * * \return The decrypted 128-bit plaintext. */ -static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_cbc( - AesNI_Block128 ciphertext, +static __inline AesNI_Aes_Block __fastcall aesni_aes128_decrypt_block_cbc( + AesNI_Aes_Block ciphertext, const AesNI_Aes128_RoundKeys* decryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(decryption_keys); assert(next_init_vector); - AesNI_Block128 plaintext = aesni_xor_block128(aesni_aes128_decrypt_block_(ciphertext, decryption_keys), init_vector); + AesNI_Aes_Block plaintext = aesni_xor_block128(aesni_aes128_decrypt_block_(ciphertext, decryption_keys), init_vector); *next_init_vector = ciphertext; return plaintext; } @@ -208,16 +324,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_cbc( * * \return The encrypted 128-bit ciphertext. */ -static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_cfb( - AesNI_Block128 plaintext, +static __inline AesNI_Aes_Block __fastcall aesni_aes128_encrypt_block_cfb( + AesNI_Aes_Block plaintext, const AesNI_Aes128_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(encryption_keys); assert(next_init_vector); - AesNI_Block128 ciphertext = aesni_xor_block128(aesni_aes128_encrypt_block_(init_vector, encryption_keys), plaintext); + AesNI_Aes_Block ciphertext = aesni_xor_block128(aesni_aes128_encrypt_block_(init_vector, encryption_keys), plaintext); *next_init_vector = ciphertext; return ciphertext; } @@ -232,16 +348,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_cfb( * * \return The decrypted 128-bit plaintext. */ -static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_cfb( - AesNI_Block128 ciphertext, +static __inline AesNI_Aes_Block __fastcall aesni_aes128_decrypt_block_cfb( + AesNI_Aes_Block ciphertext, const AesNI_Aes128_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(encryption_keys); assert(next_init_vector); - AesNI_Block128 plaintext = aesni_xor_block128(aesni_aes128_encrypt_block_(init_vector, encryption_keys), ciphertext); + AesNI_Aes_Block plaintext = aesni_xor_block128(aesni_aes128_encrypt_block_(init_vector, encryption_keys), ciphertext); *next_init_vector = ciphertext; return plaintext; } @@ -256,16 +372,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_cfb( * * \return The encrypted 128-bit ciphertext. */ -static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_ofb( - AesNI_Block128 plaintext, +static __inline AesNI_Aes_Block __fastcall aesni_aes128_encrypt_block_ofb( + AesNI_Aes_Block plaintext, const AesNI_Aes128_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(encryption_keys); assert(next_init_vector); - AesNI_Block128 tmp = aesni_aes128_encrypt_block_(init_vector, encryption_keys); + AesNI_Aes_Block tmp = aesni_aes128_encrypt_block_(init_vector, encryption_keys); *next_init_vector = tmp; return aesni_xor_block128(tmp, plaintext); } @@ -280,16 +396,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_ofb( * * \return The decrypted 128-bit plaintext. */ -static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_ofb( - AesNI_Block128 ciphertext, +static __inline AesNI_Aes_Block __fastcall aesni_aes128_decrypt_block_ofb( + AesNI_Aes_Block ciphertext, const AesNI_Aes128_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(encryption_keys); assert(next_init_vector); - AesNI_Block128 tmp = aesni_aes128_encrypt_block_(init_vector, encryption_keys); + AesNI_Aes_Block tmp = aesni_aes128_encrypt_block_(init_vector, encryption_keys); *next_init_vector = tmp; return aesni_xor_block128(tmp, ciphertext); } @@ -304,17 +420,17 @@ static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_ofb( * * \return The encrypted 128-bit ciphertext. */ -static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_ctr( - AesNI_Block128 plaintext, +static __inline AesNI_Aes_Block __fastcall aesni_aes128_encrypt_block_ctr( + AesNI_Aes_Block plaintext, const AesNI_Aes128_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, + AesNI_Aes_Block init_vector, int counter) { assert(encryption_keys); - init_vector = aesni_le2be128(init_vector); + init_vector = aesni_reverse_bytes_block128(init_vector); init_vector = _mm_add_epi32(init_vector, aesni_make_block128(0, 0, 0, counter)); - init_vector = aesni_be2le128(init_vector); + init_vector = aesni_reverse_bytes_block128(init_vector); return aesni_xor_block128(plaintext, aesni_aes128_encrypt_block_(init_vector, encryption_keys)); } @@ -329,17 +445,17 @@ static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_ctr( * * \return The decrypted 128-bit plaintext. */ -static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_ctr( - AesNI_Block128 ciphertext, +static __inline AesNI_Aes_Block __fastcall aesni_aes128_decrypt_block_ctr( + AesNI_Aes_Block ciphertext, const AesNI_Aes128_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, + AesNI_Aes_Block init_vector, int counter) { assert(encryption_keys); - init_vector = aesni_le2be128(init_vector); + init_vector = aesni_reverse_bytes_block128(init_vector); init_vector = _mm_add_epi32(init_vector, aesni_make_block128(0, 0, 0, counter)); - init_vector = aesni_be2le128(init_vector); + init_vector = aesni_reverse_bytes_block128(init_vector); return aesni_xor_block128(ciphertext, aesni_aes128_encrypt_block_(init_vector, encryption_keys)); } @@ -351,7 +467,7 @@ static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_ctr( * \param[out] encryption_keys The AES-192 encryption round keys. Must not be `NULL`. */ static __inline void __fastcall aesni_aes192_expand_key( - AesNI_Block192* key, + const AesNI_Aes192_Key* key, AesNI_Aes192_RoundKeys* encryption_keys) { assert(key); @@ -384,8 +500,8 @@ static __inline void __fastcall aesni_aes192_derive_decryption_keys( * * \return The encrypted 128-bit ciphertext. */ -static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_ecb( - AesNI_Block128 plaintext, +static __inline AesNI_Aes_Block __fastcall aesni_aes192_encrypt_block_ecb( + AesNI_Aes_Block plaintext, const AesNI_Aes192_RoundKeys* encryption_keys) { assert(encryption_keys); @@ -401,8 +517,8 @@ static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_ecb( * * \return The decrypted 128-bit plaintext. */ -static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_ecb( - AesNI_Block128 ciphertext, +static __inline AesNI_Aes_Block __fastcall aesni_aes192_decrypt_block_ecb( + AesNI_Aes_Block ciphertext, const AesNI_Aes192_RoundKeys* decryption_keys) { assert(decryption_keys); @@ -420,16 +536,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_ecb( * * \return The encrypted 128-bit ciphertext. */ -static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_cbc( - AesNI_Block128 plaintext, +static __inline AesNI_Aes_Block __fastcall aesni_aes192_encrypt_block_cbc( + AesNI_Aes_Block plaintext, const AesNI_Aes192_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(encryption_keys); assert(next_init_vector); - AesNI_Block128 ciphertext = aesni_aes192_encrypt_block_(aesni_xor_block128(plaintext, init_vector), encryption_keys); + AesNI_Aes_Block ciphertext = aesni_aes192_encrypt_block_(aesni_xor_block128(plaintext, init_vector), encryption_keys); *next_init_vector = ciphertext; return ciphertext; } @@ -444,16 +560,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_cbc( * * \return The decrypted 128-bit plaintext. */ -static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_cbc( - AesNI_Block128 ciphertext, +static __inline AesNI_Aes_Block __fastcall aesni_aes192_decrypt_block_cbc( + AesNI_Aes_Block ciphertext, const AesNI_Aes192_RoundKeys* decryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(decryption_keys); assert(next_init_vector); - AesNI_Block128 plaintext = aesni_xor_block128(aesni_aes192_decrypt_block_(ciphertext, decryption_keys), init_vector); + AesNI_Aes_Block plaintext = aesni_xor_block128(aesni_aes192_decrypt_block_(ciphertext, decryption_keys), init_vector); *next_init_vector = ciphertext; return plaintext; } @@ -468,16 +584,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_cbc( * * \return The encrypted 128-bit ciphertext. */ -static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_cfb( - AesNI_Block128 plaintext, +static __inline AesNI_Aes_Block __fastcall aesni_aes192_encrypt_block_cfb( + AesNI_Aes_Block plaintext, const AesNI_Aes192_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(encryption_keys); assert(next_init_vector); - AesNI_Block128 ciphertext = aesni_xor_block128(aesni_aes192_encrypt_block_(init_vector, encryption_keys), plaintext); + AesNI_Aes_Block ciphertext = aesni_xor_block128(aesni_aes192_encrypt_block_(init_vector, encryption_keys), plaintext); *next_init_vector = ciphertext; return ciphertext; } @@ -492,16 +608,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_cfb( * * \return The decrypted 128-bit plaintext. */ -static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_cfb( - AesNI_Block128 ciphertext, +static __inline AesNI_Aes_Block __fastcall aesni_aes192_decrypt_block_cfb( + AesNI_Aes_Block ciphertext, const AesNI_Aes192_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(encryption_keys); assert(next_init_vector); - AesNI_Block128 plaintext = aesni_xor_block128(aesni_aes192_encrypt_block_(init_vector, encryption_keys), ciphertext); + AesNI_Aes_Block plaintext = aesni_xor_block128(aesni_aes192_encrypt_block_(init_vector, encryption_keys), ciphertext); *next_init_vector = ciphertext; return plaintext; } @@ -516,16 +632,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_cfb( * * \return The encrypted 128-bit ciphertext. */ -static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_ofb( - AesNI_Block128 plaintext, +static __inline AesNI_Aes_Block __fastcall aesni_aes192_encrypt_block_ofb( + AesNI_Aes_Block plaintext, const AesNI_Aes192_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(encryption_keys); assert(next_init_vector); - AesNI_Block128 tmp = aesni_aes192_encrypt_block_(init_vector, encryption_keys); + AesNI_Aes_Block tmp = aesni_aes192_encrypt_block_(init_vector, encryption_keys); *next_init_vector = tmp; return aesni_xor_block128(tmp, plaintext); } @@ -540,16 +656,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_ofb( * * \return The decrypted 128-bit plaintext. */ -static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_ofb( - AesNI_Block128 ciphertext, +static __inline AesNI_Aes_Block __fastcall aesni_aes192_decrypt_block_ofb( + AesNI_Aes_Block ciphertext, const AesNI_Aes192_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(encryption_keys); assert(next_init_vector); - AesNI_Block128 tmp = aesni_aes192_encrypt_block_(init_vector, encryption_keys); + AesNI_Aes_Block tmp = aesni_aes192_encrypt_block_(init_vector, encryption_keys); *next_init_vector = tmp; return aesni_xor_block128(tmp, ciphertext); } @@ -564,17 +680,17 @@ static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_ofb( * * \return The encrypted 128-bit ciphertext. */ -static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_ctr( - AesNI_Block128 plaintext, +static __inline AesNI_Aes_Block __fastcall aesni_aes192_encrypt_block_ctr( + AesNI_Aes_Block plaintext, const AesNI_Aes192_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, + AesNI_Aes_Block init_vector, int counter) { assert(encryption_keys); - init_vector = aesni_le2be128(init_vector); + init_vector = aesni_reverse_bytes_block128(init_vector); init_vector = _mm_add_epi32(init_vector, aesni_make_block128(0, 0, 0, counter)); - init_vector = aesni_be2le128(init_vector); + init_vector = aesni_reverse_bytes_block128(init_vector); return aesni_xor_block128(plaintext, aesni_aes192_encrypt_block_(init_vector, encryption_keys)); } @@ -589,17 +705,17 @@ static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_ctr( * * \return The decrypted 128-bit plaintext. */ -static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_ctr( - AesNI_Block128 ciphertext, +static __inline AesNI_Aes_Block __fastcall aesni_aes192_decrypt_block_ctr( + AesNI_Aes_Block ciphertext, const AesNI_Aes192_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, + AesNI_Aes_Block init_vector, int counter) { assert(encryption_keys); - init_vector = aesni_le2be128(init_vector); + init_vector = aesni_reverse_bytes_block128(init_vector); init_vector = _mm_add_epi32(init_vector, aesni_make_block128(0, 0, 0, counter)); - init_vector = aesni_be2le128(init_vector); + init_vector = aesni_reverse_bytes_block128(init_vector); return aesni_xor_block128(ciphertext, aesni_aes192_encrypt_block_(init_vector, encryption_keys)); } @@ -611,7 +727,7 @@ static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_ctr( * \param[out] encryption_keys The AES-256 encryption round keys. Must not be `NULL`. */ static __inline void __fastcall aesni_aes256_expand_key( - const AesNI_Block256* key, + const AesNI_Aes256_Key* key, AesNI_Aes256_RoundKeys* encryption_keys) { assert(key); @@ -644,8 +760,8 @@ static __inline void __fastcall aesni_aes256_derive_decryption_keys( * * \return The encrypted 128-bit ciphertext. */ -static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_ecb( - AesNI_Block128 plaintext, +static __inline AesNI_Aes_Block __fastcall aesni_aes256_encrypt_block_ecb( + AesNI_Aes_Block plaintext, const AesNI_Aes256_RoundKeys* encryption_keys) { assert(encryption_keys); @@ -661,8 +777,8 @@ static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_ecb( * * \return The decrypted 128-bit plaintext. */ -static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_ecb( - AesNI_Block128 ciphertext, +static __inline AesNI_Aes_Block __fastcall aesni_aes256_decrypt_block_ecb( + AesNI_Aes_Block ciphertext, const AesNI_Aes256_RoundKeys* decryption_keys) { assert(decryption_keys); @@ -680,16 +796,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_ecb( * * \return The encrypted 128-bit ciphertext. */ -static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_cbc( - AesNI_Block128 plaintext, +static __inline AesNI_Aes_Block __fastcall aesni_aes256_encrypt_block_cbc( + AesNI_Aes_Block plaintext, const AesNI_Aes256_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(encryption_keys); assert(next_init_vector); - AesNI_Block128 ciphertext = aesni_aes256_encrypt_block_(aesni_xor_block128(plaintext, init_vector), encryption_keys); + AesNI_Aes_Block ciphertext = aesni_aes256_encrypt_block_(aesni_xor_block128(plaintext, init_vector), encryption_keys); *next_init_vector = ciphertext; return ciphertext; } @@ -704,16 +820,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_cbc( * * \return The decrypted 128-bit plaintext. */ -static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_cbc( - AesNI_Block128 ciphertext, +static __inline AesNI_Aes_Block __fastcall aesni_aes256_decrypt_block_cbc( + AesNI_Aes_Block ciphertext, const AesNI_Aes256_RoundKeys* decryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(decryption_keys); assert(next_init_vector); - AesNI_Block128 plaintext = aesni_xor_block128(aesni_aes256_decrypt_block_(ciphertext, decryption_keys), init_vector); + AesNI_Aes_Block plaintext = aesni_xor_block128(aesni_aes256_decrypt_block_(ciphertext, decryption_keys), init_vector); *next_init_vector = ciphertext; return plaintext; } @@ -728,16 +844,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_cbc( * * \return The encrypted 128-bit ciphertext. */ -static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_cfb( - AesNI_Block128 plaintext, +static __inline AesNI_Aes_Block __fastcall aesni_aes256_encrypt_block_cfb( + AesNI_Aes_Block plaintext, const AesNI_Aes256_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(encryption_keys); assert(next_init_vector); - AesNI_Block128 ciphertext = aesni_xor_block128(aesni_aes256_encrypt_block_(init_vector, encryption_keys), plaintext); + AesNI_Aes_Block ciphertext = aesni_xor_block128(aesni_aes256_encrypt_block_(init_vector, encryption_keys), plaintext); *next_init_vector = ciphertext; return ciphertext; } @@ -752,16 +868,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_cfb( * * \return The decrypted 128-bit plaintext. */ -static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_cfb( - AesNI_Block128 ciphertext, +static __inline AesNI_Aes_Block __fastcall aesni_aes256_decrypt_block_cfb( + AesNI_Aes_Block ciphertext, const AesNI_Aes256_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(encryption_keys); assert(next_init_vector); - AesNI_Block128 plaintext = aesni_xor_block128(aesni_aes256_encrypt_block_(init_vector, encryption_keys), ciphertext); + AesNI_Aes_Block plaintext = aesni_xor_block128(aesni_aes256_encrypt_block_(init_vector, encryption_keys), ciphertext); *next_init_vector = ciphertext; return plaintext; } @@ -776,16 +892,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_cfb( * * \return The encrypted 128-bit ciphertext. */ -static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_ofb( - AesNI_Block128 plaintext, +static __inline AesNI_Aes_Block __fastcall aesni_aes256_encrypt_block_ofb( + AesNI_Aes_Block plaintext, const AesNI_Aes256_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(encryption_keys); assert(next_init_vector); - AesNI_Block128 tmp = aesni_aes256_encrypt_block_(init_vector, encryption_keys); + AesNI_Aes_Block tmp = aesni_aes256_encrypt_block_(init_vector, encryption_keys); *next_init_vector = tmp; return aesni_xor_block128(tmp, plaintext); } @@ -800,16 +916,16 @@ static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_ofb( * * \return The decrypted 128-bit plaintext. */ -static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_ofb( - AesNI_Block128 ciphertext, +static __inline AesNI_Aes_Block __fastcall aesni_aes256_decrypt_block_ofb( + AesNI_Aes_Block ciphertext, const AesNI_Aes256_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) + AesNI_Aes_Block init_vector, + AesNI_Aes_Block* next_init_vector) { assert(encryption_keys); assert(next_init_vector); - AesNI_Block128 tmp = aesni_aes256_encrypt_block_(init_vector, encryption_keys); + AesNI_Aes_Block tmp = aesni_aes256_encrypt_block_(init_vector, encryption_keys); *next_init_vector = tmp; return aesni_xor_block128(tmp, ciphertext); } @@ -824,17 +940,17 @@ static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_ofb( * * \return The encrypted 128-bit ciphertext. */ -static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_ctr( - AesNI_Block128 plaintext, +static __inline AesNI_Aes_Block __fastcall aesni_aes256_encrypt_block_ctr( + AesNI_Aes_Block plaintext, const AesNI_Aes256_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, + AesNI_Aes_Block init_vector, int counter) { assert(encryption_keys); - init_vector = aesni_le2be128(init_vector); + init_vector = aesni_reverse_bytes_block128(init_vector); init_vector = _mm_add_epi32(init_vector, aesni_make_block128(0, 0, 0, counter)); - init_vector = aesni_be2le128(init_vector); + init_vector = aesni_reverse_bytes_block128(init_vector); return aesni_xor_block128(plaintext, aesni_aes256_encrypt_block_(init_vector, encryption_keys)); } @@ -849,17 +965,17 @@ static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_ctr( * * \return The decrypted 128-bit plaintext. */ -static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_ctr( - AesNI_Block128 ciphertext, +static __inline AesNI_Aes_Block __fastcall aesni_aes256_decrypt_block_ctr( + AesNI_Aes_Block ciphertext, const AesNI_Aes256_RoundKeys* encryption_keys, - AesNI_Block128 init_vector, + AesNI_Aes_Block init_vector, int counter) { assert(encryption_keys); - init_vector = aesni_le2be128(init_vector); + init_vector = aesni_reverse_bytes_block128(init_vector); init_vector = _mm_add_epi32(init_vector, aesni_make_block128(0, 0, 0, counter)); - init_vector = aesni_be2le128(init_vector); + init_vector = aesni_reverse_bytes_block128(init_vector); return aesni_xor_block128(ciphertext, aesni_aes256_encrypt_block_(init_vector, encryption_keys)); } diff --git a/include/aesni/box_aes.h b/include/aesni/box_aes.h index 391f13e..98de721 100644 --- a/include/aesni/box_aes.h +++ b/include/aesni/box_aes.h @@ -25,7 +25,7 @@ static __inline AesNI_StatusCode aesni_box_derive_params_aes128( AesNI_ErrorDetails* err_details) { aesni_aes128_expand_key_( - algorithm_params->aes128_key, + algorithm_params->aes128_key.key, &encrypt_params->aes128_encryption_keys); aesni_aes128_derive_decryption_keys_( &encrypt_params->aes128_encryption_keys, diff --git a/include/aesni/box_data.h b/include/aesni/box_data.h index 160cf34..732f714 100644 --- a/include/aesni/box_data.h +++ b/include/aesni/box_data.h @@ -17,9 +17,9 @@ extern "C" typedef union { - AesNI_Block128 aes128_key; - AesNI_Block192 aes192_key; - AesNI_Block256 aes256_key; + AesNI_Aes128_Key aes128_key; + AesNI_Aes192_Key aes192_key; + AesNI_Aes256_Key aes256_key; } AesNI_BoxAlgorithmParams; @@ -59,7 +59,7 @@ AesNI_BoxDecryptionParams; typedef union { - AesNI_Block128 aes_block; + AesNI_Aes_Block aes_block; } AesNI_BoxBlock; diff --git a/include/aesni/data.h b/include/aesni/data.h index a6dc71f..381a32a 100644 --- a/include/aesni/data.h +++ b/include/aesni/data.h @@ -122,158 +122,11 @@ static __inline AesNI_Block128 __fastcall aesni_make_block128( return _mm_set_epi32(hi3, hi2, lo1, lo0); } -/** - * \brief Represents a 192-bit block. - */ -typedef struct -{ - AesNI_Block128 hi; ///< The most significant 64 bits. - AesNI_Block128 lo; ///< The least significant 128 bits. -} -AesNI_Block192; - -/** - * \brief Builds a 192-bit block from six 4-byte values. - * - * Builds a 192-bit block like this: - * - * * dest[191:160] = hi5 - * * dest[159:128] = hi4 - * * dest[127:96] = lo3 - * * dest[95:64] = lo2 - * * dest[63:32] = lo1 - * * dest[31:0] = lo0 - * - * \param[in] hi5 The most significant 4-byte value (bits 160--191). - * \param[in] hi4 The more significant 4-byte value (bits 128--159). - * \param[in] lo3 The 4-byte value to be stored in bits 96--127. - * \param[in] lo2 The 4-byte value to be stored in bits 64--95. - * \param[in] lo1 The less significant 4-byte value (bits 32--63). - * \param[in] lo0 The least significant 4-byte value (bits 0--31). - * \return The built 192-bit block. - */ -static __inline AesNI_Block192 __fastcall aesni_make_block192( - int hi5, int hi4, int lo3, int lo2, int lo1, int lo0) -{ - AesNI_Block192 result; - result.hi = aesni_make_block128(0, 0, hi5, hi4); - result.lo = aesni_make_block128(lo3, lo2, lo1, lo0); - return result; -} - -/** - * \brief Represents a 256-bit block. - */ -typedef struct -{ - AesNI_Block128 hi; ///< The most significant 128 bits. - AesNI_Block128 lo; ///< The least significant 128 bits. -} -AesNI_Block256; - -/** - * \brief Builds a 256-bit block from eight 4-byte values. - * - * Builds a 256-bit block like this: - * - * * dest[255:224] = hi7 - * * dest[223:192] = hi6 - * * dest[191:160] = hi5 - * * dest[159:128] = hi4 - * * dest[127:96] = lo3 - * * dest[95:64] = lo2 - * * dest[63:32] = lo1 - * * dest[31:0] = lo0 - * - * \param[in] hi7 The 4-byte value to be stored in bits 224--255. - * \param[in] hi6 The 4-byte value to be stored in bits 192--223. - * \param[in] hi5 The 4-byte value to be stored in bits 160--191. - * \param[in] hi4 The 4-byte value to be stored in bits 128--159. - * \param[in] lo3 The 4-byte value to be stored in bits 96--127. - * \param[in] lo2 The 4-byte value to be stored in bits 64--95. - * \param[in] lo1 The 4-byte value to be stored in bits 32--63. - * \param[in] lo0 The 4-byte value to be stored in bits 0--31. - * \return The built 256-bit block. - */ -static __inline AesNI_Block256 __fastcall aesni_make_block256( - int hi7, int hi6, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0) -{ - AesNI_Block256 result; - result.hi = aesni_make_block128(hi7, hi6, hi5, hi4); - result.lo = aesni_make_block128(lo3, lo2, lo1, lo0); - return result; -} - -static __inline AesNI_Block128 __fastcall aesni_reverse_byte_order128(AesNI_Block128 block) +static __inline AesNI_Block128 __fastcall aesni_reverse_bytes_block128(AesNI_Block128 block) { return _mm_shuffle_epi8(block, aesni_make_block128(0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f)); } -static __inline AesNI_Block128 __fastcall aesni_le2be128(AesNI_Block128 block) -{ - return aesni_reverse_byte_order128(block); -} - -static __inline AesNI_Block128 __fastcall aesni_be2le128(AesNI_Block128 block) -{ - return aesni_reverse_byte_order128(block); -} - -typedef struct { char str[33]; } AesNI_BlockString128; -typedef struct { char str[49]; } AesNI_BlockString192; -typedef struct { char str[65]; } AesNI_BlockString256; - -AesNI_StatusCode aesni_format_block128(AesNI_BlockString128*, const AesNI_Block128*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_format_block192(AesNI_BlockString192*, const AesNI_Block192*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_format_block256(AesNI_BlockString256*, const AesNI_Block256*, AesNI_ErrorDetails*); - -typedef struct { char str[49]; } AesNI_BlockMatrixString128; -typedef struct { char str[73]; } AesNI_BlockMatrixString192; -typedef struct { char str[97]; } AesNI_BlockMatrixString256; - -AesNI_StatusCode aesni_format_block128_as_matrix(AesNI_BlockMatrixString128*, const AesNI_Block128*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_format_block192_as_matrix(AesNI_BlockMatrixString192*, const AesNI_Block192*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_format_block256_as_matrix(AesNI_BlockMatrixString256*, const AesNI_Block256*, AesNI_ErrorDetails*); - -AesNI_StatusCode aesni_print_block128(const AesNI_Block128*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_print_block192(const AesNI_Block192*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_print_block256(const AesNI_Block256*, AesNI_ErrorDetails*); - -AesNI_StatusCode aesni_print_block128_as_matrix(const AesNI_Block128*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_print_block192_as_matrix(const AesNI_Block192*, AesNI_ErrorDetails*); -AesNI_StatusCode aesni_print_block256_as_matrix(const AesNI_Block256*, AesNI_ErrorDetails*); - -AesNI_StatusCode aesni_parse_block128( - AesNI_Block128* dest, - const char* src, - AesNI_ErrorDetails* err_details); - -AesNI_StatusCode aesni_parse_block192( - AesNI_Block192* dest, - const char* src, - AesNI_ErrorDetails* err_details); - -/** - * \brief Parses a 256-bit block, from the least significant to the most significant byte. - * - * The block is parsed from a hexadecimal number represented using the big endian notation. - * - * The source string may optionally start with "0x" or "0X". - * Then 64 characters in the range [0-9a-fA-F] must follow. - * - * \param[out] dest The pointer to the parsed block. Must not be `NULL`. - * \param[in] src The pointer to the source C string. Must not be `NULL`. - * \param[out] err_details The error details structure. - * \retval AESNI_SUCCESS If parsed successfully. - * \retval AESNI_NULL_ARGUMENT_ERROR If either `dest` or `src` is `NULL`. - * \retval AESNI_PARSE_ERROR If `src` couldn't be parsed as a valid 256-bit block. - * \sa aesni_error_handling. - */ -AesNI_StatusCode aesni_parse_block256( - AesNI_Block256* dest, - const char* src, - AesNI_ErrorDetails* err_details); - #ifdef __cplusplus } #endif @@ -8,13 +8,14 @@ #include <aesni/all.h> -#include <intrin.h> - #include <assert.h> #include <stdio.h> #include <string.h> -AesNI_StatusCode aesni_format_block128(AesNI_BlockString128* str, const AesNI_Block128* block, AesNI_ErrorDetails* err_details) +AesNI_StatusCode aesni_aes_format_block( + AesNI_Aes_BlockString* str, + const AesNI_Aes_Block* block, + AesNI_ErrorDetails* err_details) { assert(str); assert(block); @@ -33,10 +34,13 @@ AesNI_StatusCode aesni_format_block128(AesNI_BlockString128* str, const AesNI_Bl sprintf(cursor, "%02x", bytes[i]); *cursor = '\0'; - return aesni_initialize_error_details(err_details); + return AESNI_SUCCESS; } -AesNI_StatusCode aesni_format_block192(AesNI_BlockString192* str, const AesNI_Block192* block, AesNI_ErrorDetails* err_details) +AesNI_StatusCode aesni_aes_format_block_as_matrix( + AesNI_Aes_BlockMatrixString* str, + const AesNI_Aes_Block* block, + AesNI_ErrorDetails* err_details) { assert(str); assert(block); @@ -48,272 +52,220 @@ AesNI_StatusCode aesni_format_block192(AesNI_BlockString192* str, const AesNI_Bl char* cursor = str->str; - { - __declspec(align(16)) unsigned char bytes[16]; - aesni_store_block128_aligned(bytes, block->lo); - - for (int i = 0; i < 16; ++i, cursor += 2) - sprintf(cursor, "%02x", bytes[i]); - } + __declspec(align(16)) unsigned char bytes[4][4]; + aesni_store_block128_aligned(bytes, *block); + for (int i = 0; i < 4; ++i, cursor += 3) { - __declspec(align(16)) unsigned char bytes[16]; - aesni_store_block128_aligned(bytes, block->hi); - - for (int i = 0; i < 8; ++i, cursor += 2) - sprintf(cursor, "%02x", bytes[i]); + for (int j = 0; j < 3; ++j, cursor += 3) + sprintf(cursor, "%02x ", bytes[j][i]); + sprintf(cursor, "%02x\n", bytes[3][i]); } *cursor = '\0'; - return aesni_initialize_error_details(err_details); + return AESNI_SUCCESS; } -AesNI_StatusCode aesni_format_block256(AesNI_BlockString256* str, const AesNI_Block256* block, AesNI_ErrorDetails* err_details) +AesNI_StatusCode aesni_aes_print_block( + const AesNI_Aes_Block* block, + AesNI_ErrorDetails* err_details) { - assert(str); assert(block); - if (str == NULL) - return aesni_make_null_argument_error(err_details, "str"); if (block == NULL) return aesni_make_null_argument_error(err_details, "block"); - char* cursor = str->str; + AesNI_StatusCode ec = AESNI_SUCCESS; + AesNI_Aes_BlockString str; - { - __declspec(align(16)) unsigned char bytes[16]; - aesni_store_block128_aligned(bytes, block->lo); - - for (int i = 0; i < 16; ++i, cursor += 2) - sprintf(cursor, "%02x", bytes[i]); - } - - { - __declspec(align(16)) unsigned char bytes[16]; - aesni_store_block128_aligned(bytes, block->hi); - - for (int i = 0; i < 16; ++i, cursor += 2) - sprintf(cursor, "%02x", bytes[i]); - } + if (aesni_is_error(ec = aesni_aes_format_block(&str, block, err_details))) + return ec; - *cursor = '\0'; - return aesni_initialize_error_details(err_details); + printf("%s\n", str.str); + return ec; } -AesNI_StatusCode aesni_format_block128_as_matrix(AesNI_BlockMatrixString128* str, const AesNI_Block128* block, AesNI_ErrorDetails* err_details) +AesNI_StatusCode aesni_aes_print_block_as_matrix( + const AesNI_Aes_Block* block, + AesNI_ErrorDetails* err_details) { - assert(str); assert(block); - if (str == NULL) - return aesni_make_null_argument_error(err_details, "str"); if (block == NULL) return aesni_make_null_argument_error(err_details, "block"); - char* cursor = str->str; + AesNI_StatusCode ec = AESNI_SUCCESS; + AesNI_Aes_BlockMatrixString str; - __declspec(align(16)) unsigned char bytes[4][4]; - aesni_store_block128_aligned(bytes, *block); + if (aesni_is_error(ec = aesni_aes_format_block_as_matrix(&str, block, err_details))) + return ec; - for (int i = 0; i < 4; ++i, cursor += 3) + printf("%s", str.str); + return ec; +} + +AesNI_StatusCode aesni_aes_parse_block( + AesNI_Aes_Block* dest, + const char* src, + AesNI_ErrorDetails* err_details) +{ + assert(dest); + assert(src); + + if (dest == NULL) + return aesni_make_null_argument_error(err_details, "dest"); + if (src == NULL) + return aesni_make_null_argument_error(err_details, "src"); + + __declspec(align(16)) unsigned char bytes[16]; + + for (int i = 0; i < 16; ++i) { - for (int j = 0; j < 3; ++j, cursor += 3) - sprintf(cursor, "%02x ", bytes[j][i]); - sprintf(cursor, "%02x\n", bytes[3][i]); + int n; + unsigned int byte; + if (sscanf(src, "%2x%n", &byte, &n) != 1) + return aesni_make_parse_error(err_details, src); + bytes[i] = (unsigned char) byte; + src += n; } - *cursor = '\0'; - return aesni_initialize_error_details(err_details); + *dest = aesni_load_block128_aligned(bytes); + return AESNI_SUCCESS; +} + +AesNI_StatusCode aesni_aes128_format_key( + AesNI_Aes128_KeyString* str, + const AesNI_Aes128_Key* key, + AesNI_ErrorDetails* err_details) +{ + return aesni_aes_format_block(str, &key->key, err_details); } -AesNI_StatusCode aesni_format_block192_as_matrix(AesNI_BlockMatrixString192* str, const AesNI_Block192* block, AesNI_ErrorDetails* err_details) +AesNI_StatusCode aesni_aes192_format_key( + AesNI_Aes192_KeyString* str, + const AesNI_Aes192_Key* key, + AesNI_ErrorDetails* err_details) { assert(str); - assert(block); + assert(key); if (str == NULL) return aesni_make_null_argument_error(err_details, "str"); - if (block == NULL) - return aesni_make_null_argument_error(err_details, "block"); + if (key == NULL) + return aesni_make_null_argument_error(err_details, "key"); char* cursor = str->str; - __declspec(align(16)) unsigned char bytes[8][4]; - aesni_store_block128_aligned(bytes, block->lo); - aesni_store_block128_aligned(bytes + 4, block->hi); + { + __declspec(align(16)) unsigned char bytes[16]; + aesni_store_block128_aligned(bytes, key->lo); + + for (int i = 0; i < 16; ++i, cursor += 2) + sprintf(cursor, "%02x", bytes[i]); + } - for (int i = 0; i < 4; ++i, cursor += 3) { - for (int j = 0; j < 5; ++j, cursor += 3) - sprintf(cursor, "%02x ", bytes[j][i]); - sprintf(cursor, "%02x\n", bytes[5][i]); + __declspec(align(16)) unsigned char bytes[16]; + aesni_store_block128_aligned(bytes, key->hi); + + for (int i = 0; i < 8; ++i, cursor += 2) + sprintf(cursor, "%02x", bytes[i]); } *cursor = '\0'; - return aesni_initialize_error_details(err_details); + return AESNI_SUCCESS; } -AesNI_StatusCode aesni_format_block256_as_matrix(AesNI_BlockMatrixString256* str, const AesNI_Block256* block, AesNI_ErrorDetails* err_details) +AesNI_StatusCode aesni_aes256_format_key( + AesNI_Aes256_KeyString* str, + const AesNI_Aes256_Key* key, + AesNI_ErrorDetails* err_details) { assert(str); - assert(block); + assert(key); if (str == NULL) return aesni_make_null_argument_error(err_details, "str"); - if (block == NULL) - return aesni_make_null_argument_error(err_details, "block"); + if (key == NULL) + return aesni_make_null_argument_error(err_details, "key"); char* cursor = str->str; - __declspec(align(16)) unsigned char bytes[8][4]; - aesni_store_block128_aligned(bytes, block->lo); - aesni_store_block128_aligned(bytes + 4, block->hi); + { + __declspec(align(16)) unsigned char bytes[16]; + aesni_store_block128_aligned(bytes, key->lo); + + for (int i = 0; i < 16; ++i, cursor += 2) + sprintf(cursor, "%02x", bytes[i]); + } - for (int i = 0; i < 4; ++i, cursor += 3) { - for (int j = 0; j < 7; ++j, cursor += 3) - sprintf(cursor, "%02x ", bytes[j][i]); - sprintf(cursor, "%02x\n", bytes[7][i]); + __declspec(align(16)) unsigned char bytes[16]; + aesni_store_block128_aligned(bytes, key->hi); + + for (int i = 0; i < 16; ++i, cursor += 2) + sprintf(cursor, "%02x", bytes[i]); } *cursor = '\0'; - return aesni_initialize_error_details(err_details); + return AESNI_SUCCESS; } -AesNI_StatusCode aesni_print_block128(const AesNI_Block128* block, AesNI_ErrorDetails* err_details) +AesNI_StatusCode aesni_aes128_print_key( + const AesNI_Aes128_Key* key, + AesNI_ErrorDetails* err_details) { - assert(block); - - if (block == NULL) - return aesni_make_null_argument_error(err_details, "block"); - - AesNI_StatusCode ec = aesni_initialize_error_details(err_details); - AesNI_BlockString128 str; - - if (aesni_is_error(ec = aesni_format_block128(&str, block, err_details))) - return ec; - - printf("%s\n", str.str); - return ec; + return aesni_aes_print_block(&key->key, err_details); } -AesNI_StatusCode aesni_print_block192(const AesNI_Block192* block, AesNI_ErrorDetails* err_details) +AesNI_StatusCode aesni_aes192_print_key( + const AesNI_Aes192_Key* key, + AesNI_ErrorDetails* err_details) { - assert(block); + assert(key); - if (block == NULL) - return aesni_make_null_argument_error(err_details, "block"); + if (key == NULL) + return aesni_make_null_argument_error(err_details, "key"); - AesNI_StatusCode ec = aesni_initialize_error_details(err_details); - AesNI_BlockString192 str; + AesNI_StatusCode ec = AESNI_SUCCESS; + AesNI_Aes192_KeyString str; - if (aesni_is_error(ec = aesni_format_block192(&str, block, err_details))) + if (aesni_is_error(ec = aesni_aes192_format_key(&str, key, err_details))) return ec; printf("%s\n", str.str); return ec; } -AesNI_StatusCode aesni_print_block256(const AesNI_Block256* block, AesNI_ErrorDetails* err_details) +AesNI_StatusCode aesni_aes256_print_key( + const AesNI_Aes256_Key* key, + AesNI_ErrorDetails* err_details) { - assert(block); + assert(key); - if (block == NULL) - return aesni_make_null_argument_error(err_details, "block"); + if (key == NULL) + return aesni_make_null_argument_error(err_details, "key"); - AesNI_StatusCode ec = aesni_initialize_error_details(err_details); - AesNI_BlockString256 str; + AesNI_StatusCode ec = AESNI_SUCCESS; + AesNI_Aes256_KeyString str; - if (aesni_is_error(ec = aesni_format_block256(&str, block, err_details))) + if (aesni_is_error(ec = aesni_aes256_format_key(&str, key, err_details))) return ec; printf("%s\n", str.str); return ec; } -AesNI_StatusCode aesni_print_block128_as_matrix(const AesNI_Block128* block, AesNI_ErrorDetails* err_details) -{ - assert(block); - - if (block == NULL) - return aesni_make_null_argument_error(err_details, "block"); - - AesNI_StatusCode ec = aesni_initialize_error_details(err_details); - AesNI_BlockMatrixString128 str; - - if (aesni_is_error(ec = aesni_format_block128_as_matrix(&str, block, err_details))) - return ec; - - printf("%s", str.str); - return ec; -} - -AesNI_StatusCode aesni_print_block192_as_matrix(const AesNI_Block192* block, AesNI_ErrorDetails* err_details) -{ - assert(block); - - if (block == NULL) - return aesni_make_null_argument_error(err_details, "block"); - - AesNI_StatusCode ec = aesni_initialize_error_details(err_details); - AesNI_BlockMatrixString192 str; - - if (aesni_is_error(ec = aesni_format_block192_as_matrix(&str, block, err_details))) - return ec; - - printf("%s", str.str); - return ec; -} - -AesNI_StatusCode aesni_print_block256_as_matrix(const AesNI_Block256* block, AesNI_ErrorDetails* err_details) -{ - assert(block); - - if (block == NULL) - return aesni_make_null_argument_error(err_details, "block"); - - AesNI_StatusCode ec = aesni_initialize_error_details(err_details); - AesNI_BlockMatrixString256 str; - - if (aesni_is_error(ec = aesni_format_block256_as_matrix(&str, block, err_details))) - return ec; - - printf("%s", str.str); - return ec; -} - -AesNI_StatusCode aesni_parse_block128( - AesNI_Block128* dest, +AesNI_StatusCode aesni_aes128_parse_key( + AesNI_Aes128_Key* dest, const char* src, AesNI_ErrorDetails* err_details) { - assert(dest); - assert(src); - - if (dest == NULL) - return aesni_make_null_argument_error(err_details, "dest"); - if (src == NULL) - return aesni_make_null_argument_error(err_details, "src"); - - __declspec(align(16)) unsigned char bytes[16]; - - for (int i = 0; i < 16; ++i) - { - int n; - unsigned int byte; - if (sscanf(src, "%2x%n", &byte, &n) != 1) - return aesni_make_parse_error(err_details, src); - bytes[i] = (unsigned char) byte; - src += n; - } - - *dest = aesni_load_block128_aligned(bytes); - - return aesni_initialize_error_details(err_details); + return aesni_aes_parse_block(&dest->key, src, err_details); } -AesNI_StatusCode aesni_parse_block192( - AesNI_Block192* dest, +AesNI_StatusCode aesni_aes192_parse_key( + AesNI_Aes192_Key* dest, const char* src, AesNI_ErrorDetails* err_details) { @@ -358,11 +310,11 @@ AesNI_StatusCode aesni_parse_block192( dest->hi = aesni_load_block128_aligned(bytes); } - return aesni_initialize_error_details(err_details); + return AESNI_SUCCESS; } -AesNI_StatusCode aesni_parse_block256( - AesNI_Block256* dest, +AesNI_StatusCode aesni_aes256_parse_key( + AesNI_Aes256_Key* dest, const char* src, AesNI_ErrorDetails* err_details) { @@ -406,5 +358,5 @@ AesNI_StatusCode aesni_parse_block256( dest->hi = aesni_load_block128_aligned(bytes); } - return aesni_initialize_error_details(err_details); + return AESNI_SUCCESS; } diff --git a/src/c/aes128.c b/src/c/aes128.c index 8f2da44..b2e37ba 100644 --- a/src/c/aes128.c +++ b/src/c/aes128.c @@ -11,8 +11,8 @@ #include <emmintrin.h> #include <wmmintrin.h> -AesNI_Block128 __fastcall aesni_aes128_encrypt_block_( - AesNI_Block128 plaintext, +AesNI_Aes_Block __fastcall aesni_aes128_encrypt_block_( + AesNI_Aes_Block plaintext, const AesNI_Aes128_RoundKeys* encryption_keys) { plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]); @@ -28,8 +28,8 @@ AesNI_Block128 __fastcall aesni_aes128_encrypt_block_( return _mm_aesenclast_si128(plaintext, encryption_keys->keys[10]); } -AesNI_Block128 __fastcall aesni_aes128_decrypt_block_( - AesNI_Block128 ciphertext, +AesNI_Aes_Block __fastcall aesni_aes128_decrypt_block_( + AesNI_Aes_Block ciphertext, const AesNI_Aes128_RoundKeys* decryption_keys) { ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]); @@ -45,11 +45,11 @@ AesNI_Block128 __fastcall aesni_aes128_decrypt_block_( return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[10]); } -static AesNI_Block128 __fastcall aesni_aes128_expand_key_assist( - AesNI_Block128 prev, - AesNI_Block128 hwgen) +static AesNI_Aes_Block __fastcall aesni_aes128_expand_key_assist( + AesNI_Aes_Block prev, + AesNI_Aes_Block hwgen) { - AesNI_Block128 tmp = prev; + AesNI_Aes_Block tmp = prev; tmp = _mm_slli_si128(tmp, 4); prev = _mm_xor_si128(prev, tmp); @@ -65,7 +65,7 @@ static AesNI_Block128 __fastcall aesni_aes128_expand_key_assist( } void __fastcall aesni_aes128_expand_key_( - AesNI_Block128 key, + AesNI_Aes_Block key, AesNI_Aes128_RoundKeys* encryption_keys) { AesNI_Block128 prev = encryption_keys->keys[0] = key; diff --git a/src/c/aes192.c b/src/c/aes192.c index 6e97637..702ee5e 100644 --- a/src/c/aes192.c +++ b/src/c/aes192.c @@ -11,8 +11,8 @@ #include <emmintrin.h> #include <wmmintrin.h> -AesNI_Block128 __fastcall aesni_aes192_encrypt_block_( - AesNI_Block128 plaintext, +AesNI_Aes_Block __fastcall aesni_aes192_encrypt_block_( + AesNI_Aes_Block plaintext, const AesNI_Aes192_RoundKeys* encryption_keys) { plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]); @@ -30,8 +30,8 @@ AesNI_Block128 __fastcall aesni_aes192_encrypt_block_( return _mm_aesenclast_si128(plaintext, encryption_keys->keys[12]); } -AesNI_Block128 __fastcall aesni_aes192_decrypt_block_( - AesNI_Block128 ciphertext, +AesNI_Aes_Block __fastcall aesni_aes192_decrypt_block_( + AesNI_Aes_Block ciphertext, const AesNI_Aes192_RoundKeys* decryption_keys) { ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]); @@ -50,11 +50,11 @@ AesNI_Block128 __fastcall aesni_aes192_decrypt_block_( } static void __fastcall aesni_aes192_expand_key_assist( - AesNI_Block128* prev_lo, - AesNI_Block128* prev_hi, - AesNI_Block128 hwgen) + AesNI_Aes_Block* prev_lo, + AesNI_Aes_Block* prev_hi, + AesNI_Aes_Block hwgen) { - AesNI_Block128 tmp = *prev_lo; + AesNI_Aes_Block tmp = *prev_lo; tmp = _mm_slli_si128(tmp, 4); *prev_lo = _mm_xor_si128(*prev_lo, tmp); @@ -75,8 +75,8 @@ static void __fastcall aesni_aes192_expand_key_assist( } void __fastcall aesni_aes192_expand_key_( - AesNI_Block128 key_lo, - AesNI_Block128 key_hi, + AesNI_Aes_Block key_lo, + AesNI_Aes_Block key_hi, AesNI_Aes192_RoundKeys* encryption_keys) { encryption_keys->keys[0] = key_lo; diff --git a/src/c/aes256.c b/src/c/aes256.c index 820010d..243ec03 100644 --- a/src/c/aes256.c +++ b/src/c/aes256.c @@ -11,8 +11,8 @@ #include <emmintrin.h> #include <wmmintrin.h> -AesNI_Block128 __fastcall aesni_aes256_encrypt_block_( - AesNI_Block128 plaintext, +AesNI_Aes_Block __fastcall aesni_aes256_encrypt_block_( + AesNI_Aes_Block plaintext, const AesNI_Aes256_RoundKeys* encryption_keys) { plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]); @@ -32,8 +32,8 @@ AesNI_Block128 __fastcall aesni_aes256_encrypt_block_( return _mm_aesenclast_si128(plaintext, encryption_keys->keys[14]); } -AesNI_Block128 __fastcall aesni_aes256_decrypt_block_( - AesNI_Block128 ciphertext, +AesNI_Aes_Block __fastcall aesni_aes256_decrypt_block_( + AesNI_Aes_Block ciphertext, const AesNI_Aes256_RoundKeys* decryption_keys) { ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]); @@ -53,12 +53,12 @@ AesNI_Block128 __fastcall aesni_aes256_decrypt_block_( return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[14]); } -static AesNI_Block128 __fastcall aesni_aes256_expand_key_assist( - AesNI_Block128* prev_lo, - AesNI_Block128* prev_hi, - AesNI_Block128 hwgen) +static AesNI_Aes_Block __fastcall aesni_aes256_expand_key_assist( + AesNI_Aes_Block* prev_lo, + AesNI_Aes_Block* prev_hi, + AesNI_Aes_Block hwgen) { - AesNI_Block128 tmp = *prev_lo; + AesNI_Aes_Block tmp = *prev_lo; tmp = _mm_slli_si128(tmp, 4); *prev_lo = _mm_xor_si128(*prev_lo, tmp); @@ -77,12 +77,12 @@ static AesNI_Block128 __fastcall aesni_aes256_expand_key_assist( } void __fastcall aesni_aes256_expand_key_( - AesNI_Block128 key_lo, - AesNI_Block128 key_hi, + AesNI_Aes_Block key_lo, + AesNI_Aes_Block key_hi, AesNI_Aes256_RoundKeys* encryption_keys) { - AesNI_Block128 prev_lo, prev_hi; - AesNI_Block128 hwgen; + AesNI_Aes_Block prev_lo, prev_hi; + AesNI_Aes_Block hwgen; prev_lo = encryption_keys->keys[0] = key_lo; prev_hi = encryption_keys->keys[1] = key_hi; diff --git a/test/aes128cbc_decrypt_block.c b/test/aes128cbc_decrypt_block.c index b286e64..ce05e1d 100644 --- a/test/aes128cbc_decrypt_block.c +++ b/test/aes128cbc_decrypt_block.c @@ -22,25 +22,26 @@ int main(int argc, char** argv) { for (--argc, ++argv; argc > -1; --argc, ++argv) { - AesNI_Block128 plaintext, key, ciphertext, iv; + AesNI_Block128 plaintext, ciphertext, iv; + AesNI_Aes128_Key key; AesNI_Aes128_RoundKeys encryption_keys, decryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block128(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); } - aesni_aes128_expand_key(key, &encryption_keys); + aesni_aes128_expand_key(&key, &encryption_keys); aesni_aes128_derive_decryption_keys(&encryption_keys, &decryption_keys); for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) @@ -48,13 +49,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&ciphertext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } plaintext = aesni_aes128_decrypt_block_cbc(ciphertext, &decryption_keys, iv, &iv); - aesni_print_block128(&plaintext, NULL); + aesni_aes_print_block(&plaintext, NULL); } } diff --git a/test/aes128cbc_encrypt_block.c b/test/aes128cbc_encrypt_block.c index 15348de..d51a673 100644 --- a/test/aes128cbc_encrypt_block.c +++ b/test/aes128cbc_encrypt_block.c @@ -22,38 +22,39 @@ int main(int argc, char** argv) { for (--argc, ++argv; argc > -1; --argc, ++argv) { - AesNI_Block128 plaintext, key, ciphertext, iv; + AesNI_Block128 plaintext, ciphertext, iv; + AesNI_Aes128_Key key; AesNI_Aes128_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block128(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); } - aesni_aes128_expand_key(key, &encryption_keys); + aesni_aes128_expand_key(&key, &encryption_keys); for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) { if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&plaintext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } ciphertext = aesni_aes128_encrypt_block_cbc(plaintext, &encryption_keys, iv, &iv); - aesni_print_block128(&ciphertext, NULL); + aesni_aes_print_block(&ciphertext, NULL); } } diff --git a/test/aes128cfb_decrypt_block.c b/test/aes128cfb_decrypt_block.c index a6d4f72..636e2d9 100644 --- a/test/aes128cfb_decrypt_block.c +++ b/test/aes128cfb_decrypt_block.c @@ -22,38 +22,39 @@ int main(int argc, char** argv) { for (--argc, ++argv; argc > -1; --argc, ++argv) { - AesNI_Block128 plaintext, key, ciphertext, iv; + AesNI_Block128 plaintext, ciphertext, iv; + AesNI_Aes128_Key key; AesNI_Aes128_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block128(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); } - aesni_aes128_expand_key(key, &encryption_keys); + aesni_aes128_expand_key(&key, &encryption_keys); for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) { if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&ciphertext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } plaintext = aesni_aes128_decrypt_block_cfb(ciphertext, &encryption_keys, iv, &iv); - aesni_print_block128(&plaintext, NULL); + aesni_aes_print_block(&plaintext, NULL); } } diff --git a/test/aes128cfb_encrypt_block.c b/test/aes128cfb_encrypt_block.c index e238048..fd64dc6 100644 --- a/test/aes128cfb_encrypt_block.c +++ b/test/aes128cfb_encrypt_block.c @@ -22,38 +22,39 @@ int main(int argc, char** argv) { for (--argc, ++argv; argc > -1; --argc, ++argv) { - AesNI_Block128 plaintext, key, ciphertext, iv; + AesNI_Block128 plaintext, ciphertext, iv; + AesNI_Aes128_Key key; AesNI_Aes128_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block128(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); } - aesni_aes128_expand_key(key, &encryption_keys); + aesni_aes128_expand_key(&key, &encryption_keys); for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) { if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&plaintext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } ciphertext = aesni_aes128_encrypt_block_cfb(plaintext, &encryption_keys, iv, &iv); - aesni_print_block128(&ciphertext, NULL); + aesni_aes_print_block(&ciphertext, NULL); } } diff --git a/test/aes128ctr_decrypt_block.c b/test/aes128ctr_decrypt_block.c index a9ed568..4e7e5b0 100644 --- a/test/aes128ctr_decrypt_block.c +++ b/test/aes128ctr_decrypt_block.c @@ -22,25 +22,26 @@ int main(int argc, char** argv) { for (--argc, ++argv; argc > -1; --argc, ++argv) { - AesNI_Block128 plaintext, key, ciphertext, iv; + AesNI_Block128 plaintext, ciphertext, iv; + AesNI_Aes128_Key key; AesNI_Aes128_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block128(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); } - aesni_aes128_expand_key(key, &encryption_keys); + aesni_aes128_expand_key(&key, &encryption_keys); int ctr = 0; @@ -49,13 +50,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&ciphertext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } plaintext = aesni_aes128_decrypt_block_ctr(ciphertext, &encryption_keys, iv, ctr++); - aesni_print_block128(&plaintext, NULL); + aesni_aes_print_block(&plaintext, NULL); } } diff --git a/test/aes128ctr_encrypt_block.c b/test/aes128ctr_encrypt_block.c index 1541274..ad2e036 100644 --- a/test/aes128ctr_encrypt_block.c +++ b/test/aes128ctr_encrypt_block.c @@ -22,25 +22,26 @@ int main(int argc, char** argv) { for (--argc, ++argv; argc > -1; --argc, ++argv) { - AesNI_Block128 plaintext, key, ciphertext, iv; + AesNI_Block128 plaintext, ciphertext, iv; + AesNI_Aes128_Key key; AesNI_Aes128_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block128(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); } - aesni_aes128_expand_key(key, &encryption_keys); + aesni_aes128_expand_key(&key, &encryption_keys); int ctr = 0; @@ -49,13 +50,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&plaintext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } ciphertext = aesni_aes128_encrypt_block_ctr(plaintext, &encryption_keys, iv, ctr++); - aesni_print_block128(&ciphertext, NULL); + aesni_aes_print_block(&ciphertext, NULL); } } diff --git a/test/aes128ecb_decrypt_block.c b/test/aes128ecb_decrypt_block.c index 809ed67..d68505d 100644 --- a/test/aes128ecb_decrypt_block.c +++ b/test/aes128ecb_decrypt_block.c @@ -22,19 +22,20 @@ int main(int argc, char** argv) { for (--argc, ++argv; argc > -1; --argc, ++argv) { - AesNI_Block128 plaintext, key, ciphertext; + AesNI_Block128 plaintext, ciphertext; + AesNI_Aes128_Key key; AesNI_Aes128_RoundKeys encryption_keys, decryption_keys; if (argc < 1) exit_with_usage(); - if (aesni_is_error(aesni_parse_block128(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); exit_with_usage(); } - aesni_aes128_expand_key(key, &encryption_keys); + aesni_aes128_expand_key(&key, &encryption_keys); aesni_aes128_derive_decryption_keys(&encryption_keys, &decryption_keys); for (--argc, ++argv; argc > 0; --argc, ++argv) @@ -42,13 +43,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&ciphertext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } plaintext = aesni_aes128_decrypt_block_ecb(ciphertext, &decryption_keys); - aesni_print_block128(&plaintext, NULL); + aesni_aes_print_block(&plaintext, NULL); } } diff --git a/test/aes128ecb_encrypt_block.c b/test/aes128ecb_encrypt_block.c index 1c73e90..77bb557 100644 --- a/test/aes128ecb_encrypt_block.c +++ b/test/aes128ecb_encrypt_block.c @@ -22,32 +22,33 @@ int main(int argc, char** argv) { for (--argc, ++argv; argc > -1; --argc, ++argv) { - AesNI_Block128 plaintext, key, ciphertext; + AesNI_Block128 plaintext, ciphertext; + AesNI_Aes128_Key key; AesNI_Aes128_RoundKeys encryption_keys; if (argc < 1) exit_with_usage(); - if (aesni_is_error(aesni_parse_block128(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); exit_with_usage(); } - aesni_aes128_expand_key(key, &encryption_keys); + aesni_aes128_expand_key(&key, &encryption_keys); for (--argc, ++argv; argc > 0; --argc, ++argv) { if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&plaintext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } ciphertext = aesni_aes128_encrypt_block_ecb(plaintext, &encryption_keys); - aesni_print_block128(&ciphertext, NULL); + aesni_aes_print_block(&ciphertext, NULL); } } diff --git a/test/aes128ofb_decrypt_block.c b/test/aes128ofb_decrypt_block.c index e230451..10e865e 100644 --- a/test/aes128ofb_decrypt_block.c +++ b/test/aes128ofb_decrypt_block.c @@ -22,38 +22,39 @@ int main(int argc, char** argv) { for (--argc, ++argv; argc > -1; --argc, ++argv) { - AesNI_Block128 plaintext, key, ciphertext, iv; + AesNI_Block128 plaintext, ciphertext, iv; + AesNI_Aes128_Key key; AesNI_Aes128_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block128(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); } - aesni_aes128_expand_key(key, &encryption_keys); + aesni_aes128_expand_key(&key, &encryption_keys); for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) { if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&ciphertext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } plaintext = aesni_aes128_decrypt_block_ofb(ciphertext, &encryption_keys, iv, &iv); - aesni_print_block128(&plaintext, NULL); + aesni_aes_print_block(&plaintext, NULL); } } diff --git a/test/aes128ofb_encrypt_block.c b/test/aes128ofb_encrypt_block.c index 3911cf7..7bf3b00 100644 --- a/test/aes128ofb_encrypt_block.c +++ b/test/aes128ofb_encrypt_block.c @@ -22,38 +22,39 @@ int main(int argc, char** argv) { for (--argc, ++argv; argc > -1; --argc, ++argv) { - AesNI_Block128 plaintext, key, ciphertext, iv; + AesNI_Block128 plaintext, ciphertext, iv; + AesNI_Aes128_Key key; AesNI_Aes128_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block128(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); } - aesni_aes128_expand_key(key, &encryption_keys); + aesni_aes128_expand_key(&key, &encryption_keys); for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) { if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&plaintext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } ciphertext = aesni_aes128_encrypt_block_ofb(plaintext, &encryption_keys, iv, &iv); - aesni_print_block128(&ciphertext, NULL); + aesni_aes_print_block(&ciphertext, NULL); } } diff --git a/test/aes192cbc_decrypt_block.c b/test/aes192cbc_decrypt_block.c index fc72cf2..0cbef38 100644 --- a/test/aes192cbc_decrypt_block.c +++ b/test/aes192cbc_decrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block192 key; + AesNI_Aes192_Key key; AesNI_Aes192_RoundKeys encryption_keys, decryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block192(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -49,13 +49,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&ciphertext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } plaintext = aesni_aes192_decrypt_block_cbc(ciphertext, &decryption_keys, iv, &iv); - aesni_print_block128(&plaintext, NULL); + aesni_aes_print_block(&plaintext, NULL); } } diff --git a/test/aes192cbc_encrypt_block.c b/test/aes192cbc_encrypt_block.c index 8df44e2..c7df499 100644 --- a/test/aes192cbc_encrypt_block.c +++ b/test/aes192cbc_encrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block192 key; + AesNI_Aes192_Key key; AesNI_Aes192_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block192(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -48,13 +48,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&plaintext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } ciphertext = aesni_aes192_encrypt_block_cbc(plaintext, &encryption_keys, iv, &iv); - aesni_print_block128(&ciphertext, NULL); + aesni_aes_print_block(&ciphertext, NULL); } } diff --git a/test/aes192cfb_decrypt_block.c b/test/aes192cfb_decrypt_block.c index 8143972..1ede253 100644 --- a/test/aes192cfb_decrypt_block.c +++ b/test/aes192cfb_decrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block192 key; + AesNI_Aes192_Key key; AesNI_Aes192_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block192(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -48,13 +48,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&ciphertext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } plaintext = aesni_aes192_decrypt_block_cfb(ciphertext, &encryption_keys, iv, &iv); - aesni_print_block128(&plaintext, NULL); + aesni_aes_print_block(&plaintext, NULL); } } diff --git a/test/aes192cfb_encrypt_block.c b/test/aes192cfb_encrypt_block.c index 40214d8..7c98132 100644 --- a/test/aes192cfb_encrypt_block.c +++ b/test/aes192cfb_encrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block192 key; + AesNI_Aes192_Key key; AesNI_Aes192_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block192(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -48,13 +48,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&plaintext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } ciphertext = aesni_aes192_encrypt_block_cfb(plaintext, &encryption_keys, iv, &iv); - aesni_print_block128(&ciphertext, NULL); + aesni_aes_print_block(&ciphertext, NULL); } } diff --git a/test/aes192ctr_decrypt_block.c b/test/aes192ctr_decrypt_block.c index 2f88bcd..16bd35b 100644 --- a/test/aes192ctr_decrypt_block.c +++ b/test/aes192ctr_decrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block192 key; + AesNI_Aes192_Key key; AesNI_Aes192_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block192(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -50,13 +50,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&ciphertext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } plaintext = aesni_aes192_decrypt_block_ctr(ciphertext, &encryption_keys, iv, ctr++); - aesni_print_block128(&plaintext, NULL); + aesni_aes_print_block(&plaintext, NULL); } } diff --git a/test/aes192ctr_encrypt_block.c b/test/aes192ctr_encrypt_block.c index 3052ea3..d390f52 100644 --- a/test/aes192ctr_encrypt_block.c +++ b/test/aes192ctr_encrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block192 key; + AesNI_Aes192_Key key; AesNI_Aes192_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block192(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -50,13 +50,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&plaintext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } ciphertext = aesni_aes192_encrypt_block_ctr(plaintext, &encryption_keys, iv, ctr++); - aesni_print_block128(&ciphertext, NULL); + aesni_aes_print_block(&ciphertext, NULL); } } diff --git a/test/aes192ecb_decrypt_block.c b/test/aes192ecb_decrypt_block.c index 70c19f4..4200fc4 100644 --- a/test/aes192ecb_decrypt_block.c +++ b/test/aes192ecb_decrypt_block.c @@ -23,13 +23,13 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext; - AesNI_Block192 key; + AesNI_Aes192_Key key; AesNI_Aes192_RoundKeys encryption_keys, decryption_keys; if (argc < 1) exit_with_usage(); - if (aesni_is_error(aesni_parse_block192(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); exit_with_usage(); @@ -43,13 +43,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&ciphertext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } plaintext = aesni_aes192_decrypt_block_ecb(ciphertext, &decryption_keys); - aesni_print_block128(&plaintext, NULL); + aesni_aes_print_block(&plaintext, NULL); } } diff --git a/test/aes192ecb_encrypt_block.c b/test/aes192ecb_encrypt_block.c index b8eb7b2..2b140e3 100644 --- a/test/aes192ecb_encrypt_block.c +++ b/test/aes192ecb_encrypt_block.c @@ -23,13 +23,13 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext; - AesNI_Block192 key; + AesNI_Aes192_Key key; AesNI_Aes192_RoundKeys encryption_keys; if (argc < 1) exit_with_usage(); - if (aesni_is_error(aesni_parse_block192(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); exit_with_usage(); @@ -42,13 +42,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&plaintext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } ciphertext = aesni_aes192_encrypt_block_ecb(plaintext, &encryption_keys); - aesni_print_block128(&ciphertext, NULL); + aesni_aes_print_block(&ciphertext, NULL); } } diff --git a/test/aes192ofb_decrypt_block.c b/test/aes192ofb_decrypt_block.c index 6e1adcb..5d791ac 100644 --- a/test/aes192ofb_decrypt_block.c +++ b/test/aes192ofb_decrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block192 key; + AesNI_Aes192_Key key; AesNI_Aes192_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block192(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -48,13 +48,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&ciphertext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } plaintext = aesni_aes192_decrypt_block_ofb(ciphertext, &encryption_keys, iv, &iv); - aesni_print_block128(&plaintext, NULL); + aesni_aes_print_block(&plaintext, NULL); } } diff --git a/test/aes192ofb_encrypt_block.c b/test/aes192ofb_encrypt_block.c index 0ece731..cb2ab85 100644 --- a/test/aes192ofb_encrypt_block.c +++ b/test/aes192ofb_encrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block192 key; + AesNI_Aes192_Key key; AesNI_Aes192_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block192(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -48,13 +48,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&plaintext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } ciphertext = aesni_aes192_encrypt_block_ofb(plaintext, &encryption_keys, iv, &iv); - aesni_print_block128(&ciphertext, NULL); + aesni_aes_print_block(&ciphertext, NULL); } } diff --git a/test/aes256cbc_decrypt_block.c b/test/aes256cbc_decrypt_block.c index c65d5e5..db66bef 100644 --- a/test/aes256cbc_decrypt_block.c +++ b/test/aes256cbc_decrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block256 key; + AesNI_Aes256_Key key; AesNI_Aes256_RoundKeys encryption_keys, decryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block256(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -49,13 +49,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&ciphertext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } plaintext = aesni_aes256_decrypt_block_cbc(ciphertext, &decryption_keys, iv, &iv); - aesni_print_block128(&plaintext, NULL); + aesni_aes_print_block(&plaintext, NULL); } } diff --git a/test/aes256cbc_encrypt_block.c b/test/aes256cbc_encrypt_block.c index 76c3b4e..69426a4 100644 --- a/test/aes256cbc_encrypt_block.c +++ b/test/aes256cbc_encrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block256 key; + AesNI_Aes256_Key key; AesNI_Aes256_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block256(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -48,13 +48,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&plaintext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } ciphertext = aesni_aes256_encrypt_block_cbc(plaintext, &encryption_keys, iv, &iv); - aesni_print_block128(&ciphertext, NULL); + aesni_aes_print_block(&ciphertext, NULL); } } diff --git a/test/aes256cfb_decrypt_block.c b/test/aes256cfb_decrypt_block.c index 7c356a6..b4a0728 100644 --- a/test/aes256cfb_decrypt_block.c +++ b/test/aes256cfb_decrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block256 key; + AesNI_Aes256_Key key; AesNI_Aes256_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block256(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -48,13 +48,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&ciphertext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } plaintext = aesni_aes256_decrypt_block_cfb(ciphertext, &encryption_keys, iv, &iv); - aesni_print_block128(&plaintext, NULL); + aesni_aes_print_block(&plaintext, NULL); } } diff --git a/test/aes256cfb_encrypt_block.c b/test/aes256cfb_encrypt_block.c index 7d95658..ab0090f 100644 --- a/test/aes256cfb_encrypt_block.c +++ b/test/aes256cfb_encrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block256 key; + AesNI_Aes256_Key key; AesNI_Aes256_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block256(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -48,13 +48,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&plaintext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } ciphertext = aesni_aes256_encrypt_block_cfb(plaintext, &encryption_keys, iv, &iv); - aesni_print_block128(&ciphertext, NULL); + aesni_aes_print_block(&ciphertext, NULL); } } diff --git a/test/aes256ctr_decrypt_block.c b/test/aes256ctr_decrypt_block.c index 71f9854..9ba7365 100644 --- a/test/aes256ctr_decrypt_block.c +++ b/test/aes256ctr_decrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block256 key; + AesNI_Aes256_Key key; AesNI_Aes256_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block256(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -50,13 +50,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&ciphertext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } plaintext = aesni_aes256_decrypt_block_ctr(ciphertext, &encryption_keys, iv, ctr++); - aesni_print_block128(&plaintext, NULL); + aesni_aes_print_block(&plaintext, NULL); } } diff --git a/test/aes256ctr_encrypt_block.c b/test/aes256ctr_encrypt_block.c index c0452f1..344decc 100644 --- a/test/aes256ctr_encrypt_block.c +++ b/test/aes256ctr_encrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block256 key; + AesNI_Aes256_Key key; AesNI_Aes256_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block256(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -50,13 +50,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&plaintext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } ciphertext = aesni_aes256_encrypt_block_ctr(plaintext, &encryption_keys, iv, ctr++); - aesni_print_block128(&ciphertext, NULL); + aesni_aes_print_block(&ciphertext, NULL); } } diff --git a/test/aes256ecb_decrypt_block.c b/test/aes256ecb_decrypt_block.c index c1f84b9..25aa20e 100644 --- a/test/aes256ecb_decrypt_block.c +++ b/test/aes256ecb_decrypt_block.c @@ -23,13 +23,13 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext; - AesNI_Block256 key; + AesNI_Aes256_Key key; AesNI_Aes256_RoundKeys encryption_keys, decryption_keys; if (argc < 1) exit_with_usage(); - if (aesni_is_error(aesni_parse_block256(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); exit_with_usage(); @@ -43,13 +43,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&ciphertext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } plaintext = aesni_aes256_decrypt_block_ecb(ciphertext, &decryption_keys); - aesni_print_block128(&plaintext, NULL); + aesni_aes_print_block(&plaintext, NULL); } } diff --git a/test/aes256ecb_encrypt_block.c b/test/aes256ecb_encrypt_block.c index f12f1a2..b83ff39 100644 --- a/test/aes256ecb_encrypt_block.c +++ b/test/aes256ecb_encrypt_block.c @@ -23,13 +23,13 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext; - AesNI_Block256 key; + AesNI_Aes256_Key key; AesNI_Aes256_RoundKeys encryption_keys; if (argc < 1) exit_with_usage(); - if (aesni_is_error(aesni_parse_block256(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); exit_with_usage(); @@ -42,13 +42,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&plaintext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } ciphertext = aesni_aes256_encrypt_block_ecb(plaintext, &encryption_keys); - aesni_print_block128(&ciphertext, NULL); + aesni_aes_print_block(&ciphertext, NULL); } } diff --git a/test/aes256ofb_decrypt_block.c b/test/aes256ofb_decrypt_block.c index dfd29bc..02d7532 100644 --- a/test/aes256ofb_decrypt_block.c +++ b/test/aes256ofb_decrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block256 key; + AesNI_Aes256_Key key; AesNI_Aes256_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block256(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -48,13 +48,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&ciphertext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } plaintext = aesni_aes256_decrypt_block_ofb(ciphertext, &encryption_keys, iv, &iv); - aesni_print_block128(&plaintext, NULL); + aesni_aes_print_block(&plaintext, NULL); } } diff --git a/test/aes256ofb_encrypt_block.c b/test/aes256ofb_encrypt_block.c index 7d65671..a8434c8 100644 --- a/test/aes256ofb_encrypt_block.c +++ b/test/aes256ofb_encrypt_block.c @@ -23,19 +23,19 @@ int main(int argc, char** argv) for (--argc, ++argv; argc > -1; --argc, ++argv) { AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Block256 key; + AesNI_Aes256_Key key; AesNI_Aes256_RoundKeys encryption_keys; if (argc < 2) exit_with_usage(); - if (aesni_is_error(aesni_parse_block256(&key, *argv, NULL))) + if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) { fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); exit_with_usage(); } - if (aesni_is_error(aesni_parse_block128(&iv, argv[1], NULL))) + if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); exit_with_usage(); @@ -48,13 +48,13 @@ int main(int argc, char** argv) if (strcmp("--", *argv) == 0) break; - if (aesni_is_error(aesni_parse_block128(&plaintext, *argv, NULL))) + if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) { fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); continue; } ciphertext = aesni_aes256_encrypt_block_ofb(plaintext, &encryption_keys, iv, &iv); - aesni_print_block128(&ciphertext, NULL); + aesni_aes_print_block(&ciphertext, NULL); } } diff --git a/test/decrypt_block_aes.cpp b/test/decrypt_block_aes.cpp index 6cb9ce7..e0c289a 100644 --- a/test/decrypt_block_aes.cpp +++ b/test/decrypt_block_aes.cpp @@ -35,10 +35,10 @@ int main(int argc, char** argv) exit_with_usage(); AesNI_BoxAlgorithmParams algorithm_params; - aesni::from_string(algorithm_params.aes128_key, argv[0]); + aesni::aes::from_string(algorithm_params.aes128_key, argv[0]); AesNI_BoxBlock iv; - aesni::from_string(iv.aes_block, argv[1]); + aesni::aes::from_string(iv.aes_block, argv[1]); AesNI_Box box; aesni_box_init( @@ -55,7 +55,7 @@ int main(int argc, char** argv) break; AesNI_BoxBlock ciphertext; - aesni::from_string(ciphertext.aes_block, argv[0]); + aesni::aes::from_string(ciphertext.aes_block, argv[0]); AesNI_BoxBlock plaintext; aesni_box_decrypt( @@ -64,7 +64,7 @@ int main(int argc, char** argv) &plaintext, aesni::ErrorDetailsThrowsInDestructor()); - std::cout << plaintext.aes_block << "\n"; + std::cout << aesni::aes::to_string(plaintext.aes_block) << "\n"; } } diff --git a/test/encrypt_block_aes.cpp b/test/encrypt_block_aes.cpp index f15ddda..8be1fef 100644 --- a/test/encrypt_block_aes.cpp +++ b/test/encrypt_block_aes.cpp @@ -35,10 +35,10 @@ int main(int argc, char** argv) exit_with_usage(); AesNI_BoxAlgorithmParams algorithm_params; - aesni::from_string(algorithm_params.aes128_key, argv[0]); + aesni::aes::from_string(algorithm_params.aes128_key, argv[0]); AesNI_BoxBlock iv; - aesni::from_string(iv.aes_block, argv[1]); + aesni::aes::from_string(iv.aes_block, argv[1]); AesNI_Box box; aesni_box_init( @@ -55,7 +55,7 @@ int main(int argc, char** argv) break; AesNI_BoxBlock plaintext; - aesni::from_string(plaintext.aes_block, argv[0]); + aesni::aes::from_string(plaintext.aes_block, argv[0]); AesNI_BoxBlock ciphertext; aesni_box_encrypt( @@ -64,7 +64,7 @@ int main(int argc, char** argv) &ciphertext, aesni::ErrorDetailsThrowsInDestructor()); - std::cout << ciphertext.aes_block << "\n"; + std::cout << aesni::aes::to_string(ciphertext.aes_block) << "\n"; } } diff --git a/utils/aes128ecb_decrypt_file.cpp b/utils/aes128ecb_decrypt_file.cpp index 0f88144..ab55304 100644 --- a/utils/aes128ecb_decrypt_file.cpp +++ b/utils/aes128ecb_decrypt_file.cpp @@ -36,15 +36,15 @@ namespace int main(int argc, char** argv) { - AesNI_Block128 key; - AesNI_Aes128_RoundKeys encryption_keys, decryption_keys; - if (argc != 4) exit_with_usage(); try { - aesni_parse_block128(&key, argv[1], aesni::ErrorDetailsThrowsInDestructor()); + aesni::aes::Key128 key; + aesni::aes::from_string(key, argv[1]); + + aesni::aes::RoundKeys128 encryption_keys, decryption_keys; const std::string src_path(argv[2]); const std::string dest_path(argv[3]); @@ -60,7 +60,7 @@ int main(int argc, char** argv) src_buf.assign(std::istreambuf_iterator<char>(src_ifs), std::istreambuf_iterator<char>()); - aesni_aes128_expand_key(key, &encryption_keys); + aesni_aes128_expand_key(&key, &encryption_keys); aesni_aes128_derive_decryption_keys(&encryption_keys, &decryption_keys); std::size_t dest_size; diff --git a/utils/aes128ecb_encrypt_file.cpp b/utils/aes128ecb_encrypt_file.cpp index c7fef82..d197ec6 100644 --- a/utils/aes128ecb_encrypt_file.cpp +++ b/utils/aes128ecb_encrypt_file.cpp @@ -36,15 +36,15 @@ namespace int main(int argc, char** argv) { - AesNI_Block128 key; - AesNI_Aes128_RoundKeys encryption_keys; - if (argc != 4) exit_with_usage(); try { - aesni_parse_block128(&key, argv[1], aesni::ErrorDetailsThrowsInDestructor()); + aesni::aes::Key128 key; + aesni::aes::from_string(key, argv[1]); + + AesNI_Aes128_RoundKeys encryption_keys; const std::string src_path(argv[2]); const std::string dest_path(argv[3]); @@ -60,7 +60,7 @@ int main(int argc, char** argv) src_buf.assign(std::istreambuf_iterator<char>(src_ifs), std::istreambuf_iterator<char>()); - aesni_aes128_expand_key(key, &encryption_keys); + aesni_aes128_expand_key(&key, &encryption_keys); std::size_t dest_size; |