From 8fdfe033a9cb297b80877894e9d3b148fc99d935 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 6 Jun 2015 02:26:05 +0300 Subject: test: enable the utilities to accept many keys --- test/aes256ecb_decrypt.c | 49 +++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) (limited to 'test/aes256ecb_decrypt.c') diff --git a/test/aes256ecb_decrypt.c b/test/aes256ecb_decrypt.c index 82bf353..c4ae001 100644 --- a/test/aes256ecb_decrypt.c +++ b/test/aes256ecb_decrypt.c @@ -10,40 +10,47 @@ #include #include +#include -static void exit_with_usage(const char* argv0) +static void exit_with_usage() { - printf("Usage: %s KEY [CIPHER...]\n", argv0); + puts("Usage: aes256ecb_decrypt.exe KEY0 [CIPHER0...] [-- KEY1 [CIPHER1...]...]"); exit(EXIT_FAILURE); } int main(int argc, char** argv) { - AesBlock128 plain, cipher; - AesBlock256 key; - Aes256KeySchedule key_schedule, inverted_schedule; + for (--argc, ++argv; argc > -1; --argc, ++argv) + { + AesBlock128 plain, cipher; + AesBlock256 key; + Aes256KeySchedule key_schedule, inverted_schedule; - if (argc < 2) - exit_with_usage(argv[0]); + if (argc < 1) + exit_with_usage(); - if (parse_aes_block256(&key, argv[1]) != 0) - { - fprintf(stderr, "Invalid 256-bit AES block '%s'\n", argv[1]); - exit_with_usage(argv[0]); - } + if (parse_aes_block256(&key, *argv) != 0) + { + fprintf(stderr, "Invalid 256-bit AES block '%s'\n", *argv); + exit_with_usage(); + } - aes256_expand_key_schedule(&key, &key_schedule); - aes256_invert_key_schedule(&key_schedule, &inverted_schedule); + aes256_expand_key_schedule(&key, &key_schedule); + aes256_invert_key_schedule(&key_schedule, &inverted_schedule); - for (int i = 2; i < argc; ++i) - { - if (parse_aes_block128(&cipher, argv[i]) != 0) + for (--argc, ++argv; argc > 0; --argc, ++argv) { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[i]); - continue; + if (strcmp("--", *argv) == 0) + break; + + if (parse_aes_block128(&cipher, *argv) != 0) + { + fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); + continue; + } + plain = aes256ecb_decrypt(cipher, &inverted_schedule); + print_aes_block128(&plain); } - plain = aes256ecb_decrypt(cipher, &inverted_schedule); - print_aes_block128(&plain); } return 0; -- cgit v1.2.3