aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2015-07-26 00:44:16 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2015-07-26 00:44:16 +0300
commit6b31d793706f8422e06b5148e366644074a48b5d (patch)
tree4fffdc6e31d4edbce132443aeabc0d4c3ddc2d53
parentcxx: disable DbgHelp.h warnings (diff)
downloadaes-tools-6b31d793706f8422e06b5148e366644074a48b5d.tar.gz
aes-tools-6b31d793706f8422e06b5148e366644074a48b5d.zip
examples: merge to block utils
Diffstat (limited to '')
-rw-r--r--CMakeLists.txt1
-rw-r--r--TODO.md1
-rw-r--r--cxx/include/aesnixx/aes.hpp86
-rw-r--r--examples/CMakeLists.txt21
-rw-r--r--examples/aes128cbc.cpp60
-rw-r--r--examples/aes128cfb.cpp56
-rw-r--r--examples/aes128ctr.cpp56
-rw-r--r--examples/aes128ecb.cpp54
-rw-r--r--examples/aes128ofb.cpp56
-rw-r--r--examples/aes192cbc.cpp60
-rw-r--r--examples/aes192cfb.cpp56
-rw-r--r--examples/aes192ctr.cpp56
-rw-r--r--examples/aes192ecb.cpp54
-rw-r--r--examples/aes192ofb.cpp56
-rw-r--r--examples/aes256cbc.cpp60
-rw-r--r--examples/aes256cfb.cpp56
-rw-r--r--examples/aes256ctr.cpp56
-rw-r--r--examples/aes256ecb.cpp54
-rw-r--r--examples/aes256ofb.cpp56
-rw-r--r--examples/common.hpp105
-rw-r--r--utils/README.md7
-rw-r--r--utils/aes_block_common.hpp136
-rw-r--r--utils/aes_decrypt_block.cpp49
-rw-r--r--utils/aes_encrypt_block.cpp48
24 files changed, 251 insertions, 1049 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 19b6707..582309a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,5 +16,4 @@ target_compile_definitions(libaesni PRIVATE _CRT_SECURE_NO_WARNINGS)
add_subdirectory(cxx)
-add_subdirectory(examples)
add_subdirectory(utils)
diff --git a/TODO.md b/TODO.md
index cebb095..6084659 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,5 +1,4 @@
* Add file encryption tests.
* Add unit tests to the library.
* Using Boost.Test, perhaps? I'm using Boost anyway.
-* Merge "examples" into block utilities.
* Add algorithm benchmarks.
diff --git a/cxx/include/aesnixx/aes.hpp b/cxx/include/aesnixx/aes.hpp
index 1273c56..231e223 100644
--- a/cxx/include/aesnixx/aes.hpp
+++ b/cxx/include/aesnixx/aes.hpp
@@ -462,138 +462,128 @@ namespace aesni
};
template <Algorithm algorithm, Mode mode>
- class Encrypt;
+ struct Encrypt;
template <Algorithm algorithm>
- class Encrypt<algorithm, AESNI_ECB>
+ struct Encrypt<algorithm, AESNI_ECB>
{
- public:
Encrypt(const typename Types<algorithm>::KeyT& key,
const typename Types<algorithm>::BlockT& iv)
{
- expand_key(key, m_encryption_keys);
- derive_decryption_keys(m_encryption_keys, m_decryption_keys);
+ expand_key(key, encryption_keys);
+ derive_decryption_keys(encryption_keys, decryption_keys);
}
inline typename Types<algorithm>::BlockT encrypt(const typename Types<algorithm>::BlockT& plaintext)
{
- return encrypt_ecb(plaintext, m_encryption_keys);
+ return encrypt_ecb(plaintext, encryption_keys);
}
inline typename Types<algorithm>::BlockT decrypt(const typename Types<algorithm>::BlockT& ciphertext)
{
- return decrypt_ecb(ciphertext, m_decryption_keys);
+ return decrypt_ecb(ciphertext, decryption_keys);
}
- private:
- typename Types<algorithm>::RoundKeysT m_encryption_keys;
- typename Types<algorithm>::RoundKeysT m_decryption_keys;
+ typename Types<algorithm>::RoundKeysT encryption_keys;
+ typename Types<algorithm>::RoundKeysT decryption_keys;
};
template <Algorithm algorithm>
- class Encrypt<algorithm, AESNI_CBC>
+ struct Encrypt<algorithm, AESNI_CBC>
{
- public:
Encrypt(const typename Types<algorithm>::KeyT& key,
const typename Types<algorithm>::BlockT& iv)
- : m_iv(iv)
+ : iv(iv)
{
- expand_key(key, m_encryption_keys);
- derive_decryption_keys(m_encryption_keys, m_decryption_keys);
+ expand_key(key, encryption_keys);
+ derive_decryption_keys(encryption_keys, decryption_keys);
}
inline typename Types<algorithm>::BlockT encrypt(const typename Types<algorithm>::BlockT& plaintext)
{
- return encrypt_cbc(plaintext, m_encryption_keys, m_iv, m_iv);
+ return encrypt_cbc(plaintext, encryption_keys, iv, iv);
}
inline typename Types<algorithm>::BlockT decrypt(const typename Types<algorithm>::BlockT& ciphertext)
{
- return decrypt_cbc(ciphertext, m_decryption_keys, m_iv, m_iv);
+ return decrypt_cbc(ciphertext, decryption_keys, iv, iv);
}
- private:
- typename Types<algorithm>::BlockT m_iv;
- typename Types<algorithm>::RoundKeysT m_encryption_keys;
- typename Types<algorithm>::RoundKeysT m_decryption_keys;
+ typename Types<algorithm>::BlockT iv;
+ typename Types<algorithm>::RoundKeysT encryption_keys;
+ typename Types<algorithm>::RoundKeysT decryption_keys;
};
template <Algorithm algorithm>
- class Encrypt<algorithm, AESNI_CFB>
+ struct Encrypt<algorithm, AESNI_CFB>
{
- public:
Encrypt(const typename Types<algorithm>::KeyT& key,
const typename Types<algorithm>::BlockT& iv)
- : m_iv(iv)
+ : iv(iv)
{
- expand_key(key, m_encryption_keys);
+ expand_key(key, encryption_keys);
}
inline typename Types<algorithm>::BlockT encrypt(const typename Types<algorithm>::BlockT& plaintext)
{
- return encrypt_cfb(plaintext, m_encryption_keys, m_iv, m_iv);
+ return encrypt_cfb(plaintext, encryption_keys, iv, iv);
}
inline typename Types<algorithm>::BlockT decrypt(const typename Types<algorithm>::BlockT& ciphertext)
{
- return decrypt_cfb(ciphertext, m_encryption_keys, m_iv, m_iv);
+ return decrypt_cfb(ciphertext, encryption_keys, iv, iv);
}
- private:
- typename Types<algorithm>::BlockT m_iv;
- typename Types<algorithm>::RoundKeysT m_encryption_keys;
+ typename Types<algorithm>::BlockT iv;
+ typename Types<algorithm>::RoundKeysT encryption_keys;
};
template <Algorithm algorithm>
- class Encrypt<algorithm, AESNI_OFB>
+ struct Encrypt<algorithm, AESNI_OFB>
{
- public:
Encrypt(const typename Types<algorithm>::KeyT& key,
const typename Types<algorithm>::BlockT& iv)
- : m_iv(iv)
+ : iv(iv)
{
- expand_key(key, m_encryption_keys);
+ expand_key(key, encryption_keys);
}
inline typename Types<algorithm>::BlockT encrypt(const typename Types<algorithm>::BlockT& plaintext)
{
- return encrypt_ofb(plaintext, m_encryption_keys, m_iv, m_iv);
+ return encrypt_ofb(plaintext, encryption_keys, iv, iv);
}
inline typename Types<algorithm>::BlockT decrypt(const typename Types<algorithm>::BlockT& ciphertext)
{
- return decrypt_ofb(ciphertext, m_encryption_keys, m_iv, m_iv);
+ return decrypt_ofb(ciphertext, encryption_keys, iv, iv);
}
- private:
- typename Types<algorithm>::BlockT m_iv;
- typename Types<algorithm>::RoundKeysT m_encryption_keys;
+ typename Types<algorithm>::BlockT iv;
+ typename Types<algorithm>::RoundKeysT encryption_keys;
};
template <Algorithm algorithm>
- class Encrypt<algorithm, AESNI_CTR>
+ struct Encrypt<algorithm, AESNI_CTR>
{
- public:
Encrypt(const typename Types<algorithm>::KeyT& key,
const typename Types<algorithm>::BlockT& iv)
- : m_iv(iv)
+ : iv(iv)
{
- expand_key(key, m_encryption_keys);
+ expand_key(key, encryption_keys);
}
inline typename Types<algorithm>::BlockT encrypt(const typename Types<algorithm>::BlockT& plaintext)
{
- return encrypt_ctr(plaintext, m_encryption_keys, m_iv, m_iv);
+ return encrypt_ctr(plaintext, encryption_keys, iv, iv);
}
inline typename Types<algorithm>::BlockT decrypt(const typename Types<algorithm>::BlockT& ciphertext)
{
- return decrypt_ctr(ciphertext, m_encryption_keys, m_iv, m_iv);
+ return decrypt_ctr(ciphertext, encryption_keys, iv, iv);
}
- private:
- typename Types<algorithm>::RoundKeysT m_encryption_keys;
- typename Types<algorithm>::BlockT m_iv;
+ typename Types<algorithm>::RoundKeysT encryption_keys;
+ typename Types<algorithm>::BlockT iv;
};
}
}
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
deleted file mode 100644
index cb82577..0000000
--- a/examples/CMakeLists.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-macro(example prefix)
- add_executable(example_${prefix} ${prefix}.cpp)
- target_link_libraries(example_${prefix} libaesni libaesnixx)
- set_target_properties(example_${prefix} PROPERTIES OUTPUT_NAME ${prefix})
-endmacro()
-
-example(aes128ecb)
-example(aes128cbc)
-example(aes128cfb)
-example(aes128ofb)
-example(aes128ctr)
-example(aes192ecb)
-example(aes192cbc)
-example(aes192cfb)
-example(aes192ofb)
-example(aes192ctr)
-example(aes256ecb)
-example(aes256cbc)
-example(aes256cfb)
-example(aes256ofb)
-example(aes256ctr)
diff --git a/examples/aes128cbc.cpp b/examples/aes128cbc.cpp
deleted file mode 100644
index cf61604..0000000
--- a/examples/aes128cbc.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * \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 "common.hpp"
-
-#include <aesni/all.h>
-
-#include <aesnixx/all.hpp>
-
-#include <exception>
-#include <iostream>
-
-int main()
-{
- try
- {
- aesni::aes::Block plaintext;
- make_default_plaintext(plaintext);
-
- aesni::aes::Key128 key;
- make_default_key(key);
-
- aesni::aes::Block iv;
- make_default_iv(iv);
-
- aesni::aes::RoundKeys128 encryption_keys;
- aesni_aes128_expand_key(&key, &encryption_keys);
- dump_encryption_keys(encryption_keys);
-
- aesni::aes::Block next_iv;
- const auto ciphertext = aesni_aes128_encrypt_block_cbc(plaintext, &encryption_keys, iv, &next_iv);
- dump_ciphertext(ciphertext);
- dump_next_iv(next_iv);
-
- aesni::aes::RoundKeys128 decryption_keys;
- aesni_aes128_derive_decryption_keys(&encryption_keys, &decryption_keys);
- dump_decryption_keys(decryption_keys);
-
- aesni::aes::Block decrypted = aesni_aes128_decrypt_block_cbc(ciphertext, &decryption_keys, iv, &next_iv);
- dump_decrypted(decrypted);
- dump_next_iv(next_iv);
-
- return 0;
- }
- catch (const aesni::Error& e)
- {
- std::cerr << e;
- return 1;
- }
- catch (const std::exception& e)
- {
- std::cerr << e.what() << "\n";
- return 1;
- }
-}
diff --git a/examples/aes128cfb.cpp b/examples/aes128cfb.cpp
deleted file mode 100644
index c8f7230..0000000
--- a/examples/aes128cfb.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * \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 "common.hpp"
-
-#include <aesni/all.h>
-
-#include <aesnixx/all.hpp>
-
-#include <exception>
-#include <iostream>
-
-int main()
-{
- try
- {
- aesni::aes::Block plaintext;
- make_default_plaintext(plaintext);
-
- aesni::aes::Key128 key;
- make_default_key(key);
-
- aesni::aes::Block iv;
- make_default_iv(iv);
-
- aesni::aes::RoundKeys128 encryption_keys;
- aesni_aes128_expand_key(&key, &encryption_keys);
- dump_encryption_keys(encryption_keys);
-
- aesni::aes::Block next_iv;
- const auto ciphertext = aesni_aes128_encrypt_block_cfb(plaintext, &encryption_keys, iv, &next_iv);
- dump_ciphertext(ciphertext);
- dump_next_iv(next_iv);
-
- const auto decrypted = aesni_aes128_decrypt_block_cfb(ciphertext, &encryption_keys, iv, &next_iv);
- dump_decrypted(decrypted);
- dump_next_iv(next_iv);
-
- return 0;
- }
- catch (const aesni::Error& e)
- {
- std::cerr << e;
- return 1;
- }
- catch (const std::exception& e)
- {
- std::cerr << e.what() << "\n";
- return 1;
- }
-}
diff --git a/examples/aes128ctr.cpp b/examples/aes128ctr.cpp
deleted file mode 100644
index 5419ce2..0000000
--- a/examples/aes128ctr.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * \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 "common.hpp"
-
-#include <aesni/all.h>
-
-#include <aesnixx/all.hpp>
-
-#include <exception>
-#include <iostream>
-
-int main()
-{
- try
- {
- aesni::aes::Block plaintext;
- make_default_plaintext(plaintext);
-
- aesni::aes::Key128 key;
- make_default_key(key);
-
- aesni::aes::Block iv;
- make_default_iv(iv);
-
- aesni::aes::RoundKeys128 encryption_keys;
- aesni_aes128_expand_key(&key, &encryption_keys);
- dump_encryption_keys(encryption_keys);
-
- aesni::aes::Block next_iv;
- const auto ciphertext = aesni_aes128_encrypt_block_ctr(plaintext, &encryption_keys, iv, &next_iv);
- dump_ciphertext(ciphertext);
- dump_next_iv(next_iv);
-
- const auto decrypted = aesni_aes128_decrypt_block_ctr(ciphertext, &encryption_keys, iv, &next_iv);
- dump_decrypted(decrypted);
- dump_next_iv(next_iv);
-
- return 0;
- }
- catch (const aesni::Error& e)
- {
- std::cerr << e;
- return 1;
- }
- catch (const std::exception& e)
- {
- std::cerr << e.what() << "\n";
- return 1;
- }
-}
diff --git a/examples/aes128ecb.cpp b/examples/aes128ecb.cpp
deleted file mode 100644
index d999f81..0000000
--- a/examples/aes128ecb.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * \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 "common.hpp"
-
-#include <aesni/all.h>
-
-#include <aesnixx/all.hpp>
-
-#include <exception>
-#include <iostream>
-
-int main()
-{
- try
- {
- aesni::aes::Block plaintext;
- make_default_plaintext(plaintext);
-
- aesni::aes::Key128 key;
- make_default_key(key);
-
- aesni::aes::RoundKeys128 encryption_keys;
- aesni_aes128_expand_key(&key, &encryption_keys);
- dump_encryption_keys(encryption_keys);
-
- const auto ciphertext = aesni_aes128_encrypt_block_ecb(plaintext, &encryption_keys);
- dump_ciphertext(ciphertext);
-
- aesni::aes::RoundKeys128 decryption_keys;
- aesni_aes128_derive_decryption_keys(&encryption_keys, &decryption_keys);
- dump_decryption_keys(decryption_keys);
-
- const auto decrypted = aesni_aes128_decrypt_block_ecb(ciphertext, &decryption_keys);
- dump_decrypted(decrypted);
-
- return 0;
- }
- catch (const aesni::Error& e)
- {
- std::cerr << e;
- return 1;
- }
- catch (const std::exception& e)
- {
- std::cerr << e.what() << "\n";
- return 1;
- }
-}
diff --git a/examples/aes128ofb.cpp b/examples/aes128ofb.cpp
deleted file mode 100644
index f5f93d0..0000000
--- a/examples/aes128ofb.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * \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 "common.hpp"
-
-#include <aesni/all.h>
-
-#include <aesnixx/all.hpp>
-
-#include <exception>
-#include <iostream>
-
-int main()
-{
- try
- {
- aesni::aes::Block plaintext;
- make_default_plaintext(plaintext);
-
- aesni::aes::Key128 key;
- make_default_key(key);
-
- aesni::aes::Block iv;
- make_default_iv(iv);
-
- aesni::aes::RoundKeys128 encryption_keys;
- aesni_aes128_expand_key(&key, &encryption_keys);
- dump_encryption_keys(encryption_keys);
-
- aesni::aes::Block next_iv;
- const auto ciphertext = aesni_aes128_encrypt_block_ofb(plaintext, &encryption_keys, iv, &next_iv);
- dump_ciphertext(ciphertext);
- dump_next_iv(next_iv);
-
- const auto decrypted = aesni_aes128_decrypt_block_ofb(ciphertext, &encryption_keys, iv, &next_iv);
- dump_decrypted(decrypted);
- dump_next_iv(next_iv);
-
- return 0;
- }
- catch (const aesni::Error& e)
- {
- std::cerr << e;
- return 1;
- }
- catch (const std::exception& e)
- {
- std::cerr << e.what() << "\n";
- return 1;
- }
-}
diff --git a/examples/aes192cbc.cpp b/examples/aes192cbc.cpp
deleted file mode 100644
index b2adabd..0000000
--- a/examples/aes192cbc.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * \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 "common.hpp"
-
-#include <aesni/all.h>
-
-#include <aesnixx/all.hpp>
-
-#include <exception>
-#include <iostream>
-
-int main()
-{
- try
- {
- aesni::aes::Block plaintext;
- make_default_plaintext(plaintext);
-
- aesni::aes::Key192 key;
- make_default_key(key);
-
- aesni::aes::Block iv;
- make_default_iv(iv);
-
- aesni::aes::RoundKeys192 encryption_keys;
- aesni_aes192_expand_key(&key, &encryption_keys);
- dump_encryption_keys(encryption_keys);
-
- aesni::aes::Block next_iv;
- const auto ciphertext = aesni_aes192_encrypt_block_cbc(plaintext, &encryption_keys, iv, &next_iv);
- dump_ciphertext(ciphertext);
- dump_next_iv(next_iv);
-
- aesni::aes::RoundKeys192 decryption_keys;
- aesni_aes192_derive_decryption_keys(&encryption_keys, &decryption_keys);
- dump_decryption_keys(decryption_keys);
-
- const auto decrypted = aesni_aes192_decrypt_block_cbc(ciphertext, &decryption_keys, iv, &next_iv);
- dump_decrypted(decrypted);
- dump_next_iv(next_iv);
-
- return 0;
- }
- catch (const aesni::Error& e)
- {
- std::cerr << e;
- return 1;
- }
- catch (const std::exception& e)
- {
- std::cerr << e.what() << "\n";
- return 1;
- }
-}
diff --git a/examples/aes192cfb.cpp b/examples/aes192cfb.cpp
deleted file mode 100644
index d7fd9b5..0000000
--- a/examples/aes192cfb.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * \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 "common.hpp"
-
-#include <aesni/all.h>
-
-#include <aesnixx/all.hpp>
-
-#include <exception>
-#include <iostream>
-
-int main()
-{
- try
- {
- aesni::aes::Block plaintext;
- make_default_plaintext(plaintext);
-
- aesni::aes::Key192 key;
- make_default_key(key);
-
- aesni::aes::Block iv;
- make_default_iv(iv);
-
- aesni::aes::RoundKeys192 encryption_keys;
- aesni_aes192_expand_key(&key, &encryption_keys);
- dump_encryption_keys(encryption_keys);
-
- aesni::aes::Block next_iv;
- const auto ciphertext = aesni_aes192_encrypt_block_cfb(plaintext, &encryption_keys, iv, &next_iv);
- dump_ciphertext(ciphertext);
- dump_next_iv(next_iv);
-
- const auto decrypted = aesni_aes192_decrypt_block_cfb(ciphertext, &encryption_keys, iv, &next_iv);
- dump_decrypted(decrypted);
- dump_next_iv(next_iv);
-
- return 0;
- }
- catch (const aesni::Error& e)
- {
- std::cerr << e;
- return 1;
- }
- catch (const std::exception& e)
- {
- std::cerr << e.what() << "\n";
- return 1;
- }
-}
diff --git a/examples/aes192ctr.cpp b/examples/aes192ctr.cpp
deleted file mode 100644
index 9cad355..0000000
--- a/examples/aes192ctr.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * \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 "common.hpp"
-
-#include <aesni/all.h>
-
-#include <aesnixx/all.hpp>
-
-#include <exception>
-#include <iostream>
-
-int main()
-{
- try
- {
- aesni::aes::Block plaintext;
- make_default_plaintext(plaintext);
-
- aesni::aes::Key192 key;
- make_default_key(key);
-
- aesni::aes::Block iv;
- make_default_iv(iv);
-
- aesni::aes::RoundKeys192 encryption_keys;
- aesni_aes192_expand_key(&key, &encryption_keys);
- dump_encryption_keys(encryption_keys);
-
- aesni::aes::Block next_iv;
- const auto ciphertext = aesni_aes192_encrypt_block_ctr(plaintext, &encryption_keys, iv, &next_iv);
- dump_ciphertext(ciphertext);
- dump_next_iv(next_iv);
-
- const auto decrypted = aesni_aes192_decrypt_block_ctr(ciphertext, &encryption_keys, iv, &next_iv);
- dump_decrypted(decrypted);
- dump_next_iv(next_iv);
- }
- catch (const aesni::Error& e)
- {
- std::cerr << e;
- return 1;
- }
- catch (const std::exception& e)
- {
- std::cerr << e.what() << "\n";
- return 1;
- }
-
- return 0;
-}
diff --git a/examples/aes192ecb.cpp b/examples/aes192ecb.cpp
deleted file mode 100644
index 313f084..0000000
--- a/examples/aes192ecb.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * \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 "common.hpp"
-
-#include <aesni/all.h>
-
-#include <aesnixx/all.hpp>
-
-#include <exception>
-#include <iostream>
-
-int main()
-{
- try
- {
- aesni::aes::Block plaintext;
- make_default_plaintext(plaintext);
-
- aesni::aes::Key192 key;
- make_default_key(key);
-
- aesni::aes::RoundKeys192 encryption_keys;
- aesni_aes192_expand_key(&key, &encryption_keys);
- dump_encryption_keys(encryption_keys);
-
- const auto ciphertext = aesni_aes192_encrypt_block_ecb(plaintext, &encryption_keys);
- dump_ciphertext(ciphertext);
-
- aesni::aes::RoundKeys192 decryption_keys;
- aesni_aes192_derive_decryption_keys(&encryption_keys, &decryption_keys);
- dump_decryption_keys(decryption_keys);
-
- const auto decrypted = aesni_aes192_decrypt_block_ecb(ciphertext, &decryption_keys);
- dump_decrypted(decrypted);
-
- return 0;
- }
- catch (const aesni::Error& e)
- {
- std::cerr << e;
- return 1;
- }
- catch (const std::exception& e)
- {
- std::cerr << e.what() << "\n";
- return 1;
- }
-}
diff --git a/examples/aes192ofb.cpp b/examples/aes192ofb.cpp
deleted file mode 100644
index e2d96c4..0000000
--- a/examples/aes192ofb.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * \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 "common.hpp"
-
-#include <aesni/all.h>
-
-#include <aesnixx/all.hpp>
-
-#include <exception>
-#include <iostream>
-
-int main()
-{
- try
- {
- aesni::aes::Block plaintext;
- make_default_plaintext(plaintext);
-
- aesni::aes::Key192 key;
- make_default_key(key);
-
- aesni::aes::Block iv;
- make_default_iv(iv);
-
- aesni::aes::RoundKeys192 encryption_keys;
- aesni_aes192_expand_key(&key, &encryption_keys);
- dump_encryption_keys(encryption_keys);
-
- aesni::aes::Block next_iv;
- const auto ciphertext = aesni_aes192_encrypt_block_ofb(plaintext, &encryption_keys, iv, &next_iv);
- dump_ciphertext(ciphertext);
- dump_next_iv(next_iv);
-
- const auto decrypted = aesni_aes192_decrypt_block_ofb(ciphertext, &encryption_keys, iv, &next_iv);
- dump_decrypted(decrypted);
- dump_next_iv(next_iv);
-
- return 0;
- }
- catch (const aesni::Error& e)
- {
- std::cerr << e;
- return 1;
- }
- catch (const std::exception& e)
- {
- std::cerr << e.what() << "\n";
- return 1;
- }
-}
diff --git a/examples/aes256cbc.cpp b/examples/aes256cbc.cpp
deleted file mode 100644
index c5ab427..0000000
--- a/examples/aes256cbc.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * \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 "common.hpp"
-
-#include <aesni/all.h>
-
-#include <aesnixx/all.hpp>
-
-#include <exception>
-#include <iostream>
-
-int main()
-{
- try
- {
- aesni::aes::Block plaintext;
- make_default_plaintext(plaintext);
-
- aesni::aes::Key256 key;
- make_default_key(key);
-
- aesni::aes::Block iv;
- make_default_iv(iv);
-
- aesni::aes::RoundKeys256 encryption_keys;
- aesni_aes256_expand_key(&key, &encryption_keys);
- dump_encryption_keys(encryption_keys);
-
- aesni::aes::Block next_iv;
- const auto ciphertext = aesni_aes256_encrypt_block_cbc(plaintext, &encryption_keys, iv, &next_iv);
- dump_ciphertext(ciphertext);
- dump_next_iv(next_iv);
-
- aesni::aes::RoundKeys256 decryption_keys;
- aesni_aes256_derive_decryption_keys(&encryption_keys, &decryption_keys);
- dump_decryption_keys(decryption_keys);
-
- const auto decrypted = aesni_aes256_decrypt_block_cbc(ciphertext, &decryption_keys, iv, &next_iv);
- dump_decrypted(decrypted);
- dump_next_iv(next_iv);
-
- return 0;
- }
- catch (const aesni::Error& e)
- {
- std::cerr << e;
- return 1;
- }
- catch (const std::exception& e)
- {
- std::cerr << e.what() << "\n";
- return 1;
- }
-}
diff --git a/examples/aes256cfb.cpp b/examples/aes256cfb.cpp
deleted file mode 100644
index fb43d3a..0000000
--- a/examples/aes256cfb.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * \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 "common.hpp"
-
-#include <aesni/all.h>
-
-#include <aesnixx/all.hpp>
-
-#include <exception>
-#include <iostream>
-
-int main()
-{
- try
- {
- aesni::aes::Block plaintext;
- make_default_plaintext(plaintext);
-
- aesni::aes::Key256 key;
- make_default_key(key);
-
- aesni::aes::Block iv;
- make_default_iv(iv);
-
- aesni::aes::RoundKeys256 encryption_keys;
- aesni_aes256_expand_key(&key, &encryption_keys);
- dump_encryption_keys(encryption_keys);
-
- aesni::aes::Block next_iv;
- const auto ciphertext = aesni_aes256_encrypt_block_cfb(plaintext, &encryption_keys, iv, &next_iv);
- dump_ciphertext(ciphertext);
- dump_next_iv(next_iv);
-
- const auto decrypted = aesni_aes256_decrypt_block_cfb(ciphertext, &encryption_keys, iv, &next_iv);
- dump_decrypted(decrypted);
- dump_next_iv(next_iv);
-
- return 0;
- }
- catch (const aesni::Error& e)
- {
- std::cerr << e;
- return 1;
- }
- catch (const std::exception& e)
- {
- std::cerr << e.what() << "\n";
- return 1;
- }
-}
diff --git a/examples/aes256ctr.cpp b/examples/aes256ctr.cpp
deleted file mode 100644
index 9827e79..0000000
--- a/examples/aes256ctr.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * \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 "common.hpp"
-
-#include <aesni/all.h>
-
-#include <aesnixx/all.hpp>
-
-#include <exception>
-#include <iostream>
-
-int main()
-{
- try
- {
- aesni::aes::Block plaintext;
- make_default_plaintext(plaintext);
-
- aesni::aes::Key256 key;
- make_default_key(key);
-
- aesni::aes::Block iv;
- make_default_iv(iv);
-
- aesni::aes::RoundKeys256 encryption_keys;
- aesni_aes256_expand_key(&key, &encryption_keys);
- dump_encryption_keys(encryption_keys);
-
- aesni::aes::Block next_iv;
- const auto ciphertext = aesni_aes256_encrypt_block_ctr(plaintext, &encryption_keys, iv, &next_iv);
- dump_ciphertext(ciphertext);
- dump_next_iv(next_iv);
-
- const auto decrypted = aesni_aes256_decrypt_block_ctr(ciphertext, &encryption_keys, iv, &next_iv);
- dump_decrypted(decrypted);
- dump_next_iv(next_iv);
- }
- catch (const aesni::Error& e)
- {
- std::cerr << e;
- return 1;
- }
- catch (const std::exception& e)
- {
- std::cerr << e.what() << "\n";
- return 1;
- }
-
- return 0;
-}
diff --git a/examples/aes256ecb.cpp b/examples/aes256ecb.cpp
deleted file mode 100644
index e8777e2..0000000
--- a/examples/aes256ecb.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * \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 "common.hpp"
-
-#include <aesni/all.h>
-
-#include <aesnixx/all.hpp>
-
-#include <exception>
-#include <iostream>
-
-int main()
-{
- try
- {
- aesni::aes::Block plaintext;
- make_default_plaintext(plaintext);
-
- aesni::aes::Key256 key;
- make_default_key(key);
-
- aesni::aes::RoundKeys256 encryption_keys;
- aesni_aes256_expand_key(&key, &encryption_keys);
- dump_encryption_keys(encryption_keys);
-
- const auto ciphertext = aesni_aes256_encrypt_block_ecb(plaintext, &encryption_keys);
- dump_ciphertext(ciphertext);
-
- aesni::aes::RoundKeys256 decryption_keys;
- aesni_aes256_derive_decryption_keys(&encryption_keys, &decryption_keys);
- dump_decryption_keys(decryption_keys);
-
- const auto decrypted = aesni_aes256_decrypt_block_ecb(ciphertext, &decryption_keys);
- dump_decrypted(decrypted);
-
- return 0;
- }
- catch (const aesni::Error& e)
- {
- std::cerr << e;
- return 1;
- }
- catch (const std::exception& e)
- {
- std::cerr << e.what() << "\n";
- return 1;
- }
-}
diff --git a/examples/aes256ofb.cpp b/examples/aes256ofb.cpp
deleted file mode 100644
index 1d806aa..0000000
--- a/examples/aes256ofb.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * \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 "common.hpp"
-
-#include <aesni/all.h>
-
-#include <aesnixx/all.hpp>
-
-#include <exception>
-#include <iostream>
-
-int main()
-{
- try
- {
- aesni::aes::Block plaintext;
- make_default_plaintext(plaintext);
-
- aesni::aes::Key256 key;
- make_default_key(key);
-
- aesni::aes::Block iv;
- make_default_iv(iv);
-
- aesni::aes::RoundKeys256 encryption_keys;
- aesni_aes256_expand_key(&key, &encryption_keys);
- dump_encryption_keys(encryption_keys);
-
- aesni::aes::Block next_iv;
- const auto ciphertext = aesni_aes256_encrypt_block_ofb(plaintext, &encryption_keys, iv, &next_iv);
- dump_ciphertext(ciphertext);
- dump_next_iv(next_iv);
-
- const auto decrypted = aesni_aes256_decrypt_block_ofb(ciphertext, &encryption_keys, iv, &next_iv);
- dump_decrypted(decrypted);
- dump_next_iv(next_iv);
-
- return 0;
- }
- catch (const aesni::Error& e)
- {
- std::cerr << e;
- return 1;
- }
- catch (const std::exception& e)
- {
- std::cerr << e.what() << "\n";
- return 1;
- }
-}
diff --git a/examples/common.hpp b/examples/common.hpp
deleted file mode 100644
index 019a8da..0000000
--- a/examples/common.hpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- * \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.
- */
-
-#pragma once
-
-#include <aesnixx/all.hpp>
-
-#include <cstdlib>
-
-#include <iostream>
-
-namespace
-{
- void dump_block(const char* name, const aesni::aes::Block& block)
- {
- std::cout << name << ": " << aesni::aes::to_string(block) << "\n" << aesni::aes::to_matrix_string(block) << "\n";
- }
-
- void dump_plaintext(const aesni::aes::Block& block)
- {
- dump_block("Plaintext", block);
- }
-
- template <typename KeyT>
- void dump_key(const KeyT& key)
- {
- std::cout << "Key: " << aesni::aes::to_string(key) << "\n\n";
- }
-
- void dump_ciphertext(const aesni::aes::Block& ciphertext)
- {
- dump_block("Ciphertext", ciphertext);
- }
-
- void dump_iv(const aesni::aes::Block& iv)
- {
- dump_block("Initialization vector", iv);
- }
-
- void dump_next_iv(const aesni::aes::Block& next_iv)
- {
- dump_block("Next initialization vector", next_iv);
- }
-
- void dump_decrypted(const aesni::aes::Block& decrypted)
- {
- dump_block("Decrypted", decrypted);
- }
-
- void make_default_plaintext(aesni::aes::Block& plaintext)
- {
- aesni::make_block(plaintext, 0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- dump_plaintext(plaintext);
- }
-
- void make_default_key(aesni::aes::Key128& key)
- {
- aesni::aes::make_key(key, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
- dump_key(key);
- }
-
- void make_default_key(aesni::aes::Key192& key)
- {
- aesni::aes::make_key(key, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
- dump_key(key);
- }
-
- void make_default_key(aesni::aes::Key256& key)
- {
- aesni::aes::make_key(key, 0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
- dump_key(key);
- }
-
- void make_default_iv(aesni::aes::Block& iv)
- {
- aesni::make_block(iv, 0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210);
- dump_iv(iv);
- }
-
- template <typename RoundKeysT>
- void dump_round_keys(const char* name, const RoundKeysT& round_keys)
- {
- std::cout << name << ":\n";
- for (std::size_t i = 0; i < aesni::aes::get_number_of_rounds(round_keys); ++i)
- std::cout << "\t[" << i << "]: " << aesni::aes::to_string(round_keys.keys[i]) << "\n";
- std::cout << "\n";
- }
-
- template <typename RoundKeysT>
- void dump_encryption_keys(const RoundKeysT& round_keys)
- {
- dump_round_keys("Encryption round keys", round_keys);
- }
-
- template <typename RoundKeysT>
- void dump_decryption_keys(const RoundKeysT& round_keys)
- {
- dump_round_keys("Decryption round keys", round_keys);
- }
-}
diff --git a/utils/README.md b/utils/README.md
index 61204c6..8403ee0 100644
--- a/utils/README.md
+++ b/utils/README.md
@@ -15,6 +15,13 @@ On older CPUs, you can run the utilities
## Block encryption
+The block encryption utilities can produce verbose human-readable output,
+including round keys, intermediate initialization vector values, etc.
+This is primarily intended for debugging purposes.
+Enable verbose output by passing the `--verbose` flag to the utilities.
+Please note that verbose output can only be produced when *not* using "boxes"
+(the `--boxes` flag).
+
### aes_encrypt_block.exe
Encrypts 16-byte blocks using AES-128/192/256 in the specified mode of
diff --git a/utils/aes_block_common.hpp b/utils/aes_block_common.hpp
index 327efad..a61217d 100644
--- a/utils/aes_block_common.hpp
+++ b/utils/aes_block_common.hpp
@@ -69,6 +69,7 @@ namespace
: m_program_name(program_name)
, m_options("Options")
, m_boxes(false)
+ , m_verbose(false)
{ }
bool parse_options(int argc, char** argv)
@@ -79,7 +80,8 @@ namespace
("help,h", "show this message and exit")
("box,b", po::bool_switch(&m_boxes)->default_value(false), "use the \"boxes\" interface")
("mode,m", po::value<aesni::Mode>(&m_mode)->required(), "set mode of operation")
- ("algorithm,a", po::value<aesni::Algorithm>(&m_algorithm)->required(), "set algorithm");
+ ("algorithm,a", po::value<aesni::Algorithm>(&m_algorithm)->required(), "set algorithm")
+ ("verbose,v", po::bool_switch(&m_verbose)->default_value(false), "enable verbose output");
po::options_description hidden_options;
hidden_options.add_options()
@@ -130,6 +132,11 @@ namespace
return { std::make_move_iterator(m_args.begin()), std::make_move_iterator(m_args.end()) };
}
+ bool verbose() const
+ {
+ return m_verbose;
+ }
+
private:
const std::string m_program_name;
boost::program_options::options_description m_options;
@@ -138,5 +145,132 @@ namespace
aesni::Algorithm m_algorithm;
bool m_boxes;
std::vector<std::string> m_args;
+ bool m_verbose;
+ };
+}
+
+namespace
+{
+ void dump_block(const char* name, const aesni::aes::Block& block)
+ {
+ std::cout << name << ": " << aesni::aes::to_string(block) << "\n" << aesni::aes::to_matrix_string(block) << "\n";
+ }
+
+ void dump_plaintext(const aesni::aes::Block& block)
+ {
+ dump_block("Plaintext", block);
+ }
+
+ template <typename KeyT>
+ void dump_key(const KeyT& key)
+ {
+ std::cout << "Key: " << aesni::aes::to_string(key) << "\n\n";
+ }
+
+ void dump_ciphertext(const aesni::aes::Block& ciphertext)
+ {
+ dump_block("Ciphertext", ciphertext);
+ }
+
+ void dump_iv(const aesni::aes::Block& iv)
+ {
+ dump_block("Initialization vector", iv);
+ }
+
+ void dump_next_iv(const aesni::aes::Block& next_iv)
+ {
+ dump_block("Next initialization vector", next_iv);
+ }
+
+ template <typename RoundKeysT>
+ void dump_round_keys(const char* name, const RoundKeysT& round_keys)
+ {
+ std::cout << name << ":\n";
+ for (std::size_t i = 0; i < aesni::aes::get_number_of_rounds(round_keys); ++i)
+ std::cout << "\t[" << i << "]: " << aesni::aes::to_string(round_keys.keys[i]) << "\n";
+ std::cout << "\n";
+ }
+
+ template <typename RoundKeysT>
+ void dump_encryption_keys(const RoundKeysT& round_keys)
+ {
+ dump_round_keys("Encryption round keys", round_keys);
+ }
+
+ template <typename RoundKeysT>
+ void dump_decryption_keys(const RoundKeysT& round_keys)
+ {
+ dump_round_keys("Decryption round keys", round_keys);
+ }
+
+ template <aesni::Algorithm algo, aesni::Mode mode>
+ struct Dumper;
+
+ template <aesni::Algorithm algo>
+ struct Dumper<algo, AESNI_ECB>
+ {
+ static void dump_round_keys(const aesni::aes::Encrypt<algo, AESNI_ECB>& encrypt)
+ {
+ dump_encryption_keys(encrypt.encryption_keys);
+ dump_decryption_keys(encrypt.decryption_keys);
+ }
+
+ static void dump_next_iv(const aesni::aes::Encrypt<algo, AESNI_ECB>&)
+ { }
+ };
+
+ template <aesni::Algorithm algo>
+ struct Dumper<algo, AESNI_CBC>
+ {
+ static void dump_round_keys(const aesni::aes::Encrypt<algo, AESNI_CBC>& encrypt)
+ {
+ dump_encryption_keys(encrypt.encryption_keys);
+ dump_decryption_keys(encrypt.decryption_keys);
+ }
+
+ static void dump_next_iv(const aesni::aes::Encrypt<algo, AESNI_CBC>&)
+ { }
+ };
+
+ template <aesni::Algorithm algo>
+ struct Dumper<algo, AESNI_CFB>
+ {
+ static void dump_round_keys(const aesni::aes::Encrypt<algo, AESNI_CFB>& encrypt)
+ {
+ dump_encryption_keys(encrypt.encryption_keys);
+ }
+
+ static void dump_next_iv(const aesni::aes::Encrypt<algo, AESNI_CFB>& encrypt)
+ {
+ ::dump_next_iv(encrypt.iv);
+ }
+ };
+
+ template <aesni::Algorithm algo>
+ struct Dumper<algo, AESNI_OFB>
+ {
+ static void dump_round_keys(const aesni::aes::Encrypt<algo, AESNI_OFB>& encrypt)
+ {
+ dump_encryption_keys(encrypt.encryption_keys);
+ }
+
+ static void dump_next_iv(const aesni::aes::Encrypt<algo, AESNI_OFB>& encrypt)
+ {
+ ::dump_next_iv(encrypt.iv);
+ }
+ };
+
+ template <aesni::Algorithm algo>
+ struct Dumper<algo, AESNI_CTR>
+ {
+ static void dump_round_keys(const aesni::aes::Encrypt<algo, AESNI_CTR>& encrypt)
+ {
+ dump_encryption_keys(encrypt.encryption_keys);
+ }
+
+ static void dump_next_iv(const aesni::aes::Encrypt<algo, AESNI_CTR>& encrypt)
+ {
+ ::dump_next_iv(encrypt.iv);
+ }
};
}
diff --git a/utils/aes_decrypt_block.cpp b/utils/aes_decrypt_block.cpp
index 778aecb..bab5f50 100644
--- a/utils/aes_decrypt_block.cpp
+++ b/utils/aes_decrypt_block.cpp
@@ -22,7 +22,8 @@ namespace
template <aesni::Algorithm algorithm, aesni::Mode mode>
bool decrypt_with_mode(
const std::string& key_str,
- std::deque<std::string>& ciphertexts)
+ std::deque<std::string>& ciphertexts,
+ bool verbose = false)
{
typename aesni::aes::Types<algorithm>::BlockT iv;
@@ -33,20 +34,40 @@ namespace
aesni::aes::from_string(iv, ciphertexts.front());
ciphertexts.pop_front();
+
+ if (verbose)
+ dump_iv(iv);
}
typename aesni::aes::Types<algorithm>::KeyT key;
aesni::aes::from_string(key, key_str);
+ if (verbose)
+ dump_key(key);
+
aesni::aes::Encrypt<algorithm, mode> encrypt(key, iv);
+ if (verbose)
+ Dumper<algorithm, mode>::dump_round_keys(encrypt);
+
while (!ciphertexts.empty())
{
typename aesni::aes::Types<algorithm>::BlockT ciphertext;
aesni::aes::from_string(ciphertext, ciphertexts.front());
ciphertexts.pop_front();
- std::cout << aesni::aes::to_string(encrypt.decrypt(ciphertext)) << "\n";
+ const auto plaintext = encrypt.decrypt(ciphertext);
+
+ if (verbose)
+ {
+ dump_ciphertext(ciphertext);
+ dump_plaintext(plaintext);
+ Dumper<algorithm, mode>::dump_next_iv(encrypt);
+ }
+ else
+ {
+ std::cout << aesni::aes::to_string(plaintext) << "\n";
+ }
}
return true;
@@ -56,24 +77,25 @@ namespace
bool decrypt_with_algorithm(
aesni::Mode mode,
const std::string& key_str,
- std::deque<std::string>& ciphertexts)
+ std::deque<std::string>& ciphertexts,
+ bool verbose = false)
{
switch (mode)
{
case AESNI_ECB:
- return decrypt_with_mode<algorithm, AESNI_ECB>(key_str, ciphertexts);
+ return decrypt_with_mode<algorithm, AESNI_ECB>(key_str, ciphertexts, verbose);
case AESNI_CBC:
- return decrypt_with_mode<algorithm, AESNI_CBC>(key_str, ciphertexts);
+ return decrypt_with_mode<algorithm, AESNI_CBC>(key_str, ciphertexts, verbose);
case AESNI_CFB:
- return decrypt_with_mode<algorithm, AESNI_CFB>(key_str, ciphertexts);
+ return decrypt_with_mode<algorithm, AESNI_CFB>(key_str, ciphertexts, verbose);
case AESNI_OFB:
- return decrypt_with_mode<algorithm, AESNI_OFB>(key_str, ciphertexts);
+ return decrypt_with_mode<algorithm, AESNI_OFB>(key_str, ciphertexts, verbose);
case AESNI_CTR:
- return decrypt_with_mode<algorithm, AESNI_CTR>(key_str, ciphertexts);
+ return decrypt_with_mode<algorithm, AESNI_CTR>(key_str, ciphertexts, verbose);
default:
return false;
@@ -84,18 +106,19 @@ namespace
aesni::Algorithm algorithm,
aesni::Mode mode,
const std::string& key_str,
- std::deque<std::string> ciphertexts)
+ std::deque<std::string> ciphertexts,
+ bool verbose = false)
{
switch (algorithm)
{
case AESNI_AES128:
- return decrypt_with_algorithm<AESNI_AES128>(mode, key_str, ciphertexts);
+ return decrypt_with_algorithm<AESNI_AES128>(mode, key_str, ciphertexts, verbose);
case AESNI_AES192:
- return decrypt_with_algorithm<AESNI_AES192>(mode, key_str, ciphertexts);
+ return decrypt_with_algorithm<AESNI_AES192>(mode, key_str, ciphertexts, verbose);
case AESNI_AES256:
- return decrypt_with_algorithm<AESNI_AES256>(mode, key_str, ciphertexts);
+ return decrypt_with_algorithm<AESNI_AES256>(mode, key_str, ciphertexts, verbose);
default:
return false;
@@ -205,7 +228,7 @@ int main(int argc, char** argv)
const auto success = cmd_parser.use_boxes()
? decrypt_using_boxes(algorithm, mode, key, ciphertexts)
- : decrypt(algorithm, mode, key, ciphertexts);
+ : decrypt(algorithm, mode, key, ciphertexts, cmd_parser.verbose());
if (!success)
{
diff --git a/utils/aes_encrypt_block.cpp b/utils/aes_encrypt_block.cpp
index 89e935b..b814e99 100644
--- a/utils/aes_encrypt_block.cpp
+++ b/utils/aes_encrypt_block.cpp
@@ -22,7 +22,8 @@ namespace
template <aesni::Algorithm algorithm, aesni::Mode mode>
bool encrypt_with_mode(
const std::string& key_str,
- std::deque<std::string>& plaintexts)
+ std::deque<std::string>& plaintexts,
+ bool verbose = false)
{
typename aesni::aes::Types<algorithm>::BlockT iv;
@@ -33,20 +34,39 @@ namespace
aesni::aes::from_string(iv, plaintexts.front());
plaintexts.pop_front();
+
+ if (verbose)
+ dump_iv(iv);
}
typename aesni::aes::Types<algorithm>::KeyT key;
aesni::aes::from_string(key, key_str);
+ if (verbose)
+ dump_key(key);
+
aesni::aes::Encrypt<algorithm, mode> encrypt(key, iv);
+ if (verbose)
+ Dumper<algorithm, mode>::dump_round_keys(encrypt);
+
while (!plaintexts.empty())
{
typename aesni::aes::Types<algorithm>::BlockT plaintext;
aesni::aes::from_string(plaintext, plaintexts.front());
plaintexts.pop_front();
+ const auto ciphertext = encrypt.encrypt(plaintext);
- std::cout << aesni::aes::to_string(encrypt.encrypt(plaintext)) << "\n";
+ if (verbose)
+ {
+ dump_plaintext(plaintext);
+ dump_ciphertext(ciphertext);
+ Dumper<algorithm, mode>::dump_next_iv(encrypt);
+ }
+ else
+ {
+ std::cout << aesni::aes::to_string(ciphertext) << "\n";
+ }
}
return true;
@@ -56,24 +76,25 @@ namespace
bool encrypt_with_algorithm(
aesni::Mode mode,
const std::string& key_str,
- std::deque<std::string>& plaintexts)
+ std::deque<std::string>& plaintexts,
+ bool verbose = false)
{
switch (mode)
{
case AESNI_ECB:
- return encrypt_with_mode<algorithm, AESNI_ECB>(key_str, plaintexts);
+ return encrypt_with_mode<algorithm, AESNI_ECB>(key_str, plaintexts, verbose);
case AESNI_CBC:
- return encrypt_with_mode<algorithm, AESNI_CBC>(key_str, plaintexts);
+ return encrypt_with_mode<algorithm, AESNI_CBC>(key_str, plaintexts, verbose);
case AESNI_CFB:
- return encrypt_with_mode<algorithm, AESNI_CFB>(key_str, plaintexts);
+ return encrypt_with_mode<algorithm, AESNI_CFB>(key_str, plaintexts, verbose);
case AESNI_OFB:
- return encrypt_with_mode<algorithm, AESNI_OFB>(key_str, plaintexts);
+ return encrypt_with_mode<algorithm, AESNI_OFB>(key_str, plaintexts, verbose);
case AESNI_CTR:
- return encrypt_with_mode<algorithm, AESNI_CTR>(key_str, plaintexts);
+ return encrypt_with_mode<algorithm, AESNI_CTR>(key_str, plaintexts, verbose);
default:
return false;
@@ -84,18 +105,19 @@ namespace
aesni::Algorithm algorithm,
aesni::Mode mode,
const std::string& key_str,
- std::deque<std::string> plaintexts)
+ std::deque<std::string> plaintexts,
+ bool verbose = false)
{
switch (algorithm)
{
case AESNI_AES128:
- return encrypt_with_algorithm<AESNI_AES128>(mode, key_str, plaintexts);
+ return encrypt_with_algorithm<AESNI_AES128>(mode, key_str, plaintexts, verbose);
case AESNI_AES192:
- return encrypt_with_algorithm<AESNI_AES192>(mode, key_str, plaintexts);
+ return encrypt_with_algorithm<AESNI_AES192>(mode, key_str, plaintexts, verbose);
case AESNI_AES256:
- return encrypt_with_algorithm<AESNI_AES256>(mode, key_str, plaintexts);
+ return encrypt_with_algorithm<AESNI_AES256>(mode, key_str, plaintexts, verbose);
default:
return false;
@@ -205,7 +227,7 @@ int main(int argc, char** argv)
const auto success = cmd_parser.use_boxes()
? encrypt_using_boxes(algorithm, mode, key, plaintexts)
- : encrypt(algorithm, mode, key, plaintexts);
+ : encrypt(algorithm, mode, key, plaintexts, cmd_parser.verbose());
if (!success)
{