From 7fa14cde1b878f4a04daf1c1f16ca21a2bc9f6fd Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 18 Jun 2015 03:43:17 +0300 Subject: test: merge block utilities --- test/CMakeLists.txt | 37 +++--------- test/aes128cbc_decrypt_block.c | 63 ------------------- test/aes128cbc_encrypt_block.c | 62 ------------------- test/aes128cfb_decrypt_block.c | 62 ------------------- test/aes128cfb_encrypt_block.c | 62 ------------------- test/aes128ctr_decrypt_block.c | 64 -------------------- test/aes128ctr_encrypt_block.c | 64 -------------------- test/aes128ecb_decrypt_block.c | 57 ------------------ test/aes128ecb_encrypt_block.c | 56 ----------------- test/aes128ofb_decrypt_block.c | 62 ------------------- test/aes128ofb_encrypt_block.c | 62 ------------------- test/aes192cbc_decrypt_block.c | 63 ------------------- test/aes192cbc_encrypt_block.c | 62 ------------------- test/aes192cfb_decrypt_block.c | 62 ------------------- test/aes192cfb_encrypt_block.c | 62 ------------------- test/aes192ctr_decrypt_block.c | 64 -------------------- test/aes192ctr_encrypt_block.c | 64 -------------------- test/aes192ecb_decrypt_block.c | 57 ------------------ test/aes192ecb_encrypt_block.c | 56 ----------------- test/aes192ofb_decrypt_block.c | 62 ------------------- test/aes192ofb_encrypt_block.c | 62 ------------------- test/aes256cbc_decrypt_block.c | 63 ------------------- test/aes256cbc_encrypt_block.c | 62 ------------------- test/aes256cfb_decrypt_block.c | 62 ------------------- test/aes256cfb_encrypt_block.c | 62 ------------------- test/aes256ctr_decrypt_block.c | 64 -------------------- test/aes256ctr_encrypt_block.c | 64 -------------------- test/aes256ecb_decrypt_block.c | 57 ------------------ test/aes256ecb_encrypt_block.c | 56 ----------------- test/aes256ofb_decrypt_block.c | 62 ------------------- test/aes256ofb_encrypt_block.c | 62 ------------------- test/common_aes.hpp | 134 +++++++++++++++++++++++++++++++++++++++++ test/decrypt_block_aes.cpp | 87 ++++++++++++++++++-------- test/encrypt_block_aes.cpp | 87 ++++++++++++++++++-------- test/toolkit.py | 15 ++--- 35 files changed, 275 insertions(+), 1927 deletions(-) delete mode 100644 test/aes128cbc_decrypt_block.c delete mode 100644 test/aes128cbc_encrypt_block.c delete mode 100644 test/aes128cfb_decrypt_block.c delete mode 100644 test/aes128cfb_encrypt_block.c delete mode 100644 test/aes128ctr_decrypt_block.c delete mode 100644 test/aes128ctr_encrypt_block.c delete mode 100644 test/aes128ecb_decrypt_block.c delete mode 100644 test/aes128ecb_encrypt_block.c delete mode 100644 test/aes128ofb_decrypt_block.c delete mode 100644 test/aes128ofb_encrypt_block.c delete mode 100644 test/aes192cbc_decrypt_block.c delete mode 100644 test/aes192cbc_encrypt_block.c delete mode 100644 test/aes192cfb_decrypt_block.c delete mode 100644 test/aes192cfb_encrypt_block.c delete mode 100644 test/aes192ctr_decrypt_block.c delete mode 100644 test/aes192ctr_encrypt_block.c delete mode 100644 test/aes192ecb_decrypt_block.c delete mode 100644 test/aes192ecb_encrypt_block.c delete mode 100644 test/aes192ofb_decrypt_block.c delete mode 100644 test/aes192ofb_encrypt_block.c delete mode 100644 test/aes256cbc_decrypt_block.c delete mode 100644 test/aes256cbc_encrypt_block.c delete mode 100644 test/aes256cfb_decrypt_block.c delete mode 100644 test/aes256cfb_encrypt_block.c delete mode 100644 test/aes256ctr_decrypt_block.c delete mode 100644 test/aes256ctr_encrypt_block.c delete mode 100644 test/aes256ecb_decrypt_block.c delete mode 100644 test/aes256ecb_encrypt_block.c delete mode 100644 test/aes256ofb_decrypt_block.c delete mode 100644 test/aes256ofb_encrypt_block.c create mode 100644 test/common_aes.hpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4ca993e..199388d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,34 +1,11 @@ -macro(test prefix) - add_executable(test_${prefix}_encrypt_block ${prefix}_encrypt_block.c) - target_link_libraries(test_${prefix}_encrypt_block libaesni) - set_target_properties(test_${prefix}_encrypt_block PROPERTIES OUTPUT_NAME ${prefix}_encrypt_block) +find_package(Boost REQUIRED COMPONENTS program_options) - add_executable(test_${prefix}_decrypt_block ${prefix}_decrypt_block.c) - target_link_libraries(test_${prefix}_decrypt_block libaesni) - set_target_properties(test_${prefix}_decrypt_block PROPERTIES OUTPUT_NAME ${prefix}_decrypt_block) -endmacro() - -test(aes128ecb) -test(aes128cbc) -test(aes128cfb) -test(aes128ofb) -test(aes128ctr) -test(aes192ecb) -test(aes192cbc) -test(aes192cfb) -test(aes192ofb) -test(aes192ctr) -test(aes256ecb) -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) +add_executable(test_encrypt_block_aes encrypt_block_aes.cpp common_aes.hpp) +target_include_directories(test_encrypt_block_aes PRIVATE ${Boost_INCLUDE_DIRS}) +target_link_libraries(test_encrypt_block_aes libaesni libaesnixx ${Boost_LIBRARIES}) 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) +add_executable(test_decrypt_block_aes decrypt_block_aes.cpp common_aes.hpp) +target_include_directories(test_decrypt_block_aes PRIVATE ${Boost_INCLUDE_DIRS}) +target_link_libraries(test_decrypt_block_aes libaesni libaesnixx ${Boost_LIBRARIES}) set_target_properties(test_decrypt_block_aes PROPERTIES OUTPUT_NAME decrypt_block_aes) - diff --git a/test/aes128cbc_decrypt_block.c b/test/aes128cbc_decrypt_block.c deleted file mode 100644 index ce05e1d..0000000 --- a/test/aes128cbc_decrypt_block.c +++ /dev/null @@ -1,63 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes128cbc_decrypt_block.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes128_Key key; - AesNI_Aes128_RoundKeys encryption_keys, decryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes128_expand_key(&key, &encryption_keys); - aesni_aes128_derive_decryption_keys(&encryption_keys, &decryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - plaintext = aesni_aes128_decrypt_block_cbc(ciphertext, &decryption_keys, iv, &iv); - aesni_aes_print_block(&plaintext, NULL); - } - } - - return 0; -} diff --git a/test/aes128cbc_encrypt_block.c b/test/aes128cbc_encrypt_block.c deleted file mode 100644 index d51a673..0000000 --- a/test/aes128cbc_encrypt_block.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes128cbc_encrypt_block.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes128_Key key; - AesNI_Aes128_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes128_expand_key(&key, &encryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - ciphertext = aesni_aes128_encrypt_block_cbc(plaintext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&ciphertext, NULL); - } - } - - return 0; -} diff --git a/test/aes128cfb_decrypt_block.c b/test/aes128cfb_decrypt_block.c deleted file mode 100644 index 636e2d9..0000000 --- a/test/aes128cfb_decrypt_block.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes128cfb_decrypt_block.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes128_Key key; - AesNI_Aes128_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes128_expand_key(&key, &encryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - plaintext = aesni_aes128_decrypt_block_cfb(ciphertext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&plaintext, NULL); - } - } - - return 0; -} diff --git a/test/aes128cfb_encrypt_block.c b/test/aes128cfb_encrypt_block.c deleted file mode 100644 index fd64dc6..0000000 --- a/test/aes128cfb_encrypt_block.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes128cfb_encrypt_block.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes128_Key key; - AesNI_Aes128_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes128_expand_key(&key, &encryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - ciphertext = aesni_aes128_encrypt_block_cfb(plaintext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&ciphertext, NULL); - } - } - - return 0; -} diff --git a/test/aes128ctr_decrypt_block.c b/test/aes128ctr_decrypt_block.c deleted file mode 100644 index 4e7e5b0..0000000 --- a/test/aes128ctr_decrypt_block.c +++ /dev/null @@ -1,64 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes128ctr_decrypt_block.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes128_Key key; - AesNI_Aes128_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes128_expand_key(&key, &encryption_keys); - - int ctr = 0; - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - plaintext = aesni_aes128_decrypt_block_ctr(ciphertext, &encryption_keys, iv, ctr++); - aesni_aes_print_block(&plaintext, NULL); - } - } - - return 0; -} diff --git a/test/aes128ctr_encrypt_block.c b/test/aes128ctr_encrypt_block.c deleted file mode 100644 index ad2e036..0000000 --- a/test/aes128ctr_encrypt_block.c +++ /dev/null @@ -1,64 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes128ctr_encrypt_block.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes128_Key key; - AesNI_Aes128_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes128_expand_key(&key, &encryption_keys); - - int ctr = 0; - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - ciphertext = aesni_aes128_encrypt_block_ctr(plaintext, &encryption_keys, iv, ctr++); - aesni_aes_print_block(&ciphertext, NULL); - } - } - - return 0; -} diff --git a/test/aes128ecb_decrypt_block.c b/test/aes128ecb_decrypt_block.c deleted file mode 100644 index d68505d..0000000 --- a/test/aes128ecb_decrypt_block.c +++ /dev/null @@ -1,57 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes128ecb_decrypt_block.exe KEY0 [CIPHER0...] [-- KEY1 [CIPHER1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext; - AesNI_Aes128_Key key; - AesNI_Aes128_RoundKeys encryption_keys, decryption_keys; - - if (argc < 1) - exit_with_usage(); - - if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - aesni_aes128_expand_key(&key, &encryption_keys); - aesni_aes128_derive_decryption_keys(&encryption_keys, &decryption_keys); - - for (--argc, ++argv; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - plaintext = aesni_aes128_decrypt_block_ecb(ciphertext, &decryption_keys); - aesni_aes_print_block(&plaintext, NULL); - } - } - - return 0; -} diff --git a/test/aes128ecb_encrypt_block.c b/test/aes128ecb_encrypt_block.c deleted file mode 100644 index 77bb557..0000000 --- a/test/aes128ecb_encrypt_block.c +++ /dev/null @@ -1,56 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes128ecb_encrypt_block.exe KEY0 [PLAIN0...] [-- KEY1 [PLAIN1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext; - AesNI_Aes128_Key key; - AesNI_Aes128_RoundKeys encryption_keys; - - if (argc < 1) - exit_with_usage(); - - if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - aesni_aes128_expand_key(&key, &encryption_keys); - - for (--argc, ++argv; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - ciphertext = aesni_aes128_encrypt_block_ecb(plaintext, &encryption_keys); - aesni_aes_print_block(&ciphertext, NULL); - } - } - - return 0; -} diff --git a/test/aes128ofb_decrypt_block.c b/test/aes128ofb_decrypt_block.c deleted file mode 100644 index 10e865e..0000000 --- a/test/aes128ofb_decrypt_block.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes128ofb_decrypt_block.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes128_Key key; - AesNI_Aes128_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes128_expand_key(&key, &encryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - plaintext = aesni_aes128_decrypt_block_ofb(ciphertext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&plaintext, NULL); - } - } - - return 0; -} diff --git a/test/aes128ofb_encrypt_block.c b/test/aes128ofb_encrypt_block.c deleted file mode 100644 index 7bf3b00..0000000 --- a/test/aes128ofb_encrypt_block.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes128ofb_encrypt_block.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes128_Key key; - AesNI_Aes128_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes128_expand_key(&key, &encryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - ciphertext = aesni_aes128_encrypt_block_ofb(plaintext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&ciphertext, NULL); - } - } - - return 0; -} diff --git a/test/aes192cbc_decrypt_block.c b/test/aes192cbc_decrypt_block.c deleted file mode 100644 index 0cbef38..0000000 --- a/test/aes192cbc_decrypt_block.c +++ /dev/null @@ -1,63 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes192cbc_decrypt_block.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes192_Key key; - AesNI_Aes192_RoundKeys encryption_keys, decryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes192_expand_key(&key, &encryption_keys); - aesni_aes192_derive_decryption_keys(&encryption_keys, &decryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - plaintext = aesni_aes192_decrypt_block_cbc(ciphertext, &decryption_keys, iv, &iv); - aesni_aes_print_block(&plaintext, NULL); - } - } - - return 0; -} diff --git a/test/aes192cbc_encrypt_block.c b/test/aes192cbc_encrypt_block.c deleted file mode 100644 index c7df499..0000000 --- a/test/aes192cbc_encrypt_block.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes192cbc_encrypt_block.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes192_Key key; - AesNI_Aes192_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes192_expand_key(&key, &encryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - ciphertext = aesni_aes192_encrypt_block_cbc(plaintext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&ciphertext, NULL); - } - } - - return 0; -} diff --git a/test/aes192cfb_decrypt_block.c b/test/aes192cfb_decrypt_block.c deleted file mode 100644 index 1ede253..0000000 --- a/test/aes192cfb_decrypt_block.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes192cfb_decrypt_block.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes192_Key key; - AesNI_Aes192_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes192_expand_key(&key, &encryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - plaintext = aesni_aes192_decrypt_block_cfb(ciphertext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&plaintext, NULL); - } - } - - return 0; -} diff --git a/test/aes192cfb_encrypt_block.c b/test/aes192cfb_encrypt_block.c deleted file mode 100644 index 7c98132..0000000 --- a/test/aes192cfb_encrypt_block.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes192cfb_encrypt_block.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes192_Key key; - AesNI_Aes192_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes192_expand_key(&key, &encryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - ciphertext = aesni_aes192_encrypt_block_cfb(plaintext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&ciphertext, NULL); - } - } - - return 0; -} diff --git a/test/aes192ctr_decrypt_block.c b/test/aes192ctr_decrypt_block.c deleted file mode 100644 index 16bd35b..0000000 --- a/test/aes192ctr_decrypt_block.c +++ /dev/null @@ -1,64 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes192ctr_decrypt_block.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes192_Key key; - AesNI_Aes192_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes192_expand_key(&key, &encryption_keys); - - int ctr = 0; - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - plaintext = aesni_aes192_decrypt_block_ctr(ciphertext, &encryption_keys, iv, ctr++); - aesni_aes_print_block(&plaintext, NULL); - } - } - - return 0; -} diff --git a/test/aes192ctr_encrypt_block.c b/test/aes192ctr_encrypt_block.c deleted file mode 100644 index d390f52..0000000 --- a/test/aes192ctr_encrypt_block.c +++ /dev/null @@ -1,64 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes192ctr_encrypt_block.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes192_Key key; - AesNI_Aes192_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes192_expand_key(&key, &encryption_keys); - - int ctr = 0; - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - ciphertext = aesni_aes192_encrypt_block_ctr(plaintext, &encryption_keys, iv, ctr++); - aesni_aes_print_block(&ciphertext, NULL); - } - } - - return 0; -} diff --git a/test/aes192ecb_decrypt_block.c b/test/aes192ecb_decrypt_block.c deleted file mode 100644 index 4200fc4..0000000 --- a/test/aes192ecb_decrypt_block.c +++ /dev/null @@ -1,57 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes192ecb_decrypt_block.exe KEY0 [CIPHER0...] [-- KEY1 [CIPHER1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext; - AesNI_Aes192_Key key; - AesNI_Aes192_RoundKeys encryption_keys, decryption_keys; - - if (argc < 1) - exit_with_usage(); - - if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - aesni_aes192_expand_key(&key, &encryption_keys); - aesni_aes192_derive_decryption_keys(&encryption_keys, &decryption_keys); - - for (--argc, ++argv; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - plaintext = aesni_aes192_decrypt_block_ecb(ciphertext, &decryption_keys); - aesni_aes_print_block(&plaintext, NULL); - } - } - - return 0; -} diff --git a/test/aes192ecb_encrypt_block.c b/test/aes192ecb_encrypt_block.c deleted file mode 100644 index 2b140e3..0000000 --- a/test/aes192ecb_encrypt_block.c +++ /dev/null @@ -1,56 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes192ecb_encrypt_block.exe KEY0 [PLAIN0...] [-- KEY1 [PLAIN1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext; - AesNI_Aes192_Key key; - AesNI_Aes192_RoundKeys encryption_keys; - - if (argc < 1) - exit_with_usage(); - - if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - aesni_aes192_expand_key(&key, &encryption_keys); - - for (--argc, ++argv; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - ciphertext = aesni_aes192_encrypt_block_ecb(plaintext, &encryption_keys); - aesni_aes_print_block(&ciphertext, NULL); - } - } - - return 0; -} diff --git a/test/aes192ofb_decrypt_block.c b/test/aes192ofb_decrypt_block.c deleted file mode 100644 index 5d791ac..0000000 --- a/test/aes192ofb_decrypt_block.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes192ofb_decrypt_block.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes192_Key key; - AesNI_Aes192_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes192_expand_key(&key, &encryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - plaintext = aesni_aes192_decrypt_block_ofb(ciphertext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&plaintext, NULL); - } - } - - return 0; -} diff --git a/test/aes192ofb_encrypt_block.c b/test/aes192ofb_encrypt_block.c deleted file mode 100644 index cb2ab85..0000000 --- a/test/aes192ofb_encrypt_block.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes192ofb_encrypt_block.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes192_Key key; - AesNI_Aes192_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes192_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes192_expand_key(&key, &encryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - ciphertext = aesni_aes192_encrypt_block_ofb(plaintext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&ciphertext, NULL); - } - } - - return 0; -} diff --git a/test/aes256cbc_decrypt_block.c b/test/aes256cbc_decrypt_block.c deleted file mode 100644 index db66bef..0000000 --- a/test/aes256cbc_decrypt_block.c +++ /dev/null @@ -1,63 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes256cbc_decrypt_block.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes256_Key key; - AesNI_Aes256_RoundKeys encryption_keys, decryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes256_expand_key(&key, &encryption_keys); - aesni_aes256_derive_decryption_keys(&encryption_keys, &decryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - plaintext = aesni_aes256_decrypt_block_cbc(ciphertext, &decryption_keys, iv, &iv); - aesni_aes_print_block(&plaintext, NULL); - } - } - - return 0; -} diff --git a/test/aes256cbc_encrypt_block.c b/test/aes256cbc_encrypt_block.c deleted file mode 100644 index 69426a4..0000000 --- a/test/aes256cbc_encrypt_block.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes256cbc_encrypt_block.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes256_Key key; - AesNI_Aes256_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes256_expand_key(&key, &encryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - ciphertext = aesni_aes256_encrypt_block_cbc(plaintext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&ciphertext, NULL); - } - } - - return 0; -} diff --git a/test/aes256cfb_decrypt_block.c b/test/aes256cfb_decrypt_block.c deleted file mode 100644 index b4a0728..0000000 --- a/test/aes256cfb_decrypt_block.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes256cfb_decrypt_block.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes256_Key key; - AesNI_Aes256_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes256_expand_key(&key, &encryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - plaintext = aesni_aes256_decrypt_block_cfb(ciphertext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&plaintext, NULL); - } - } - - return 0; -} diff --git a/test/aes256cfb_encrypt_block.c b/test/aes256cfb_encrypt_block.c deleted file mode 100644 index ab0090f..0000000 --- a/test/aes256cfb_encrypt_block.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes256cfb_encrypt_block.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes256_Key key; - AesNI_Aes256_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes256_expand_key(&key, &encryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - ciphertext = aesni_aes256_encrypt_block_cfb(plaintext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&ciphertext, NULL); - } - } - - return 0; -} diff --git a/test/aes256ctr_decrypt_block.c b/test/aes256ctr_decrypt_block.c deleted file mode 100644 index 9ba7365..0000000 --- a/test/aes256ctr_decrypt_block.c +++ /dev/null @@ -1,64 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes256ctr_decrypt_block.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes256_Key key; - AesNI_Aes256_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes256_expand_key(&key, &encryption_keys); - - int ctr = 0; - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - plaintext = aesni_aes256_decrypt_block_ctr(ciphertext, &encryption_keys, iv, ctr++); - aesni_aes_print_block(&plaintext, NULL); - } - } - - return 0; -} diff --git a/test/aes256ctr_encrypt_block.c b/test/aes256ctr_encrypt_block.c deleted file mode 100644 index 344decc..0000000 --- a/test/aes256ctr_encrypt_block.c +++ /dev/null @@ -1,64 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes256ctr_encrypt_block.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes256_Key key; - AesNI_Aes256_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes256_expand_key(&key, &encryption_keys); - - int ctr = 0; - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - ciphertext = aesni_aes256_encrypt_block_ctr(plaintext, &encryption_keys, iv, ctr++); - aesni_aes_print_block(&ciphertext, NULL); - } - } - - return 0; -} diff --git a/test/aes256ecb_decrypt_block.c b/test/aes256ecb_decrypt_block.c deleted file mode 100644 index 25aa20e..0000000 --- a/test/aes256ecb_decrypt_block.c +++ /dev/null @@ -1,57 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes256ecb_decrypt_block.exe KEY0 [CIPHER0...] [-- KEY1 [CIPHER1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext; - AesNI_Aes256_Key key; - AesNI_Aes256_RoundKeys encryption_keys, decryption_keys; - - if (argc < 1) - exit_with_usage(); - - if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - aesni_aes256_expand_key(&key, &encryption_keys); - aesni_aes256_derive_decryption_keys(&encryption_keys, &decryption_keys); - - for (--argc, ++argv; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - plaintext = aesni_aes256_decrypt_block_ecb(ciphertext, &decryption_keys); - aesni_aes_print_block(&plaintext, NULL); - } - } - - return 0; -} diff --git a/test/aes256ecb_encrypt_block.c b/test/aes256ecb_encrypt_block.c deleted file mode 100644 index b83ff39..0000000 --- a/test/aes256ecb_encrypt_block.c +++ /dev/null @@ -1,56 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes256ecb_encrypt_block.exe KEY0 [PLAIN0...] [-- KEY1 [PLAIN1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext; - AesNI_Aes256_Key key; - AesNI_Aes256_RoundKeys encryption_keys; - - if (argc < 1) - exit_with_usage(); - - if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - aesni_aes256_expand_key(&key, &encryption_keys); - - for (--argc, ++argv; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - ciphertext = aesni_aes256_encrypt_block_ecb(plaintext, &encryption_keys); - aesni_aes_print_block(&ciphertext, NULL); - } - } - - return 0; -} diff --git a/test/aes256ofb_decrypt_block.c b/test/aes256ofb_decrypt_block.c deleted file mode 100644 index 02d7532..0000000 --- a/test/aes256ofb_decrypt_block.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes256ofb_decrypt_block.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes256_Key key; - AesNI_Aes256_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes256_expand_key(&key, &encryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&ciphertext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - plaintext = aesni_aes256_decrypt_block_ofb(ciphertext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&plaintext, NULL); - } - } - - return 0; -} diff --git a/test/aes256ofb_encrypt_block.c b/test/aes256ofb_encrypt_block.c deleted file mode 100644 index a8434c8..0000000 --- a/test/aes256ofb_encrypt_block.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include - -#include -#include -#include - -static void exit_with_usage() -{ - puts("Usage: aes256ofb_encrypt_block.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]"); - exit(EXIT_FAILURE); -} - -int main(int argc, char** argv) -{ - for (--argc, ++argv; argc > -1; --argc, ++argv) - { - AesNI_Block128 plaintext, ciphertext, iv; - AesNI_Aes256_Key key; - AesNI_Aes256_RoundKeys encryption_keys; - - if (argc < 2) - exit_with_usage(); - - if (aesni_is_error(aesni_aes256_parse_key(&key, *argv, NULL))) - { - fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); - exit_with_usage(); - } - - if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); - exit_with_usage(); - } - - aesni_aes256_expand_key(&key, &encryption_keys); - - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) - { - if (strcmp("--", *argv) == 0) - break; - - if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL))) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); - continue; - } - ciphertext = aesni_aes256_encrypt_block_ofb(plaintext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&ciphertext, NULL); - } - } - - return 0; -} diff --git a/test/common_aes.hpp b/test/common_aes.hpp new file mode 100644 index 0000000..d34d72f --- /dev/null +++ b/test/common_aes.hpp @@ -0,0 +1,134 @@ +/** + * \file + * \author Egor Tensin + * \date 2015 + * \copyright This file is licensed under the terms of the MIT License. + * See LICENSE.txt for details. + */ + +#pragma once + +#include + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +static std::istream& operator>>(std::istream& is, AesNI_BoxMode& dest) +{ + std::string src; + is >> src; + + if (boost::iequals(src, "ecb")) + dest = AESNI_ECB; + else if (boost::iequals(src, "cbc")) + dest = AESNI_CBC; + else if (boost::iequals(src, "cfb")) + dest = AESNI_CFB; + else if (boost::iequals(src, "ofb")) + dest = AESNI_OFB; + else if (boost::iequals(src, "ctr")) + dest = AESNI_CTR; + else + throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value, "mode", src); + + return is; +} + +static std::istream& operator>>(std::istream& is, AesNI_BoxAlgorithm& dest) +{ + std::string src; + is >> src; + + if (boost::iequals(src, "aes128")) + dest = AESNI_AES128; + else if (boost::iequals(src, "aes192")) + dest = AESNI_AES192; + else if (boost::iequals(src, "aes256")) + dest = AESNI_AES256; + else + throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value, "algorithm", src); + + return is; +} + +namespace +{ + class CommandLineParser + { + public: + CommandLineParser(const std::string& program_name) + : m_program_name(program_name) + , m_options("Options") + { } + + bool parse_options(int argc, char** argv) + { + namespace po = boost::program_options; + + m_options.add_options() + ("help,h", "show this message and exit") + ("mode,m", po::value(&m_mode)->required(), "set mode of operation") + ("algorithm,a", po::value(&m_algorithm)->required(), "set algorithm"); + + po::options_description hidden_options; + hidden_options.add_options() + ("positional", po::value>(&m_args)); + + po::options_description all_options; + all_options.add(m_options).add(hidden_options); + + po::positional_options_description positional_options; + positional_options.add("positional", -1); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv).options(all_options).positional(positional_options).run(), vm); + + if (vm.count("help")) + { + print_usage(); + return false; + } + + po::notify(vm); + return true; + } + + void print_usage() + { + std::cout << "CommandLineParser: " << m_program_name << " [OPTIONS...] [-- KEY [IV] [PLAINTEXT...]...]\n"; + std::cout << m_options << "\n"; + } + + AesNI_BoxMode get_mode() const + { + return m_mode; + } + + AesNI_BoxAlgorithm get_algorithm() const + { + return m_algorithm; + } + + std::deque get_args() + { + return { std::make_move_iterator(m_args.begin()), std::make_move_iterator(m_args.end()) }; + } + + private: + const std::string m_program_name; + boost::program_options::options_description m_options; + + AesNI_BoxMode m_mode; + AesNI_BoxAlgorithm m_algorithm; + std::vector m_args; + }; +} diff --git a/test/decrypt_block_aes.cpp b/test/decrypt_block_aes.cpp index e0c289a..ff2d494 100644 --- a/test/decrypt_block_aes.cpp +++ b/test/decrypt_block_aes.cpp @@ -6,56 +6,90 @@ * See LICENSE.txt for details. */ +#include "common_aes.hpp" + #include #include -#include -#include - #include #include -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(); + CommandLineParser cmd_parser("encrypt_block_aes.exe"); + if (!cmd_parser.parse_options(argc, argv)) + return 0; + + auto args = cmd_parser.get_args(); + + while (!args.empty()) + { AesNI_BoxAlgorithmParams algorithm_params; - aesni::aes::from_string(algorithm_params.aes128_key, argv[0]); + + switch (cmd_parser.get_algorithm()) + { + case AESNI_AES128: + aesni::aes::from_string(algorithm_params.aes128_key, args.front()); + break; + + case AESNI_AES192: + aesni::aes::from_string(algorithm_params.aes192_key, args.front()); + break; + + case AESNI_AES256: + aesni::aes::from_string(algorithm_params.aes256_key, args.front()); + break; + } + + args.pop_front(); AesNI_BoxBlock iv; - aesni::aes::from_string(iv.aes_block, argv[1]); + AesNI_BoxBlock* iv_ptr = nullptr; + + switch (cmd_parser.get_mode()) + { + case AESNI_ECB: + break; + + case AESNI_CBC: + case AESNI_CFB: + case AESNI_OFB: + case AESNI_CTR: + if (args.empty()) + { + cmd_parser.print_usage(); + return 1; + } + aesni::aes::from_string(iv.aes_block, args.front()); + iv_ptr = &iv; + args.pop_front(); + break; + } AesNI_Box box; aesni_box_init( &box, - AESNI_AES128, + cmd_parser.get_algorithm(), &algorithm_params, - AESNI_OFB, - &iv, + cmd_parser.get_mode(), + iv_ptr, aesni::ErrorDetailsThrowsInDestructor()); - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) + while (!args.empty()) { - if (std::strcmp("--", argv[0]) == 0) + if (args.front() == "--") + { + args.pop_front(); break; + } AesNI_BoxBlock ciphertext; - aesni::aes::from_string(ciphertext.aes_block, argv[0]); + aesni::aes::from_string(ciphertext.aes_block, args.front()); + args.pop_front(); AesNI_BoxBlock plaintext; aesni_box_decrypt( @@ -70,6 +104,11 @@ int main(int argc, char** argv) return 0; } + catch (const boost::program_options::error& e) + { + std::cerr << "Usage error: " << e.what() << "\n"; + return 1; + } catch (const std::exception& e) { std::cerr << e.what() << "\n"; diff --git a/test/encrypt_block_aes.cpp b/test/encrypt_block_aes.cpp index 8be1fef..fc56019 100644 --- a/test/encrypt_block_aes.cpp +++ b/test/encrypt_block_aes.cpp @@ -6,56 +6,90 @@ * See LICENSE.txt for details. */ +#include "common_aes.hpp" + #include #include -#include -#include - #include #include -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(); + CommandLineParser cmd_parser("encrypt_block_aes.exe"); + if (!cmd_parser.parse_options(argc, argv)) + return 0; + + auto args = cmd_parser.get_args(); + + while (!args.empty()) + { AesNI_BoxAlgorithmParams algorithm_params; - aesni::aes::from_string(algorithm_params.aes128_key, argv[0]); + + switch (cmd_parser.get_algorithm()) + { + case AESNI_AES128: + aesni::aes::from_string(algorithm_params.aes128_key, args.front()); + break; + + case AESNI_AES192: + aesni::aes::from_string(algorithm_params.aes192_key, args.front()); + break; + + case AESNI_AES256: + aesni::aes::from_string(algorithm_params.aes256_key, args.front()); + break; + } + + args.pop_front(); AesNI_BoxBlock iv; - aesni::aes::from_string(iv.aes_block, argv[1]); + AesNI_BoxBlock* iv_ptr = nullptr; + + switch (cmd_parser.get_mode()) + { + case AESNI_ECB: + break; + + case AESNI_CBC: + case AESNI_CFB: + case AESNI_OFB: + case AESNI_CTR: + if (args.empty()) + { + cmd_parser.print_usage(); + return 1; + } + aesni::aes::from_string(iv.aes_block, args.front()); + iv_ptr = &iv; + args.pop_front(); + break; + } AesNI_Box box; aesni_box_init( &box, - AESNI_AES128, + cmd_parser.get_algorithm(), &algorithm_params, - AESNI_OFB, - &iv, + cmd_parser.get_mode(), + iv_ptr, aesni::ErrorDetailsThrowsInDestructor()); - for (argc -= 2, argv += 2; argc > 0; --argc, ++argv) + while (!args.empty()) { - if (std::strcmp("--", argv[0]) == 0) + if (args.front() == "--") + { + args.pop_front(); break; + } AesNI_BoxBlock plaintext; - aesni::aes::from_string(plaintext.aes_block, argv[0]); + aesni::aes::from_string(plaintext.aes_block, args.front()); + args.pop_front(); AesNI_BoxBlock ciphertext; aesni_box_encrypt( @@ -70,6 +104,11 @@ int main(int argc, char** argv) return 0; } + catch (const boost::program_options::error& e) + { + std::cerr << "Usage error: " << e.what() << "\n"; + return 1; + } catch (const std::exception& e) { std::cerr << e.what() << "\n"; diff --git a/test/toolkit.py b/test/toolkit.py index 75a0b1f..f2c0a3e 100644 --- a/test/toolkit.py +++ b/test/toolkit.py @@ -75,14 +75,15 @@ class Tools: def _get_tool_path(self, fn): return os.path.join(self._root_dir_path, fn) - def get_encrypt_tool_path(self, algo, mode): - return self._get_tool_path('{0}{1}_encrypt_block.exe'.format(algo, mode)) + def get_encrypt_tool_path(self): + return self._get_tool_path('encrypt_block_aes.exe') - def get_decrypt_tool_path(self, algo, mode): - return self._get_tool_path('{0}{1}_decrypt_block.exe'.format(algo, mode)) + def get_decrypt_tool_path(self): + return self._get_tool_path('decrypt_block_aes.exe') - def run_tool(self, tool_path, args): + def run_tool(self, tool_path, algo, mode, args): cmd_list = ['sde', '--', tool_path] if self._use_sde else [tool_path] + cmd_list.extend(('-a', algo, '-m', mode, '--')) cmd_list.extend(args) logging.info('Trying to execute: {0}'.format(subprocess.list2cmdline(cmd_list))) try: @@ -112,11 +113,11 @@ class Tools: args = self._inputs_to_args(iter(inputs)) else: args = inputs.to_args() - return self.run_tool(self.get_encrypt_tool_path(algo, mode), args) + return self.run_tool(self.get_encrypt_tool_path(), algo, mode, args) def run_decrypt_tool(self, algo, mode, inputs): if isinstance(inputs, collections.Iterable): args = self._inputs_to_args(iter(inputs)) else: args = inputs.to_args() - return self.run_tool(self.get_decrypt_tool_path(algo, mode), args) + return self.run_tool(self.get_decrypt_tool_path(), algo, mode, args) -- cgit v1.2.3