aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/utils/aes_decrypt_block.cpp
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 /utils/aes_decrypt_block.cpp
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--utils/aes_decrypt_block.cpp49
1 files changed, 36 insertions, 13 deletions
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)
{