diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-06 02:26:05 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-06 02:26:05 +0300 |
commit | 8fdfe033a9cb297b80877894e9d3b148fc99d935 (patch) | |
tree | d0ef1b874c0fa98b91aa1d93778dd90ff1b30ccb /test/aes256ecb_encrypt.c | |
parent | ditche _mm_store_* in favor of simple assignments (diff) | |
download | aes-tools-8fdfe033a9cb297b80877894e9d3b148fc99d935.tar.gz aes-tools-8fdfe033a9cb297b80877894e9d3b148fc99d935.zip |
test: enable the utilities to accept many keys
Diffstat (limited to '')
-rw-r--r-- | test/aes256ecb_encrypt.c | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/test/aes256ecb_encrypt.c b/test/aes256ecb_encrypt.c index 3a60bed..7553362 100644 --- a/test/aes256ecb_encrypt.c +++ b/test/aes256ecb_encrypt.c @@ -10,39 +10,46 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> -static void exit_with_usage(const char* argv0) +static void exit_with_usage() { - printf("Usage: %s KEY [PLAIN...]\n", argv0); + puts("Usage: aes256ecb_encrypt.exe KEY0 [PLAIN0...] [-- KEY1 [PLAIN1...]...]"); exit(EXIT_FAILURE); } int main(int argc, char** argv) { - AesBlock128 plain, cipher; - AesBlock256 key; - Aes256KeySchedule key_schedule; + for (--argc, ++argv; argc > -1; --argc, ++argv) + { + AesBlock128 plain, cipher; + AesBlock256 key; + Aes256KeySchedule key_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_expand_key_schedule(&key, &key_schedule); - for (int i = 2; i < argc; ++i) - { - if (parse_aes_block128(&plain, 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(&plain, *argv) != 0) + { + fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); + continue; + } + cipher = aes256ecb_encrypt(plain, &key_schedule); + print_aes_block128(&cipher); } - cipher = aes256ecb_encrypt(plain, &key_schedule); - print_aes_block128(&cipher); } return 0; |