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/aes192cbc_encrypt.c | 57 +++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'test/aes192cbc_encrypt.c') diff --git a/test/aes192cbc_encrypt.c b/test/aes192cbc_encrypt.c index b6431d0..7eadb6c 100644 --- a/test/aes192cbc_encrypt.c +++ b/test/aes192cbc_encrypt.c @@ -10,45 +10,52 @@ #include #include +#include -static void exit_with_usage(const char* argv0) +static void exit_with_usage() { - printf("Usage: %s KEY INIT_VECTOR [PLAIN...]\n", argv0); + puts("Usage: aes192cbc_encrypt.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]"); exit(EXIT_FAILURE); } int main(int argc, char** argv) { - AesBlock128 plain, cipher, iv; - AesBlock192 key; - Aes192KeySchedule key_schedule; + for (--argc, ++argv; argc > -1; --argc, ++argv) + { + AesBlock128 plain, cipher, iv; + AesBlock192 key; + Aes192KeySchedule key_schedule; - if (argc < 3) - exit_with_usage(argv[0]); + if (argc < 2) + exit_with_usage(); - if (parse_aes_block192(&key, argv[1]) != 0) - { - fprintf(stderr, "Invalid 192-bit AES block '%s'\n", argv[1]); - exit_with_usage(argv[0]); - } + if (parse_aes_block192(&key, *argv) != 0) + { + fprintf(stderr, "Invalid 192-bit AES block '%s'\n", *argv); + exit_with_usage(); + } - if (parse_aes_block128(&iv, argv[2]) != 0) - { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[2]); - exit_with_usage(argv[0]); - } + if (parse_aes_block128(&iv, argv[1]) != 0) + { + fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]); + exit_with_usage(); + } - aes192_expand_key_schedule(&key, &key_schedule); + aes192_expand_key_schedule(&key, &key_schedule); - for (int i = 3; i < argc; ++i) - { - if (parse_aes_block128(&plain, argv[i]) != 0) + for (argc -= 2, argv += 2; 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(&plain, *argv) != 0) + { + fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); + continue; + } + cipher = aes192cbc_encrypt(plain, &key_schedule, iv, &iv); + print_aes_block128(&cipher); } - cipher = aes192cbc_encrypt(plain, &key_schedule, iv, &iv); - print_aes_block128(&cipher); } return 0; -- cgit v1.2.3