aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test
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
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 '')
-rw-r--r--test/aes128cbc_decrypt.c57
-rw-r--r--test/aes128cbc_encrypt.c55
-rw-r--r--test/aes128cfb_decrypt.c55
-rw-r--r--test/aes128cfb_encrypt.c55
-rw-r--r--test/aes128ctr_decrypt.c57
-rw-r--r--test/aes128ctr_encrypt.c57
-rw-r--r--test/aes128ecb_decrypt.c47
-rw-r--r--test/aes128ecb_encrypt.c45
-rw-r--r--test/aes128ofb_decrypt.c55
-rw-r--r--test/aes128ofb_encrypt.c55
-rw-r--r--test/aes192cbc_decrypt.c59
-rw-r--r--test/aes192cbc_encrypt.c57
-rw-r--r--test/aes192cfb_decrypt.c57
-rw-r--r--test/aes192cfb_encrypt.c57
-rw-r--r--test/aes192ctr_decrypt.c59
-rw-r--r--test/aes192ctr_encrypt.c59
-rw-r--r--test/aes192ecb_decrypt.c49
-rw-r--r--test/aes192ecb_encrypt.c47
-rw-r--r--test/aes192ofb_decrypt.c57
-rw-r--r--test/aes192ofb_encrypt.c57
-rw-r--r--test/aes256cbc_decrypt.c59
-rw-r--r--test/aes256cbc_encrypt.c57
-rw-r--r--test/aes256cfb_decrypt.c57
-rw-r--r--test/aes256cfb_encrypt.c57
-rw-r--r--test/aes256ctr_decrypt.c59
-rw-r--r--test/aes256ctr_encrypt.c59
-rw-r--r--test/aes256ecb_decrypt.c49
-rw-r--r--test/aes256ecb_encrypt.c47
-rw-r--r--test/aes256ofb_decrypt.c57
-rw-r--r--test/aes256ofb_encrypt.c57
30 files changed, 938 insertions, 716 deletions
diff --git a/test/aes128cbc_decrypt.c b/test/aes128cbc_decrypt.c
index f5f2c35..a97d00b 100644
--- a/test/aes128cbc_decrypt.c
+++ b/test/aes128cbc_decrypt.c
@@ -10,45 +10,52 @@
#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: aes128cbc_decrypt.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, key, cipher, iv;
- Aes128KeySchedule key_schedule, inverted_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, key, cipher, iv;
+ Aes128KeySchedule key_schedule, inverted_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ exit_with_usage();
- if (parse_aes_block128(&key, argv[1]) != 0)
- {
- fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]);
- exit_with_usage(argv[0]);
- }
+ if (parse_aes_block128(&key, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-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();
+ }
- aes128_expand_key_schedule(key, &key_schedule);
- aes128_invert_key_schedule(&key_schedule, &inverted_schedule);
+ aes128_expand_key_schedule(key, &key_schedule);
+ aes128_invert_key_schedule(&key_schedule, &inverted_schedule);
- for (int i = 3; i < argc; ++i)
- {
- if (parse_aes_block128(&cipher, 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(&cipher, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv);
+ continue;
+ }
+ plain = aes128cbc_decrypt(cipher, &inverted_schedule, iv, &iv);
+ print_aes_block128(&plain);
}
- plain = aes128cbc_decrypt(cipher, &inverted_schedule, iv, &iv);
- print_aes_block128(&plain);
}
return 0;
diff --git a/test/aes128cbc_encrypt.c b/test/aes128cbc_encrypt.c
index 25bf79a..223ebdb 100644
--- a/test/aes128cbc_encrypt.c
+++ b/test/aes128cbc_encrypt.c
@@ -10,44 +10,51 @@
#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 [PLAIN...]\n", argv0);
+ puts("Usage: aes128cbc_encrypt.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, key, cipher, iv;
- Aes128KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, key, cipher, iv;
+ Aes128KeySchedule key_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ exit_with_usage();
- if (parse_aes_block128(&key, argv[1]) != 0)
- {
- fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]);
- exit_with_usage(argv[0]);
- }
+ if (parse_aes_block128(&key, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-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();
+ }
- aes128_expand_key_schedule(key, &key_schedule);
+ aes128_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 = aes128cbc_encrypt(plain, &key_schedule, iv, &iv);
+ print_aes_block128(&cipher);
}
- cipher = aes128cbc_encrypt(plain, &key_schedule, iv, &iv);
- print_aes_block128(&cipher);
}
return 0;
diff --git a/test/aes128cfb_decrypt.c b/test/aes128cfb_decrypt.c
index 265a78a..34ac44f 100644
--- a/test/aes128cfb_decrypt.c
+++ b/test/aes128cfb_decrypt.c
@@ -10,44 +10,51 @@
#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: aes128cfb_decrypt.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, key, cipher, iv;
- Aes128KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, key, cipher, iv;
+ Aes128KeySchedule key_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ exit_with_usage();
- if (parse_aes_block128(&key, argv[1]) != 0)
- {
- fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]);
- exit_with_usage(argv[0]);
- }
+ if (parse_aes_block128(&key, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-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();
+ }
- aes128_expand_key_schedule(key, &key_schedule);
+ aes128_expand_key_schedule(key, &key_schedule);
- for (int i = 3; i < argc; ++i)
- {
- if (parse_aes_block128(&cipher, 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(&cipher, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv);
+ continue;
+ }
+ plain = aes128cfb_decrypt(cipher, &key_schedule, iv, &iv);
+ print_aes_block128(&plain);
}
- plain = aes128cfb_decrypt(cipher, &key_schedule, iv, &iv);
- print_aes_block128(&plain);
}
return 0;
diff --git a/test/aes128cfb_encrypt.c b/test/aes128cfb_encrypt.c
index 75a726c..a566922 100644
--- a/test/aes128cfb_encrypt.c
+++ b/test/aes128cfb_encrypt.c
@@ -10,44 +10,51 @@
#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 [PLAIN...]\n", argv0);
+ puts("Usage: aes128cfb_encrypt.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, key, cipher, iv;
- Aes128KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, key, cipher, iv;
+ Aes128KeySchedule key_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ exit_with_usage();
- if (parse_aes_block128(&key, argv[1]) != 0)
- {
- fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]);
- exit_with_usage(argv[0]);
- }
+ if (parse_aes_block128(&key, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-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();
+ }
- aes128_expand_key_schedule(key, &key_schedule);
+ aes128_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 = aes128cfb_encrypt(plain, &key_schedule, iv, &iv);
+ print_aes_block128(&cipher);
}
- cipher = aes128cfb_encrypt(plain, &key_schedule, iv, &iv);
- print_aes_block128(&cipher);
}
return 0;
diff --git a/test/aes128ctr_decrypt.c b/test/aes128ctr_decrypt.c
index 9421e1e..1cd8c92 100644
--- a/test/aes128ctr_decrypt.c
+++ b/test/aes128ctr_decrypt.c
@@ -10,44 +10,53 @@
#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: aes128ctr_decrypt.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, key, cipher, iv;
- Aes128KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, key, cipher, iv;
+ Aes128KeySchedule key_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ exit_with_usage();
- if (parse_aes_block128(&key, argv[1]) != 0)
- {
- fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]);
- exit_with_usage(argv[0]);
- }
+ if (parse_aes_block128(&key, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-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();
+ }
- aes128_expand_key_schedule(key, &key_schedule);
+ aes128_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 = aes128ctr_decrypt(cipher, &key_schedule, iv, ctr++);
+ print_aes_block128(&plain);
}
- plain = aes128ctr_decrypt(cipher, &key_schedule, iv, i - 3);
- print_aes_block128(&plain);
}
return 0;
diff --git a/test/aes128ctr_encrypt.c b/test/aes128ctr_encrypt.c
index a0b73eb..16b4403 100644
--- a/test/aes128ctr_encrypt.c
+++ b/test/aes128ctr_encrypt.c
@@ -10,44 +10,53 @@
#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 [PLAIN...]\n", argv0);
+ puts("Usage: aes128ctr_encrypt.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, key, cipher, iv;
- Aes128KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, key, cipher, iv;
+ Aes128KeySchedule key_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ exit_with_usage();
- if (parse_aes_block128(&key, argv[1]) != 0)
- {
- fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]);
- exit_with_usage(argv[0]);
- }
+ if (parse_aes_block128(&key, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-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();
+ }
- aes128_expand_key_schedule(key, &key_schedule);
+ aes128_expand_key_schedule(key, &key_schedule);
- for (int i = 3; i < argc; ++i)
- {
- if (parse_aes_block128(&plain, 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(&plain, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv);
+ continue;
+ }
+ cipher = aes128ctr_encrypt(plain, &key_schedule, iv, ctr++);
+ print_aes_block128(&cipher);
}
- cipher = aes128ctr_encrypt(plain, &key_schedule, iv, i - 3);
- print_aes_block128(&cipher);
}
return 0;
diff --git a/test/aes128ecb_decrypt.c b/test/aes128ecb_decrypt.c
index 65ab3db..ce40314 100644
--- a/test/aes128ecb_decrypt.c
+++ b/test/aes128ecb_decrypt.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 [CIPHER...]\n", argv0);
+ puts("Usage: aes128ecb_decrypt.exe KEY0 [CIPHER0...] [-- KEY1 [CIPHER1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, key, cipher;
- Aes128KeySchedule key_schedule, inverted_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, key, cipher;
+ Aes128KeySchedule key_schedule, inverted_schedule;
- if (argc < 2)
- exit_with_usage(argv[0]);
+ if (argc < 1)
+ exit_with_usage();
- if (parse_aes_block128(&key, argv[1]) != 0)
- {
- fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]);
- exit_with_usage(argv[0]);
- }
+ if (parse_aes_block128(&key, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv);
+ exit_with_usage();
+ }
- aes128_expand_key_schedule(key, &key_schedule);
- aes128_invert_key_schedule(&key_schedule, &inverted_schedule);
+ aes128_expand_key_schedule(key, &key_schedule);
+ aes128_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 = aes128ecb_decrypt(cipher, &inverted_schedule);
+ print_aes_block128(&plain);
}
- plain = aes128ecb_decrypt(cipher, &inverted_schedule);
- print_aes_block128(&plain);
}
return 0;
diff --git a/test/aes128ecb_encrypt.c b/test/aes128ecb_encrypt.c
index b06f60b..6fde333 100644
--- a/test/aes128ecb_encrypt.c
+++ b/test/aes128ecb_encrypt.c
@@ -10,38 +10,45 @@
#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: aes128ecb_encrypt.exe KEY0 [PLAIN0...] [-- KEY1 [PLAIN1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, key, cipher;
- Aes128KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, key, cipher;
+ Aes128KeySchedule key_schedule;
- if (argc < 2)
- exit_with_usage(argv[0]);
+ if (argc < 1)
+ exit_with_usage();
- if (parse_aes_block128(&key, argv[1]) != 0)
- {
- fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]);
- exit_with_usage(argv[0]);
- }
+ if (parse_aes_block128(&key, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv);
+ exit_with_usage();
+ }
- aes128_expand_key_schedule(key, &key_schedule);
+ aes128_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 = aes128ecb_encrypt(plain, &key_schedule);
+ print_aes_block128(&cipher);
}
- cipher = aes128ecb_encrypt(plain, &key_schedule);
- print_aes_block128(&cipher);
}
return 0;
diff --git a/test/aes128ofb_decrypt.c b/test/aes128ofb_decrypt.c
index fb3d83b..0c3d7ad 100644
--- a/test/aes128ofb_decrypt.c
+++ b/test/aes128ofb_decrypt.c
@@ -10,44 +10,51 @@
#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: aes128ofb_decrypt.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, key, cipher, iv;
- Aes128KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, key, cipher, iv;
+ Aes128KeySchedule key_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ exit_with_usage();
- if (parse_aes_block128(&key, argv[1]) != 0)
- {
- fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]);
- exit_with_usage(argv[0]);
- }
+ if (parse_aes_block128(&key, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-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();
+ }
- aes128_expand_key_schedule(key, &key_schedule);
+ aes128_expand_key_schedule(key, &key_schedule);
- for (int i = 3; i < argc; ++i)
- {
- if (parse_aes_block128(&cipher, 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(&cipher, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv);
+ continue;
+ }
+ plain = aes128ofb_decrypt(cipher, &key_schedule, iv, &iv);
+ print_aes_block128(&plain);
}
- plain = aes128ofb_decrypt(cipher, &key_schedule, iv, &iv);
- print_aes_block128(&plain);
}
return 0;
diff --git a/test/aes128ofb_encrypt.c b/test/aes128ofb_encrypt.c
index 6142110..e77b121 100644
--- a/test/aes128ofb_encrypt.c
+++ b/test/aes128ofb_encrypt.c
@@ -10,44 +10,51 @@
#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 [PLAIN...]\n", argv0);
+ puts("Usage: aes128ofb_encrypt.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, key, cipher, iv;
- Aes128KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, key, cipher, iv;
+ Aes128KeySchedule key_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ exit_with_usage();
- if (parse_aes_block128(&key, argv[1]) != 0)
- {
- fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]);
- exit_with_usage(argv[0]);
- }
+ if (parse_aes_block128(&key, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-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();
+ }
- aes128_expand_key_schedule(key, &key_schedule);
+ aes128_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 = aes128ofb_encrypt(plain, &key_schedule, iv, &iv);
+ print_aes_block128(&cipher);
}
- cipher = aes128ofb_encrypt(plain, &key_schedule, iv, &iv);
- print_aes_block128(&cipher);
}
return 0;
diff --git a/test/aes192cbc_decrypt.c b/test/aes192cbc_decrypt.c
index 0a2cf99..2b2e235 100644
--- a/test/aes192cbc_decrypt.c
+++ b/test/aes192cbc_decrypt.c
@@ -10,46 +10,53 @@
#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: aes192cbc_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, inverted_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, cipher, iv;
+ AesBlock192 key;
+ Aes192KeySchedule key_schedule, inverted_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_invert_key_schedule(&key_schedule, &inverted_schedule);
+ aes192_expand_key_schedule(&key, &key_schedule);
+ aes192_invert_key_schedule(&key_schedule, &inverted_schedule);
- for (int i = 3; i < argc; ++i)
- {
- if (parse_aes_block128(&cipher, 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(&cipher, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv);
+ continue;
+ }
+ plain = aes192cbc_decrypt(cipher, &inverted_schedule, iv, &iv);
+ print_aes_block128(&plain);
}
- plain = aes192cbc_decrypt(cipher, &inverted_schedule, iv, &iv);
- print_aes_block128(&plain);
}
return 0;
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 <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 [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;
diff --git a/test/aes192cfb_decrypt.c b/test/aes192cfb_decrypt.c
index 51aad07..711cade 100644
--- a/test/aes192cfb_decrypt.c
+++ b/test/aes192cfb_decrypt.c
@@ -10,45 +10,52 @@
#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: aes192cfb_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)
+ 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 = aes192cfb_decrypt(cipher, &key_schedule, iv, &iv);
+ print_aes_block128(&plain);
}
- plain = aes192cfb_decrypt(cipher, &key_schedule, iv, &iv);
- print_aes_block128(&plain);
}
return 0;
diff --git a/test/aes192cfb_encrypt.c b/test/aes192cfb_encrypt.c
index b0e35eb..ad2a30a 100644
--- a/test/aes192cfb_encrypt.c
+++ b/test/aes192cfb_encrypt.c
@@ -10,45 +10,52 @@
#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 [PLAIN...]\n", argv0);
+ puts("Usage: aes192cfb_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 = aes192cfb_encrypt(plain, &key_schedule, iv, &iv);
+ print_aes_block128(&cipher);
}
- cipher = aes192cfb_encrypt(plain, &key_schedule, iv, &iv);
- print_aes_block128(&cipher);
}
return 0;
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;
diff --git a/test/aes192ctr_encrypt.c b/test/aes192ctr_encrypt.c
index aa63c59..c9bf131 100644
--- a/test/aes192ctr_encrypt.c
+++ b/test/aes192ctr_encrypt.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 [PLAIN...]\n", argv0);
+ puts("Usage: aes192ctr_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)
+ 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(&plain, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv);
+ continue;
+ }
+ cipher = aes192ctr_encrypt(plain, &key_schedule, iv, ctr++);
+ print_aes_block128(&cipher);
}
- cipher = aes192ctr_encrypt(plain, &key_schedule, iv, i - 3);
- print_aes_block128(&cipher);
}
return 0;
diff --git a/test/aes192ecb_decrypt.c b/test/aes192ecb_decrypt.c
index 007a3a3..b3cc257 100644
--- a/test/aes192ecb_decrypt.c
+++ b/test/aes192ecb_decrypt.c
@@ -10,40 +10,47 @@
#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 [CIPHER...]\n", argv0);
+ puts("Usage: aes192ecb_decrypt.exe KEY0 [CIPHER0...] [-- KEY1 [CIPHER1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, cipher;
- AesBlock192 key;
- Aes192KeySchedule key_schedule, inverted_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, cipher;
+ AesBlock192 key;
+ Aes192KeySchedule key_schedule, inverted_schedule;
- if (argc < 2)
- exit_with_usage(argv[0]);
+ if (argc < 1)
+ 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 128-bit AES block '%s'\n", *argv);
+ exit_with_usage();
+ }
- aes192_expand_key_schedule(&key, &key_schedule);
- aes192_invert_key_schedule(&key_schedule, &inverted_schedule);
+ aes192_expand_key_schedule(&key, &key_schedule);
+ aes192_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 = aes192ecb_decrypt(cipher, &inverted_schedule);
+ print_aes_block128(&plain);
}
- plain = aes192ecb_decrypt(cipher, &inverted_schedule);
- print_aes_block128(&plain);
}
return 0;
diff --git a/test/aes192ecb_encrypt.c b/test/aes192ecb_encrypt.c
index 3c81b55..ea7090e 100644
--- a/test/aes192ecb_encrypt.c
+++ b/test/aes192ecb_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: aes192ecb_encrypt.exe KEY0 [PLAIN0...] [-- KEY1 [PLAIN1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, cipher;
- AesBlock192 key;
- Aes192KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, cipher;
+ AesBlock192 key;
+ Aes192KeySchedule key_schedule;
- if (argc < 2)
- exit_with_usage(argv[0]);
+ if (argc < 1)
+ 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();
+ }
- aes192_expand_key_schedule(&key, &key_schedule);
+ aes192_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 = aes192ecb_encrypt(plain, &key_schedule);
+ print_aes_block128(&cipher);
}
- cipher = aes192ecb_encrypt(plain, &key_schedule);
- print_aes_block128(&cipher);
}
return 0;
diff --git a/test/aes192ofb_decrypt.c b/test/aes192ofb_decrypt.c
index 819d8c3..7c09dfd 100644
--- a/test/aes192ofb_decrypt.c
+++ b/test/aes192ofb_decrypt.c
@@ -10,45 +10,52 @@
#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: aes192ofb_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)
+ 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 = aes192ofb_decrypt(cipher, &key_schedule, iv, &iv);
+ print_aes_block128(&plain);
}
- plain = aes192ofb_decrypt(cipher, &key_schedule, iv, &iv);
- print_aes_block128(&plain);
}
return 0;
diff --git a/test/aes192ofb_encrypt.c b/test/aes192ofb_encrypt.c
index c3c0bbc..109688e 100644
--- a/test/aes192ofb_encrypt.c
+++ b/test/aes192ofb_encrypt.c
@@ -10,45 +10,52 @@
#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 [PLAIN...]\n", argv0);
+ puts("Usage: aes192ofb_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 = aes192ofb_encrypt(plain, &key_schedule, iv, &iv);
+ print_aes_block128(&cipher);
}
- cipher = aes192ofb_encrypt(plain, &key_schedule, iv, &iv);
- print_aes_block128(&cipher);
}
return 0;
diff --git a/test/aes256cbc_decrypt.c b/test/aes256cbc_decrypt.c
index bd7c1f2..5efb0e4 100644
--- a/test/aes256cbc_decrypt.c
+++ b/test/aes256cbc_decrypt.c
@@ -10,46 +10,53 @@
#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: aes256cbc_decrypt.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, cipher, iv;
- AesBlock256 key;
- Aes256KeySchedule key_schedule, inverted_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, cipher, iv;
+ AesBlock256 key;
+ Aes256KeySchedule key_schedule, inverted_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ 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();
+ }
- 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();
+ }
- 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 = 3; i < argc; ++i)
- {
- if (parse_aes_block128(&cipher, 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(&cipher, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv);
+ continue;
+ }
+ plain = aes256cbc_decrypt(cipher, &inverted_schedule, iv, &iv);
+ print_aes_block128(&plain);
}
- plain = aes256cbc_decrypt(cipher, &inverted_schedule, iv, &iv);
- print_aes_block128(&plain);
}
return 0;
diff --git a/test/aes256cbc_encrypt.c b/test/aes256cbc_encrypt.c
index 0cac205..71484d7 100644
--- a/test/aes256cbc_encrypt.c
+++ b/test/aes256cbc_encrypt.c
@@ -10,45 +10,52 @@
#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 [PLAIN...]\n", argv0);
+ puts("Usage: aes256cbc_encrypt.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, cipher, iv;
- AesBlock256 key;
- Aes256KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, cipher, iv;
+ AesBlock256 key;
+ Aes256KeySchedule key_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ 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();
+ }
- 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();
+ }
- aes256_expand_key_schedule(&key, &key_schedule);
+ aes256_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 = aes256cbc_encrypt(plain, &key_schedule, iv, &iv);
+ print_aes_block128(&cipher);
}
- cipher = aes256cbc_encrypt(plain, &key_schedule, iv, &iv);
- print_aes_block128(&cipher);
}
return 0;
diff --git a/test/aes256cfb_decrypt.c b/test/aes256cfb_decrypt.c
index 13809d8..fc30ba4 100644
--- a/test/aes256cfb_decrypt.c
+++ b/test/aes256cfb_decrypt.c
@@ -10,45 +10,52 @@
#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: aes256cfb_decrypt.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, cipher, iv;
- AesBlock256 key;
- Aes256KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, cipher, iv;
+ AesBlock256 key;
+ Aes256KeySchedule key_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ 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();
+ }
- 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();
+ }
- aes256_expand_key_schedule(&key, &key_schedule);
+ aes256_expand_key_schedule(&key, &key_schedule);
- for (int i = 3; i < argc; ++i)
- {
- if (parse_aes_block128(&cipher, 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(&cipher, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv);
+ continue;
+ }
+ plain = aes256cfb_decrypt(cipher, &key_schedule, iv, &iv);
+ print_aes_block128(&plain);
}
- plain = aes256cfb_decrypt(cipher, &key_schedule, iv, &iv);
- print_aes_block128(&plain);
}
return 0;
diff --git a/test/aes256cfb_encrypt.c b/test/aes256cfb_encrypt.c
index f60248a..666c605 100644
--- a/test/aes256cfb_encrypt.c
+++ b/test/aes256cfb_encrypt.c
@@ -10,45 +10,52 @@
#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 [PLAIN...]\n", argv0);
+ puts("Usage: aes256cfb_encrypt.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, cipher, iv;
- AesBlock256 key;
- Aes256KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, cipher, iv;
+ AesBlock256 key;
+ Aes256KeySchedule key_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ 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();
+ }
- 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();
+ }
- aes256_expand_key_schedule(&key, &key_schedule);
+ aes256_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 = aes256cfb_encrypt(plain, &key_schedule, iv, &iv);
+ print_aes_block128(&cipher);
}
- cipher = aes256cfb_encrypt(plain, &key_schedule, iv, &iv);
- print_aes_block128(&cipher);
}
return 0;
diff --git a/test/aes256ctr_decrypt.c b/test/aes256ctr_decrypt.c
index 9d41864..68bf1b7 100644
--- a/test/aes256ctr_decrypt.c
+++ b/test/aes256ctr_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: aes256ctr_decrypt.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, cipher, iv;
- AesBlock256 key;
- Aes256KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, cipher, iv;
+ AesBlock256 key;
+ Aes256KeySchedule key_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ 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();
+ }
- 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();
+ }
- aes256_expand_key_schedule(&key, &key_schedule);
+ aes256_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 = aes256ctr_decrypt(cipher, &key_schedule, iv, ctr++);
+ print_aes_block128(&plain);
}
- plain = aes256ctr_decrypt(cipher, &key_schedule, iv, i - 3);
- print_aes_block128(&plain);
}
return 0;
diff --git a/test/aes256ctr_encrypt.c b/test/aes256ctr_encrypt.c
index bd69a7a..2552610 100644
--- a/test/aes256ctr_encrypt.c
+++ b/test/aes256ctr_encrypt.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 [PLAIN...]\n", argv0);
+ puts("Usage: aes256ctr_encrypt.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, cipher, iv;
- AesBlock256 key;
- Aes256KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, cipher, iv;
+ AesBlock256 key;
+ Aes256KeySchedule key_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ 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();
+ }
- 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();
+ }
- aes256_expand_key_schedule(&key, &key_schedule);
+ aes256_expand_key_schedule(&key, &key_schedule);
- for (int i = 3; i < argc; ++i)
- {
- if (parse_aes_block128(&plain, 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(&plain, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv);
+ continue;
+ }
+ cipher = aes256ctr_encrypt(plain, &key_schedule, iv, ctr++);
+ print_aes_block128(&cipher);
}
- cipher = aes256ctr_encrypt(plain, &key_schedule, iv, i - 3);
- print_aes_block128(&cipher);
}
return 0;
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 <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 [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;
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;
diff --git a/test/aes256ofb_decrypt.c b/test/aes256ofb_decrypt.c
index 6bbd692..7eaf7c3 100644
--- a/test/aes256ofb_decrypt.c
+++ b/test/aes256ofb_decrypt.c
@@ -10,45 +10,52 @@
#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: aes256ofb_decrypt.exe KEY0 IV0 [CIPHER0...] [-- KEY1 IV1 [CIPHER1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, cipher, iv;
- AesBlock256 key;
- Aes256KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, cipher, iv;
+ AesBlock256 key;
+ Aes256KeySchedule key_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ 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();
+ }
- 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();
+ }
- aes256_expand_key_schedule(&key, &key_schedule);
+ aes256_expand_key_schedule(&key, &key_schedule);
- for (int i = 3; i < argc; ++i)
- {
- if (parse_aes_block128(&cipher, 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(&cipher, *argv) != 0)
+ {
+ fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv);
+ continue;
+ }
+ plain = aes256ofb_decrypt(cipher, &key_schedule, iv, &iv);
+ print_aes_block128(&plain);
}
- plain = aes256ofb_decrypt(cipher, &key_schedule, iv, &iv);
- print_aes_block128(&plain);
}
return 0;
diff --git a/test/aes256ofb_encrypt.c b/test/aes256ofb_encrypt.c
index cf0acda..dde7aa2 100644
--- a/test/aes256ofb_encrypt.c
+++ b/test/aes256ofb_encrypt.c
@@ -10,45 +10,52 @@
#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 [PLAIN...]\n", argv0);
+ puts("Usage: aes256ofb_encrypt.exe KEY0 IV0 [PLAIN0...] [-- KEY1 IV1 [PLAIN1...]...]");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv)
{
- AesBlock128 plain, cipher, iv;
- AesBlock256 key;
- Aes256KeySchedule key_schedule;
+ for (--argc, ++argv; argc > -1; --argc, ++argv)
+ {
+ AesBlock128 plain, cipher, iv;
+ AesBlock256 key;
+ Aes256KeySchedule key_schedule;
- if (argc < 3)
- exit_with_usage(argv[0]);
+ if (argc < 2)
+ 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();
+ }
- 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();
+ }
- aes256_expand_key_schedule(&key, &key_schedule);
+ aes256_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 = aes256ofb_encrypt(plain, &key_schedule, iv, &iv);
+ print_aes_block128(&cipher);
}
- cipher = aes256ofb_encrypt(plain, &key_schedule, iv, &iv);
- print_aes_block128(&cipher);
}
return 0;