aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2015-06-16 20:49:10 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2015-06-16 20:49:10 +0300
commit3ddcdb338778dcb46190cce759df54fcf592dc46 (patch)
treef97474b9331665fbd5de334e5d8de7622885c195
parentcxx: include data structures & I/O functions (diff)
downloadaes-tools-3ddcdb338778dcb46190cce759df54fcf592dc46.tar.gz
aes-tools-3ddcdb338778dcb46190cce759df54fcf592dc46.zip
examples: C++/libaesnixx instead of C/libaes
Diffstat (limited to '')
-rw-r--r--examples/CMakeLists.txt4
-rw-r--r--examples/aes128cbc.c110
-rw-r--r--examples/aes128cbc.cpp55
-rw-r--r--examples/aes128cfb.c99
-rw-r--r--examples/aes128cfb.cpp51
-rw-r--r--examples/aes128ctr.c81
-rw-r--r--examples/aes128ctr.cpp48
-rw-r--r--examples/aes128ecb.c82
-rw-r--r--examples/aes128ecb.cpp49
-rw-r--r--examples/aes128ofb.c99
-rw-r--r--examples/aes128ofb.cpp51
-rw-r--r--examples/aes192cbc.c111
-rw-r--r--examples/aes192cbc.cpp55
-rw-r--r--examples/aes192cfb.c100
-rw-r--r--examples/aes192cfb.cpp51
-rw-r--r--examples/aes192ctr.c82
-rw-r--r--examples/aes192ctr.cpp48
-rw-r--r--examples/aes192ecb.c83
-rw-r--r--examples/aes192ecb.cpp49
-rw-r--r--examples/aes192ofb.c100
-rw-r--r--examples/aes192ofb.cpp51
-rw-r--r--examples/aes256cbc.c111
-rw-r--r--examples/aes256cbc.cpp55
-rw-r--r--examples/aes256cfb.c100
-rw-r--r--examples/aes256cfb.cpp51
-rw-r--r--examples/aes256ctr.c82
-rw-r--r--examples/aes256ctr.cpp48
-rw-r--r--examples/aes256ecb.c83
-rw-r--r--examples/aes256ecb.cpp49
-rw-r--r--examples/aes256ofb.c100
-rw-r--r--examples/aes256ofb.cpp51
-rw-r--r--examples/common.hpp106
32 files changed, 870 insertions, 1425 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index d8ce968..cb82577 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,6 +1,6 @@
macro(example prefix)
- add_executable(example_${prefix} ${prefix}.c)
- target_link_libraries(example_${prefix} libaesni)
+ add_executable(example_${prefix} ${prefix}.cpp)
+ target_link_libraries(example_${prefix} libaesni libaesnixx)
set_target_properties(example_${prefix} PROPERTIES OUTPUT_NAME ${prefix})
endmacro()
diff --git a/examples/aes128cbc.c b/examples/aes128cbc.c
deleted file mode 100644
index 5d828a3..0000000
--- a/examples/aes128cbc.c
+++ /dev/null
@@ -1,110 +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 <aesni/all.h>
-
-#include <stdio.h>
-
-int main()
-{
- AesNI_Block128 plain, key, cipher, decrypted, iv, next_iv;
- AesNI_KeySchedule128 key_schedule, inverted_schedule;
-
- plain = aesni_make_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- key = aesni_make_block128(0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
- iv = aesni_make_block128(0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210);
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &plain, NULL);
- printf("Plain: %s\n", str.str);
- aesni_print_block128_as_matrix(&plain, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key, NULL);
- printf("Key: %s\n", str.str);
- aesni_print_block128_as_matrix(&key, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &iv, NULL);
- printf("Initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&iv, NULL);
- }
-
- aesni_expand_key_schedule128(key, &key_schedule);
-
- printf("\n");
- printf("Key schedule:\n");
- for (int i = 0; i < 11; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- cipher = aesni_encrypt_block_cbc128(plain, &key_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &cipher, NULL);
- printf("Cipher: %s\n", str.str);
- aesni_print_block128_as_matrix(&cipher, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- aesni_invert_key_schedule128(&key_schedule, &inverted_schedule);
-
- printf("\n");
- printf("Inverted key schedule:\n");
- for (int i = 0; i < 11; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &inverted_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- decrypted = aesni_decrypt_block_cbc128(cipher, &inverted_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &decrypted, NULL);
- printf("Decrypted: %s\n", str.str);
- aesni_print_block128_as_matrix(&decrypted, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- return 0;
-}
diff --git a/examples/aes128cbc.cpp b/examples/aes128cbc.cpp
new file mode 100644
index 0000000..c7e6550
--- /dev/null
+++ b/examples/aes128cbc.cpp
@@ -0,0 +1,55 @@
+/**
+ * \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::Block128 plaintext;
+ make_default_plaintext(plaintext);
+
+ aesni::Block128 key;
+ make_default_key(key);
+
+ aesni::Block128 iv;
+ make_default_iv(iv);
+
+ aesni::KeySchedule128 encryption_schedule;
+ aesni_expand_key_schedule128(key, &encryption_schedule);
+ dump_encryption_schedule(encryption_schedule);
+
+ aesni::Block128 next_iv;
+ const auto ciphertext = aesni_encrypt_block_cbc128(plaintext, &encryption_schedule, iv, &next_iv);
+ dump_ciphertext(ciphertext);
+ dump_next_iv(next_iv);
+
+ aesni::KeySchedule128 decryption_schedule;
+ aesni_invert_key_schedule128(&encryption_schedule, &decryption_schedule);
+ dump_decryption_schedule(decryption_schedule);
+
+ aesni::Block128 decrypted = aesni_decrypt_block_cbc128(ciphertext, &decryption_schedule, iv, &next_iv);
+ dump_decrypted(decrypted);
+ dump_next_iv(next_iv);
+
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+}
diff --git a/examples/aes128cfb.c b/examples/aes128cfb.c
deleted file mode 100644
index 06c77b3..0000000
--- a/examples/aes128cfb.c
+++ /dev/null
@@ -1,99 +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 <aesni/all.h>
-
-#include <stdio.h>
-
-int main()
-{
- AesNI_Block128 plain, key, cipher, decrypted, iv, next_iv;
- AesNI_KeySchedule128 key_schedule;
-
- plain = aesni_make_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- key = aesni_make_block128(0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
- iv = aesni_make_block128(0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210);
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &plain, NULL);
- printf("Plain: %s\n", str.str);
- aesni_print_block128_as_matrix(&plain, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key, NULL);
- printf("Key: %s\n", str.str);
- aesni_print_block128_as_matrix(&key, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &iv, NULL);
- printf("Initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&iv, NULL);
- }
-
- aesni_expand_key_schedule128(key, &key_schedule);
-
- printf("\n");
- printf("Key schedule:\n");
- for (int i = 0; i < 11; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- cipher = aesni_encrypt_block_cfb128(plain, &key_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &cipher, NULL);
- printf("Cipher: %s\n", str.str);
- aesni_print_block128_as_matrix(&cipher, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- decrypted = aesni_decrypt_block_cfb128(cipher, &key_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &decrypted, NULL);
- printf("Decrypted: %s\n", str.str);
- aesni_print_block128_as_matrix(&decrypted, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- return 0;
-}
diff --git a/examples/aes128cfb.cpp b/examples/aes128cfb.cpp
new file mode 100644
index 0000000..72a1be0
--- /dev/null
+++ b/examples/aes128cfb.cpp
@@ -0,0 +1,51 @@
+/**
+ * \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::Block128 plaintext;
+ make_default_plaintext(plaintext);
+
+ aesni::Block128 key;
+ make_default_key(key);
+
+ aesni::Block128 iv;
+ make_default_iv(iv);
+
+ aesni::KeySchedule128 encryption_schedule;
+ aesni_expand_key_schedule128(key, &encryption_schedule);
+ dump_encryption_schedule(encryption_schedule);
+
+ aesni::Block128 next_iv;
+ const auto ciphertext = aesni_encrypt_block_cfb128(plaintext, &encryption_schedule, iv, &next_iv);
+ dump_ciphertext(ciphertext);
+ dump_next_iv(next_iv);
+
+ const auto decrypted = aesni_decrypt_block_cfb128(ciphertext, &encryption_schedule, iv, &next_iv);
+ dump_decrypted(decrypted);
+ dump_next_iv(next_iv);
+
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+}
diff --git a/examples/aes128ctr.c b/examples/aes128ctr.c
deleted file mode 100644
index a9bcda6..0000000
--- a/examples/aes128ctr.c
+++ /dev/null
@@ -1,81 +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 <aesni/all.h>
-
-#include <stdio.h>
-
-int main()
-{
- AesNI_Block128 plain, key, cipher, decrypted, iv;
- AesNI_KeySchedule128 key_schedule;
-
- plain = aesni_make_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- key = aesni_make_block128(0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
- iv = aesni_make_block128(0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210);
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &plain, NULL);
- printf("Plain: %s\n", str.str);
- aesni_print_block128_as_matrix(&plain, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key, NULL);
- printf("Key: %s\n", str.str);
- aesni_print_block128_as_matrix(&key, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &iv, NULL);
- printf("Initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&iv, NULL);
- }
-
- aesni_expand_key_schedule128(key, &key_schedule);
-
- printf("\n");
- printf("Key schedule:\n");
- for (int i = 0; i < 11; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- cipher = aesni_encrypt_block_ctr128(plain, &key_schedule, iv, 0);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &cipher, NULL);
- printf("Cipher: %s\n", str.str);
- aesni_print_block128_as_matrix(&cipher, NULL);
- }
-
- decrypted = aesni_decrypt_block_ctr128(cipher, &key_schedule, iv, 0);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &decrypted, NULL);
- printf("Decrypted: %s\n", str.str);
- aesni_print_block128_as_matrix(&decrypted, NULL);
- }
-
- return 0;
-}
diff --git a/examples/aes128ctr.cpp b/examples/aes128ctr.cpp
new file mode 100644
index 0000000..a02052c
--- /dev/null
+++ b/examples/aes128ctr.cpp
@@ -0,0 +1,48 @@
+/**
+ * \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::Block128 plaintext;
+ make_default_plaintext(plaintext);
+
+ aesni::Block128 key;
+ make_default_key(key);
+
+ aesni::Block128 iv;
+ make_default_iv(iv);
+
+ aesni::KeySchedule128 encryption_schedule;
+ aesni_expand_key_schedule128(key, &encryption_schedule);
+ dump_encryption_schedule(encryption_schedule);
+
+ const auto ciphertext = aesni_encrypt_block_ctr128(plaintext, &encryption_schedule, iv, 0);
+ dump_ciphertext(ciphertext);
+
+ const auto decrypted = aesni_decrypt_block_ctr128(ciphertext, &encryption_schedule, iv, 0);
+ dump_decrypted(decrypted);
+
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+}
diff --git a/examples/aes128ecb.c b/examples/aes128ecb.c
deleted file mode 100644
index 6c98f32..0000000
--- a/examples/aes128ecb.c
+++ /dev/null
@@ -1,82 +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 <aesni/all.h>
-
-#include <stdio.h>
-
-int main()
-{
- AesNI_Block128 plain, key, cipher, decrypted;
- AesNI_KeySchedule128 key_schedule, inverted_schedule;
-
- plain = aesni_make_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- key = aesni_make_block128(0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &plain, NULL);
- printf("Plain: %s\n", str.str);
- aesni_print_block128_as_matrix(&plain, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key, NULL);
- printf("Key: %s\n", str.str);
- aesni_print_block128_as_matrix(&key, NULL);
- }
-
- aesni_expand_key_schedule128(key, &key_schedule);
-
- printf("\n");
- printf("Key schedule:\n");
- for (int i = 0; i < 11; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- cipher = aesni_encrypt_block_ecb128(plain, &key_schedule);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &cipher, NULL);
- printf("Cipher: %s\n", str.str);
- aesni_print_block128_as_matrix(&cipher, NULL);
- }
-
- aesni_invert_key_schedule128(&key_schedule, &inverted_schedule);
-
- printf("\n");
- printf("Inverted key schedule:\n");
- for (int i = 0; i < 11; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &inverted_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- decrypted = aesni_decrypt_block_ecb128(cipher, &inverted_schedule);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &decrypted, NULL);
- printf("Decrypted: %s\n", str.str);
- aesni_print_block128_as_matrix(&decrypted, NULL);
- }
-
- return 0;
-}
diff --git a/examples/aes128ecb.cpp b/examples/aes128ecb.cpp
new file mode 100644
index 0000000..8ffda3a
--- /dev/null
+++ b/examples/aes128ecb.cpp
@@ -0,0 +1,49 @@
+/**
+ * \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::Block128 plaintext;
+ make_default_plaintext(plaintext);
+
+ aesni::Block128 key;
+ make_default_key(key);
+
+ aesni::KeySchedule128 encryption_schedule;
+ aesni_expand_key_schedule128(key, &encryption_schedule);
+ dump_encryption_schedule(encryption_schedule);
+
+ const auto ciphertext = aesni_encrypt_block_ecb128(plaintext, &encryption_schedule);
+ dump_ciphertext(ciphertext);
+
+ aesni::KeySchedule128 decryption_schedule;
+ aesni_invert_key_schedule128(&encryption_schedule, &decryption_schedule);
+ dump_decryption_schedule(decryption_schedule);
+
+ const auto decrypted = aesni_decrypt_block_ecb128(ciphertext, &decryption_schedule);
+ dump_decrypted(decrypted);
+
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+}
diff --git a/examples/aes128ofb.c b/examples/aes128ofb.c
deleted file mode 100644
index 541ec41..0000000
--- a/examples/aes128ofb.c
+++ /dev/null
@@ -1,99 +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 <aesni/all.h>
-
-#include <stdio.h>
-
-int main()
-{
- AesNI_Block128 plain, key, cipher, decrypted, iv, next_iv;
- AesNI_KeySchedule128 key_schedule;
-
- plain = aesni_make_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- key = aesni_make_block128(0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
- iv = aesni_make_block128(0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210);
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &plain, NULL);
- printf("Plain: %s\n", str.str);
- aesni_print_block128_as_matrix(&plain, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key, NULL);
- printf("Key: %s\n", str.str);
- aesni_print_block128_as_matrix(&key, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &iv, NULL);
- printf("Initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&iv, NULL);
- }
-
- aesni_expand_key_schedule128(key, &key_schedule);
-
- printf("\n");
- printf("Key schedule:\n");
- for (int i = 0; i < 11; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- cipher = aesni_encrypt_block_ofb128(plain, &key_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &cipher, NULL);
- printf("Cipher: %s\n", str.str);
- aesni_print_block128_as_matrix(&cipher, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- decrypted = aesni_decrypt_block_ofb128(cipher, &key_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &decrypted, NULL);
- printf("Decrypted: %s\n", str.str);
- aesni_print_block128_as_matrix(&decrypted, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- return 0;
-}
diff --git a/examples/aes128ofb.cpp b/examples/aes128ofb.cpp
new file mode 100644
index 0000000..6b63936
--- /dev/null
+++ b/examples/aes128ofb.cpp
@@ -0,0 +1,51 @@
+/**
+ * \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::Block128 plaintext;
+ make_default_plaintext(plaintext);
+
+ aesni::Block128 key;
+ make_default_key(key);
+
+ aesni::Block128 iv;
+ make_default_iv(iv);
+
+ aesni::KeySchedule128 encryption_schedule;
+ aesni_expand_key_schedule128(key, &encryption_schedule);
+ dump_encryption_schedule(encryption_schedule);
+
+ aesni::Block128 next_iv;
+ const auto ciphertext = aesni_encrypt_block_ofb128(plaintext, &encryption_schedule, iv, &next_iv);
+ dump_ciphertext(ciphertext);
+ dump_next_iv(next_iv);
+
+ const auto decrypted = aesni_decrypt_block_ofb128(ciphertext, &encryption_schedule, iv, &next_iv);
+ dump_decrypted(decrypted);
+ dump_next_iv(next_iv);
+
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+}
diff --git a/examples/aes192cbc.c b/examples/aes192cbc.c
deleted file mode 100644
index c17ec0f..0000000
--- a/examples/aes192cbc.c
+++ /dev/null
@@ -1,111 +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 <aesni/all.h>
-
-#include <stdio.h>
-
-int main()
-{
- AesNI_Block128 plain, cipher, decrypted, iv, next_iv;
- AesNI_Block192 key;
- AesNI_KeySchedule192 key_schedule, inverted_schedule;
-
- plain = aesni_make_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- key = aesni_make_block192(0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
- iv = aesni_make_block128(0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210);
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &plain, NULL);
- printf("Plain: %s\n", str.str);
- aesni_print_block128_as_matrix(&plain, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString192 str;
- aesni_format_block192(&str, &key, NULL);
- printf("Key: %s\n", str.str);
- aesni_print_block192_as_matrix(&key, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &iv, NULL);
- printf("Initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&iv, NULL);
- }
-
- aesni_expand_key_schedule192(&key, &key_schedule);
-
- printf("\n");
- printf("Key schedule:\n");
- for (int i = 0; i < 13; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- cipher = aesni_encrypt_block_cbc192(plain, &key_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &cipher, NULL);
- printf("Cipher: %s\n", str.str);
- aesni_print_block128_as_matrix(&cipher, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- aesni_invert_key_schedule192(&key_schedule, &inverted_schedule);
-
- printf("\n");
- printf("Inverted key schedule:\n");
- for (int i = 0; i < 13; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &inverted_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- decrypted = aesni_decrypt_block_cbc192(cipher, &inverted_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &decrypted, NULL);
- printf("Decrypted: %s\n", str.str);
- aesni_print_block128_as_matrix(&decrypted, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- return 0;
-}
diff --git a/examples/aes192cbc.cpp b/examples/aes192cbc.cpp
new file mode 100644
index 0000000..f4341ea
--- /dev/null
+++ b/examples/aes192cbc.cpp
@@ -0,0 +1,55 @@
+/**
+ * \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::Block128 plaintext;
+ make_default_plaintext(plaintext);
+
+ aesni::Block192 key;
+ make_default_key(key);
+
+ aesni::Block128 iv;
+ make_default_iv(iv);
+
+ aesni::KeySchedule192 encryption_schedule;
+ aesni_expand_key_schedule192(&key, &encryption_schedule);
+ dump_encryption_schedule(encryption_schedule);
+
+ aesni::Block128 next_iv;
+ const auto ciphertext = aesni_encrypt_block_cbc192(plaintext, &encryption_schedule, iv, &next_iv);
+ dump_ciphertext(ciphertext);
+ dump_next_iv(next_iv);
+
+ aesni::KeySchedule192 decryption_schedule;
+ aesni_invert_key_schedule192(&encryption_schedule, &decryption_schedule);
+ dump_decryption_schedule(decryption_schedule);
+
+ const auto decrypted = aesni_decrypt_block_cbc192(ciphertext, &decryption_schedule, iv, &next_iv);
+ dump_decrypted(decrypted);
+ dump_next_iv(next_iv);
+
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+}
diff --git a/examples/aes192cfb.c b/examples/aes192cfb.c
deleted file mode 100644
index 17480e3..0000000
--- a/examples/aes192cfb.c
+++ /dev/null
@@ -1,100 +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 <aesni/all.h>
-
-#include <stdio.h>
-
-int main()
-{
- AesNI_Block128 plain, cipher, decrypted, iv, next_iv;
- AesNI_Block192 key;
- AesNI_KeySchedule192 key_schedule;
-
- plain = aesni_make_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- key = aesni_make_block192(0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
- iv = aesni_make_block128(0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210);
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &plain, NULL);
- printf("Plain: %s\n", str.str);
- aesni_print_block128_as_matrix(&plain, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString192 str;
- aesni_format_block192(&str, &key, NULL);
- printf("Key: %s\n", str.str);
- aesni_print_block192_as_matrix(&key, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &iv, NULL);
- printf("Initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&iv, NULL);
- }
-
- aesni_expand_key_schedule192(&key, &key_schedule);
-
- printf("\n");
- printf("Key schedule:\n");
- for (int i = 0; i < 13; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- cipher = aesni_encrypt_block_cfb192(plain, &key_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &cipher, NULL);
- printf("Cipher: %s\n", str.str);
- aesni_print_block128_as_matrix(&cipher, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- decrypted = aesni_decrypt_block_cfb192(cipher, &key_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &decrypted, NULL);
- printf("Decrypted: %s\n", str.str);
- aesni_print_block128_as_matrix(&decrypted, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- return 0;
-}
diff --git a/examples/aes192cfb.cpp b/examples/aes192cfb.cpp
new file mode 100644
index 0000000..88b94b7
--- /dev/null
+++ b/examples/aes192cfb.cpp
@@ -0,0 +1,51 @@
+/**
+ * \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::Block128 plaintext;
+ make_default_plaintext(plaintext);
+
+ aesni::Block192 key;
+ make_default_key(key);
+
+ aesni::Block128 iv;
+ make_default_iv(iv);
+
+ aesni::KeySchedule192 encryption_schedule;
+ aesni_expand_key_schedule192(&key, &encryption_schedule);
+ dump_encryption_schedule(encryption_schedule);
+
+ aesni::Block128 next_iv;
+ const auto ciphertext = aesni_encrypt_block_cfb192(plaintext, &encryption_schedule, iv, &next_iv);
+ dump_ciphertext(ciphertext);
+ dump_next_iv(next_iv);
+
+ const auto decrypted = aesni_decrypt_block_cfb192(ciphertext, &encryption_schedule, iv, &next_iv);
+ dump_decrypted(decrypted);
+ dump_next_iv(next_iv);
+
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+}
diff --git a/examples/aes192ctr.c b/examples/aes192ctr.c
deleted file mode 100644
index 82b41cf..0000000
--- a/examples/aes192ctr.c
+++ /dev/null
@@ -1,82 +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 <aesni/all.h>
-
-#include <stdio.h>
-
-int main()
-{
- AesNI_Block128 plain, cipher, decrypted, iv;
- AesNI_Block192 key;
- AesNI_KeySchedule192 key_schedule;
-
- plain = aesni_make_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- key = aesni_make_block192(0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
- iv = aesni_make_block128(0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210);
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &plain, NULL);
- printf("Plain: %s\n", str.str);
- aesni_print_block128_as_matrix(&plain, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString192 str;
- aesni_format_block192(&str, &key, NULL);
- printf("Key: %s\n", str.str);
- aesni_print_block192_as_matrix(&key, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &iv, NULL);
- printf("Initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&iv, NULL);
- }
-
- aesni_expand_key_schedule192(&key, &key_schedule);
-
- printf("\n");
- printf("Key schedule:\n");
- for (int i = 0; i < 13; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- cipher = aesni_encrypt_block_ctr192(plain, &key_schedule, iv, 0);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &cipher, NULL);
- printf("Cipher: %s\n", str.str);
- aesni_print_block128_as_matrix(&cipher, NULL);
- }
-
- decrypted = aesni_decrypt_block_ctr192(cipher, &key_schedule, iv, 0);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &decrypted, NULL);
- printf("Decrypted: %s\n", str.str);
- aesni_print_block128_as_matrix(&decrypted, NULL);
- }
-
- return 0;
-}
diff --git a/examples/aes192ctr.cpp b/examples/aes192ctr.cpp
new file mode 100644
index 0000000..f7278cf
--- /dev/null
+++ b/examples/aes192ctr.cpp
@@ -0,0 +1,48 @@
+/**
+ * \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::Block128 plaintext;
+ make_default_plaintext(plaintext);
+
+ aesni::Block192 key;
+ make_default_key(key);
+
+ aesni::Block128 iv;
+ make_default_iv(iv);
+
+ aesni::KeySchedule192 encryption_schedule;
+ aesni_expand_key_schedule192(&key, &encryption_schedule);
+ dump_encryption_schedule(encryption_schedule);
+
+ const auto ciphertext = aesni_encrypt_block_ctr192(plaintext, &encryption_schedule, iv, 0);
+ dump_ciphertext(ciphertext);
+
+ const auto decrypted = aesni_decrypt_block_ctr192(ciphertext, &encryption_schedule, iv, 0);
+ dump_decrypted(decrypted);
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/examples/aes192ecb.c b/examples/aes192ecb.c
deleted file mode 100644
index bdc048c..0000000
--- a/examples/aes192ecb.c
+++ /dev/null
@@ -1,83 +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 <aesni/all.h>
-
-#include <stdio.h>
-
-int main()
-{
- AesNI_Block128 plain, cipher, decrypted;
- AesNI_Block192 key;
- AesNI_KeySchedule192 key_schedule, inverted_schedule;
-
- plain = aesni_make_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- key = aesni_make_block192(0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &plain, NULL);
- printf("Plain: %s\n", str.str);
- aesni_print_block128_as_matrix(&plain, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString192 str;
- aesni_format_block192(&str, &key, NULL);
- printf("Key: %s\n", str.str);
- aesni_print_block192_as_matrix(&key, NULL);
- }
-
- aesni_expand_key_schedule192(&key, &key_schedule);
-
- printf("\n");
- printf("Key schedule:\n");
- for (int i = 0; i < 13; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- cipher = aesni_encrypt_block_ecb192(plain, &key_schedule);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &cipher, NULL);
- printf("Cipher: %s\n", str.str);
- aesni_print_block128_as_matrix(&cipher, NULL);
- }
-
- aesni_invert_key_schedule192(&key_schedule, &inverted_schedule);
-
- printf("\n");
- printf("Inverted key schedule:\n");
- for (int i = 0; i < 13; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &inverted_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- decrypted = aesni_decrypt_block_ecb192(cipher, &inverted_schedule);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &decrypted, NULL);
- printf("Decrypted: %s\n", str.str);
- aesni_print_block128_as_matrix(&decrypted, NULL);
- }
-
- return 0;
-}
diff --git a/examples/aes192ecb.cpp b/examples/aes192ecb.cpp
new file mode 100644
index 0000000..139b48b
--- /dev/null
+++ b/examples/aes192ecb.cpp
@@ -0,0 +1,49 @@
+/**
+ * \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::Block128 plaintext;
+ make_default_plaintext(plaintext);
+
+ aesni::Block192 key;
+ make_default_key(key);
+
+ aesni::KeySchedule192 encryption_schedule;
+ aesni_expand_key_schedule192(&key, &encryption_schedule);
+ dump_encryption_schedule(encryption_schedule);
+
+ const auto ciphertext = aesni_encrypt_block_ecb192(plaintext, &encryption_schedule);
+ dump_ciphertext(ciphertext);
+
+ aesni::KeySchedule192 decryption_schedule;
+ aesni_invert_key_schedule192(&encryption_schedule, &decryption_schedule);
+ dump_decryption_schedule(decryption_schedule);
+
+ const auto decrypted = aesni_decrypt_block_ecb192(ciphertext, &decryption_schedule);
+ dump_decrypted(decrypted);
+
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+}
diff --git a/examples/aes192ofb.c b/examples/aes192ofb.c
deleted file mode 100644
index de347ae..0000000
--- a/examples/aes192ofb.c
+++ /dev/null
@@ -1,100 +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 <aesni/all.h>
-
-#include <stdio.h>
-
-int main()
-{
- AesNI_Block128 plain, cipher, decrypted, iv, next_iv;
- AesNI_Block192 key;
- AesNI_KeySchedule192 key_schedule;
-
- plain = aesni_make_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- key = aesni_make_block192(0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
- iv = aesni_make_block128(0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210);
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &plain, NULL);
- printf("Plain: %s\n", str.str);
- aesni_print_block128_as_matrix(&plain, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString192 str;
- aesni_format_block192(&str, &key, NULL);
- printf("Key: %s\n", str.str);
- aesni_print_block192_as_matrix(&key, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &iv, NULL);
- printf("Initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&iv, NULL);
- }
-
- aesni_expand_key_schedule192(&key, &key_schedule);
-
- printf("\n");
- printf("Key schedule:\n");
- for (int i = 0; i < 13; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- cipher = aesni_encrypt_block_ofb192(plain, &key_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &cipher, NULL);
- printf("Cipher: %s\n", str.str);
- aesni_print_block128_as_matrix(&cipher, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- decrypted = aesni_decrypt_block_ofb192(cipher, &key_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &decrypted, NULL);
- printf("Decrypted: %s\n", str.str);
- aesni_print_block128_as_matrix(&decrypted, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- return 0;
-}
diff --git a/examples/aes192ofb.cpp b/examples/aes192ofb.cpp
new file mode 100644
index 0000000..5a07278
--- /dev/null
+++ b/examples/aes192ofb.cpp
@@ -0,0 +1,51 @@
+/**
+ * \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::Block128 plaintext;
+ make_default_plaintext(plaintext);
+
+ aesni::Block192 key;
+ make_default_key(key);
+
+ aesni::Block128 iv;
+ make_default_iv(iv);
+
+ aesni::KeySchedule192 encryption_schedule;
+ aesni_expand_key_schedule192(&key, &encryption_schedule);
+ dump_encryption_schedule(encryption_schedule);
+
+ aesni::Block128 next_iv;
+ const auto ciphertext = aesni_encrypt_block_ofb192(plaintext, &encryption_schedule, iv, &next_iv);
+ dump_ciphertext(ciphertext);
+ dump_next_iv(next_iv);
+
+ const auto decrypted = aesni_decrypt_block_ofb192(ciphertext, &encryption_schedule, iv, &next_iv);
+ dump_decrypted(decrypted);
+ dump_next_iv(next_iv);
+
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+}
diff --git a/examples/aes256cbc.c b/examples/aes256cbc.c
deleted file mode 100644
index f62fc84..0000000
--- a/examples/aes256cbc.c
+++ /dev/null
@@ -1,111 +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 <aesni/all.h>
-
-#include <stdio.h>
-
-int main()
-{
- AesNI_Block128 plain, cipher, decrypted, iv, next_iv;
- AesNI_Block256 key;
- AesNI_KeySchedule256 key_schedule, inverted_schedule;
-
- plain = aesni_make_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- key = aesni_make_block256(0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
- iv = aesni_make_block128(0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210);
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &plain, NULL);
- printf("Plain: %s\n", str.str);
- aesni_print_block128_as_matrix(&plain, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString256 str;
- aesni_format_block256(&str, &key, NULL);
- printf("Key: %s\n", str.str);
- aesni_print_block256_as_matrix(&key, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &iv, NULL);
- printf("Initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&iv, NULL);
- }
-
- aesni_expand_key_schedule256(&key, &key_schedule);
-
- printf("\n");
- printf("Key schedule:\n");
- for (int i = 0; i < 15; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- cipher = aesni_encrypt_block_cbc256(plain, &key_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &cipher, NULL);
- printf("Cipher: %s\n", str.str);
- aesni_print_block128_as_matrix(&cipher, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- aesni_invert_key_schedule256(&key_schedule, &inverted_schedule);
-
- printf("\n");
- printf("Inverted key schedule:\n");
- for (int i = 0; i < 15; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &inverted_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- decrypted = aesni_decrypt_block_cbc256(cipher, &inverted_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &decrypted, NULL);
- printf("Decrypted: %s\n", str.str);
- aesni_print_block128_as_matrix(&decrypted, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- return 0;
-}
diff --git a/examples/aes256cbc.cpp b/examples/aes256cbc.cpp
new file mode 100644
index 0000000..0253adb
--- /dev/null
+++ b/examples/aes256cbc.cpp
@@ -0,0 +1,55 @@
+/**
+ * \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::Block128 plaintext;
+ make_default_plaintext(plaintext);
+
+ aesni::Block256 key;
+ make_default_key(key);
+
+ aesni::Block128 iv;
+ make_default_iv(iv);
+
+ aesni::KeySchedule256 encryption_schedule;
+ aesni_expand_key_schedule256(&key, &encryption_schedule);
+ dump_encryption_schedule(encryption_schedule);
+
+ aesni::Block128 next_iv;
+ const auto ciphertext = aesni_encrypt_block_cbc256(plaintext, &encryption_schedule, iv, &next_iv);
+ dump_ciphertext(ciphertext);
+ dump_next_iv(next_iv);
+
+ aesni::KeySchedule256 decryption_schedule;
+ aesni_invert_key_schedule256(&encryption_schedule, &decryption_schedule);
+ dump_decryption_schedule(decryption_schedule);
+
+ const auto decrypted = aesni_decrypt_block_cbc256(ciphertext, &decryption_schedule, iv, &next_iv);
+ dump_decrypted(decrypted);
+ dump_next_iv(next_iv);
+
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+}
diff --git a/examples/aes256cfb.c b/examples/aes256cfb.c
deleted file mode 100644
index 950585d..0000000
--- a/examples/aes256cfb.c
+++ /dev/null
@@ -1,100 +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 <aesni/all.h>
-
-#include <stdio.h>
-
-int main()
-{
- AesNI_Block128 plain, cipher, decrypted, iv, next_iv;
- AesNI_Block256 key;
- AesNI_KeySchedule256 key_schedule;
-
- plain = aesni_make_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- key = aesni_make_block256(0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
- iv = aesni_make_block128(0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210);
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &plain, NULL);
- printf("Plain: %s\n", str.str);
- aesni_print_block128_as_matrix(&plain, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString256 str;
- aesni_format_block256(&str, &key, NULL);
- printf("Key: %s\n", str.str);
- aesni_print_block256_as_matrix(&key, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &iv, NULL);
- printf("Initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&iv, NULL);
- }
-
- aesni_expand_key_schedule256(&key, &key_schedule);
-
- printf("\n");
- printf("Key schedule:\n");
- for (int i = 0; i < 15; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- cipher = aesni_encrypt_block_cfb256(plain, &key_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &cipher, NULL);
- printf("Cipher: %s\n", str.str);
- aesni_print_block128_as_matrix(&cipher, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- decrypted = aesni_decrypt_block_cfb256(cipher, &key_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &decrypted, NULL);
- printf("Decrypted: %s\n", str.str);
- aesni_print_block128_as_matrix(&decrypted, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- return 0;
-}
diff --git a/examples/aes256cfb.cpp b/examples/aes256cfb.cpp
new file mode 100644
index 0000000..ce05aec
--- /dev/null
+++ b/examples/aes256cfb.cpp
@@ -0,0 +1,51 @@
+/**
+ * \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::Block128 plaintext;
+ make_default_plaintext(plaintext);
+
+ aesni::Block256 key;
+ make_default_key(key);
+
+ aesni::Block128 iv;
+ make_default_iv(iv);
+
+ aesni::KeySchedule256 encryption_schedule;
+ aesni_expand_key_schedule256(&key, &encryption_schedule);
+ dump_encryption_schedule(encryption_schedule);
+
+ aesni::Block128 next_iv;
+ const auto ciphertext = aesni_encrypt_block_cfb256(plaintext, &encryption_schedule, iv, &next_iv);
+ dump_ciphertext(ciphertext);
+ dump_next_iv(next_iv);
+
+ const auto decrypted = aesni_decrypt_block_cfb256(ciphertext, &encryption_schedule, iv, &next_iv);
+ dump_decrypted(decrypted);
+ dump_next_iv(next_iv);
+
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+}
diff --git a/examples/aes256ctr.c b/examples/aes256ctr.c
deleted file mode 100644
index efb36e4..0000000
--- a/examples/aes256ctr.c
+++ /dev/null
@@ -1,82 +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 <aesni/all.h>
-
-#include <stdio.h>
-
-int main()
-{
- AesNI_Block128 plain, cipher, decrypted, iv;
- AesNI_Block256 key;
- AesNI_KeySchedule256 key_schedule;
-
- plain = aesni_make_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- key = aesni_make_block256(0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
- iv = aesni_make_block128(0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210);
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &plain, NULL);
- printf("Plain: %s\n", str.str);
- aesni_print_block128_as_matrix(&plain, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString256 str;
- aesni_format_block256(&str, &key, NULL);
- printf("Key: %s\n", str.str);
- aesni_print_block256_as_matrix(&key, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &iv, NULL);
- printf("Initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&iv, NULL);
- }
-
- aesni_expand_key_schedule256(&key, &key_schedule);
-
- printf("\n");
- printf("Key schedule:\n");
- for (int i = 0; i < 15; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- cipher = aesni_encrypt_block_ctr256(plain, &key_schedule, iv, 0);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &cipher, NULL);
- printf("Cipher: %s\n", str.str);
- aesni_print_block128_as_matrix(&cipher, NULL);
- }
-
- decrypted = aesni_decrypt_block_ctr256(cipher, &key_schedule, iv, 0);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &decrypted, NULL);
- printf("Decrypted: %s\n", str.str);
- aesni_print_block128_as_matrix(&decrypted, NULL);
- }
-
- return 0;
-}
diff --git a/examples/aes256ctr.cpp b/examples/aes256ctr.cpp
new file mode 100644
index 0000000..1be85f7
--- /dev/null
+++ b/examples/aes256ctr.cpp
@@ -0,0 +1,48 @@
+/**
+ * \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::Block128 plaintext;
+ make_default_plaintext(plaintext);
+
+ aesni::Block256 key;
+ make_default_key(key);
+
+ aesni::Block128 iv;
+ make_default_iv(iv);
+
+ aesni::KeySchedule256 encryption_schedule;
+ aesni_expand_key_schedule256(&key, &encryption_schedule);
+ dump_encryption_schedule(encryption_schedule);
+
+ const auto ciphertext = aesni_encrypt_block_ctr256(plaintext, &encryption_schedule, iv, 0);
+ dump_ciphertext(ciphertext);
+
+ const auto decrypted = aesni_decrypt_block_ctr256(ciphertext, &encryption_schedule, iv, 0);
+ dump_decrypted(decrypted);
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/examples/aes256ecb.c b/examples/aes256ecb.c
deleted file mode 100644
index ddb90ca..0000000
--- a/examples/aes256ecb.c
+++ /dev/null
@@ -1,83 +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 <aesni/all.h>
-
-#include <stdio.h>
-
-int main()
-{
- AesNI_Block128 plain, cipher, decrypted;
- AesNI_Block256 key;
- AesNI_KeySchedule256 key_schedule, inverted_schedule;
-
- plain = aesni_make_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- key = aesni_make_block256(0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &plain, NULL);
- printf("Plain: %s\n", str.str);
- aesni_print_block128_as_matrix(&plain, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString256 str;
- aesni_format_block256(&str, &key, NULL);
- printf("Key: %s\n", str.str);
- aesni_print_block256_as_matrix(&key, NULL);
- }
-
- aesni_expand_key_schedule256(&key, &key_schedule);
-
- printf("\n");
- printf("Key schedule:\n");
- for (int i = 0; i < 15; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- cipher = aesni_encrypt_block_ecb256(plain, &key_schedule);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &cipher, NULL);
- printf("Cipher: %s\n", str.str);
- aesni_print_block128_as_matrix(&cipher, NULL);
- }
-
- aesni_invert_key_schedule256(&key_schedule, &inverted_schedule);
-
- printf("\n");
- printf("Inverted key schedule:\n");
- for (int i = 0; i < 15; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &inverted_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- decrypted = aesni_decrypt_block_ecb256(cipher, &inverted_schedule);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &decrypted, NULL);
- printf("Decrypted: %s\n", str.str);
- aesni_print_block128_as_matrix(&decrypted, NULL);
- }
-
- return 0;
-}
diff --git a/examples/aes256ecb.cpp b/examples/aes256ecb.cpp
new file mode 100644
index 0000000..72f132e
--- /dev/null
+++ b/examples/aes256ecb.cpp
@@ -0,0 +1,49 @@
+/**
+ * \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::Block128 plaintext;
+ make_default_plaintext(plaintext);
+
+ aesni::Block256 key;
+ make_default_key(key);
+
+ aesni::KeySchedule256 encryption_schedule;
+ aesni_expand_key_schedule256(&key, &encryption_schedule);
+ dump_encryption_schedule(encryption_schedule);
+
+ const auto ciphertext = aesni_encrypt_block_ecb256(plaintext, &encryption_schedule);
+ dump_ciphertext(ciphertext);
+
+ aesni::KeySchedule256 decryption_schedule;
+ aesni_invert_key_schedule256(&encryption_schedule, &decryption_schedule);
+ dump_decryption_schedule(decryption_schedule);
+
+ const auto decrypted = aesni_decrypt_block_ecb256(ciphertext, &decryption_schedule);
+ dump_decrypted(decrypted);
+
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+}
diff --git a/examples/aes256ofb.c b/examples/aes256ofb.c
deleted file mode 100644
index 8a7bf32..0000000
--- a/examples/aes256ofb.c
+++ /dev/null
@@ -1,100 +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 <aesni/all.h>
-
-#include <stdio.h>
-
-int main()
-{
- AesNI_Block128 plain, cipher, decrypted, iv, next_iv;
- AesNI_Block256 key;
- AesNI_KeySchedule256 key_schedule;
-
- plain = aesni_make_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
- key = aesni_make_block256(0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
- iv = aesni_make_block128(0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210);
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &plain, NULL);
- printf("Plain: %s\n", str.str);
- aesni_print_block128_as_matrix(&plain, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString256 str;
- aesni_format_block256(&str, &key, NULL);
- printf("Key: %s\n", str.str);
- aesni_print_block256_as_matrix(&key, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &iv, NULL);
- printf("Initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&iv, NULL);
- }
-
- aesni_expand_key_schedule256(&key, &key_schedule);
-
- printf("\n");
- printf("Key schedule:\n");
- for (int i = 0; i < 15; ++i)
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &key_schedule.keys[i], NULL);
- printf("\t[%d]: %s\n", i, str.str);
- }
-
- cipher = aesni_encrypt_block_ofb256(plain, &key_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &cipher, NULL);
- printf("Cipher: %s\n", str.str);
- aesni_print_block128_as_matrix(&cipher, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- decrypted = aesni_decrypt_block_ofb256(cipher, &key_schedule, iv, &next_iv);
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &decrypted, NULL);
- printf("Decrypted: %s\n", str.str);
- aesni_print_block128_as_matrix(&decrypted, NULL);
- }
-
- printf("\n");
-
- {
- AesNI_BlockString128 str;
- aesni_format_block128(&str, &next_iv, NULL);
- printf("Next initialization vector: %s\n", str.str);
- aesni_print_block128_as_matrix(&next_iv, NULL);
- }
-
- return 0;
-}
diff --git a/examples/aes256ofb.cpp b/examples/aes256ofb.cpp
new file mode 100644
index 0000000..34f9725
--- /dev/null
+++ b/examples/aes256ofb.cpp
@@ -0,0 +1,51 @@
+/**
+ * \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::Block128 plaintext;
+ make_default_plaintext(plaintext);
+
+ aesni::Block256 key;
+ make_default_key(key);
+
+ aesni::Block128 iv;
+ make_default_iv(iv);
+
+ aesni::KeySchedule256 encryption_schedule;
+ aesni_expand_key_schedule256(&key, &encryption_schedule);
+ dump_encryption_schedule(encryption_schedule);
+
+ aesni::Block128 next_iv;
+ const auto ciphertext = aesni_encrypt_block_ofb256(plaintext, &encryption_schedule, iv, &next_iv);
+ dump_ciphertext(ciphertext);
+ dump_next_iv(next_iv);
+
+ const auto decrypted = aesni_decrypt_block_ofb256(ciphertext, &encryption_schedule, iv, &next_iv);
+ dump_decrypted(decrypted);
+ dump_next_iv(next_iv);
+
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ return 1;
+ }
+}
diff --git a/examples/common.hpp b/examples/common.hpp
new file mode 100644
index 0000000..0188352
--- /dev/null
+++ b/examples/common.hpp
@@ -0,0 +1,106 @@
+/**
+ * \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
+{
+ template <typename BlockT>
+ void dump_block(const char* name, const BlockT& block)
+ {
+ std::cout << name << ": " << block << "\n" << aesni::to_matrix_string(block) << "\n";
+ }
+
+ void dump_plaintext(const aesni::Block128& block)
+ {
+ dump_block("Plaintext", block);
+ }
+
+ template <typename BlockT>
+ void dump_key(const BlockT& key)
+ {
+ dump_block("Key", key);
+ }
+
+ void dump_ciphertext(const aesni::Block128& ciphertext)
+ {
+ dump_block("Ciphertext", ciphertext);
+ }
+
+ void dump_iv(const aesni::Block128& iv)
+ {
+ dump_block("Initialization vector", iv);
+ }
+
+ void dump_next_iv(const aesni::Block128& next_iv)
+ {
+ dump_block("Next initialization vector", next_iv);
+ }
+
+ void dump_decrypted(const aesni::Block128& decrypted)
+ {
+ dump_block("Decrypted", decrypted);
+ }
+
+ void make_default_plaintext(aesni::Block128& plaintext)
+ {
+ aesni::make_block(plaintext, 0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100);
+ dump_plaintext(plaintext);
+ }
+
+ void make_default_key(aesni::Block128& key)
+ {
+ aesni::make_block(key, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
+ dump_key(key);
+ }
+
+ void make_default_key(aesni::Block192& key)
+ {
+ aesni::make_block(key, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
+ dump_key(key);
+ }
+
+ void make_default_key(aesni::Block256& key)
+ {
+ aesni::make_block(key, 0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
+ dump_key(key);
+ }
+
+ void make_default_iv(aesni::Block128& iv)
+ {
+ aesni::make_block(iv, 0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210);
+ dump_iv(iv);
+ }
+
+ template <typename KeyScheduleT>
+ 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";
+ std::cout << "\n";
+ }
+
+ template <typename KeyScheduleT>
+ void dump_encryption_schedule(const KeyScheduleT& schedule)
+ {
+ dump_schedule("Encryption schedule", schedule);
+ }
+
+ template <typename KeyScheduleT>
+ void dump_decryption_schedule(const KeyScheduleT& schedule)
+ {
+ dump_schedule("Decryption schedule", schedule);
+ }
+}