aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/aes192ctr_decrypt.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2015-06-06 02:26:05 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2015-06-06 02:26:05 +0300
commit8fdfe033a9cb297b80877894e9d3b148fc99d935 (patch)
treed0ef1b874c0fa98b91aa1d93778dd90ff1b30ccb /test/aes192ctr_decrypt.c
parentditche _mm_store_* in favor of simple assignments (diff)
downloadaes-tools-8fdfe033a9cb297b80877894e9d3b148fc99d935.tar.gz
aes-tools-8fdfe033a9cb297b80877894e9d3b148fc99d935.zip
test: enable the utilities to accept many keys
Diffstat (limited to 'test/aes192ctr_decrypt.c')
-rw-r--r--test/aes192ctr_decrypt.c59
1 files changed, 34 insertions, 25 deletions
diff --git a/test/aes192ctr_decrypt.c b/test/aes192ctr_decrypt.c
index 5d91b3a..e456fff 100644
--- a/test/aes192ctr_decrypt.c
+++ b/test/aes192ctr_decrypt.c
@@ -10,45 +10,54 @@
#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 INIT_VECTOR [CIPHER...]\n", argv0);
+ puts("Usage: aes192ctr_decrypt.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]");
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(&cipher, argv[i]) != 0)
+ int ctr = 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(&cipher, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv);
+ continue;
+ }
+ plain = aes192ctr_decrypt(cipher, &key_schedule, iv, ctr++);
+ print_aes_block128(&plain);
}
- plain = aes192ctr_decrypt(cipher, &key_schedule, iv, i - 3);
- print_aes_block128(&plain);
}
return 0;