aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/decrypt_block_aes.cpp
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2015-06-17 05:35:55 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2015-06-17 05:35:55 +0300
commite24033e9b9e9fb28c86a3bbd43e94aa9f3417ff7 (patch)
tree0d82efe240b8b8525ceba4d6cc8d48de53785295 /test/decrypt_block_aes.cpp
parentadd "boxes" as a uniform encryption interface (diff)
downloadaes-tools-e24033e9b9e9fb28c86a3bbd43e94aa9f3417ff7.tar.gz
aes-tools-e24033e9b9e9fb28c86a3bbd43e94aa9f3417ff7.zip
test: add utilities to play with "boxes"
Diffstat (limited to 'test/decrypt_block_aes.cpp')
-rw-r--r--test/decrypt_block_aes.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/test/decrypt_block_aes.cpp b/test/decrypt_block_aes.cpp
new file mode 100644
index 0000000..acc9c6b
--- /dev/null
+++ b/test/decrypt_block_aes.cpp
@@ -0,0 +1,78 @@
+/**
+ * \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 <aesni/all.h>
+
+#include <aesnixx/all.hpp>
+
+#include <cstdlib>
+#include <cstring>
+
+#include <exception>
+#include <iostream>
+
+namespace
+{
+ void exit_with_usage()
+ {
+ std::cout << "Usage: encrypt_block_aes.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]\n";
+ std::exit(EXIT_FAILURE);
+ }
+}
+
+int main(int argc, char** argv)
+{
+ try
+ {
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ if (argc < 2)
+ exit_with_usage();
+
+ AesNI_AlgorithmParams algorithm_params;
+ aesni::from_string(algorithm_params.aes128_key, argv[0]);
+
+ AesNI_State iv;
+ aesni::from_string(iv.aes_block, argv[1]);
+
+ AesNI_Box box;
+ aesni_box_init(
+ &box,
+ AESNI_AES128,
+ &algorithm_params,
+ AESNI_OFB,
+ &iv,
+ aesni::ErrorDetailsThrowsInDestructor());
+
+ for (argc -= 2, argv += 2; argc > 0; --argc, ++argv)
+ {
+ if (std::strcmp("--", argv[0]) == 0)
+ break;
+
+ AesNI_State ciphertext;
+ aesni::from_string(ciphertext.aes_block, argv[0]);
+
+ AesNI_State plaintext;
+ aesni_box_decrypt(
+ &box,
+ &ciphertext,
+ &plaintext,
+ aesni::ErrorDetailsThrowsInDestructor());
+
+ std::cout << plaintext.aes_block << "\n";
+ }
+ }
+
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+}