aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/aes128cbc_encrypt_block.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2015-06-19 19:33:02 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2015-06-19 19:33:02 +0300
commit8f02b653ccd8565529a427c65e6834088739ba26 (patch)
tree58857e88cf569806a12744ca803d8499bc7664ee /test/aes128cbc_encrypt_block.c
parentrename executables (diff)
downloadaes-tools-8f02b653ccd8565529a427c65e6834088739ba26.tar.gz
aes-tools-8f02b653ccd8565529a427c65e6834088739ba26.zip
test: better error handling in block utils
Diffstat (limited to '')
-rw-r--r--test/aes128cbc_encrypt_block.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/test/aes128cbc_encrypt_block.c b/test/aes128cbc_encrypt_block.c
index c9c719d..68f95a3 100644
--- a/test/aes128cbc_encrypt_block.c
+++ b/test/aes128cbc_encrypt_block.c
@@ -18,8 +18,15 @@ static void exit_with_usage()
exit(EXIT_FAILURE);
}
+static void print_error(AesNI_StatusCode status)
+{
+ fprintf(stderr, "AesNI error: %s\n", aesni_strerror(status));
+}
+
int main(int argc, char** argv)
{
+ AesNI_StatusCode status = AESNI_SUCCESS;
+
for (--argc, ++argv; argc > -1; --argc, ++argv)
{
AesNI_Block128 plaintext, ciphertext, iv;
@@ -29,15 +36,15 @@ int main(int argc, char** argv)
if (argc < 2)
exit_with_usage();
- if (aesni_is_error(aesni_aes128_parse_key(&key, *argv, NULL)))
+ if (aesni_is_error(status = aesni_aes128_parse_key(&key, *argv, NULL)))
{
- fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv);
+ print_error(status);
exit_with_usage();
}
- if (aesni_is_error(aesni_aes_parse_block(&iv, argv[1], NULL)))
+ if (aesni_is_error(status = aesni_aes_parse_block(&iv, argv[1], NULL)))
{
- fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[1]);
+ print_error(status);
exit_with_usage();
}
@@ -48,13 +55,19 @@ int main(int argc, char** argv)
if (strcmp("--", *argv) == 0)
break;
- if (aesni_is_error(aesni_aes_parse_block(&plaintext, *argv, NULL)))
+ if (aesni_is_error(status = aesni_aes_parse_block(&plaintext, *argv, NULL)))
{
- fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv);
+ print_error(status);
continue;
}
+
ciphertext = aesni_aes128_encrypt_block_cbc(plaintext, &encryption_keys, iv, &iv);
- aesni_aes_print_block(&ciphertext, NULL);
+
+ if (aesni_is_error(status = aesni_aes_print_block(&ciphertext, NULL)))
+ {
+ print_error(status);
+ continue;
+ }
}
}