aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--test/CMakeLists.txt9
-rw-r--r--test/decrypt_block_aes.cpp78
-rw-r--r--test/encrypt_block_aes.cpp78
3 files changed, 165 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 2a1cc9a..4ca993e 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -23,3 +23,12 @@ test(aes256cbc)
test(aes256cfb)
test(aes256ofb)
test(aes256ctr)
+
+add_executable(test_encrypt_block_aes encrypt_block_aes.cpp)
+target_link_libraries(test_encrypt_block_aes libaesni libaesnixx)
+set_target_properties(test_encrypt_block_aes PROPERTIES OUTPUT_NAME encrypt_block_aes)
+
+add_executable(test_decrypt_block_aes decrypt_block_aes.cpp)
+target_link_libraries(test_decrypt_block_aes libaesni libaesnixx)
+set_target_properties(test_decrypt_block_aes PROPERTIES OUTPUT_NAME decrypt_block_aes)
+
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;
+ }
+}
diff --git a/test/encrypt_block_aes.cpp b/test/encrypt_block_aes.cpp
new file mode 100644
index 0000000..9db6e32
--- /dev/null
+++ b/test/encrypt_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 plaintext;
+ aesni::from_string(plaintext.aes_block, argv[0]);
+
+ AesNI_State ciphertext;
+ aesni_box_encrypt(
+ &box,
+ &plaintext,
+ &ciphertext,
+ aesni::ErrorDetailsThrowsInDestructor());
+
+ std::cout << ciphertext.aes_block << "\n";
+ }
+ }
+
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+}