From 8f02b653ccd8565529a427c65e6834088739ba26 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 19 Jun 2015 19:33:02 +0300 Subject: test: better error handling in block utils --- test/aes128ctr_decrypt_block.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'test/aes128ctr_decrypt_block.c') diff --git a/test/aes128ctr_decrypt_block.c b/test/aes128ctr_decrypt_block.c index e7513b5..85d07f5 100644 --- a/test/aes128ctr_decrypt_block.c +++ b/test/aes128ctr_decrypt_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(&ciphertext, *argv, NULL))) + if (aesni_is_error(status = aesni_aes_parse_block(&ciphertext, *argv, NULL))) { - fprintf(stderr, "Invalid 128-bit AES block '%s'\n", *argv); + print_error(status); continue; } + plaintext = aesni_aes128_decrypt_block_ctr(ciphertext, &encryption_keys, iv, &iv); - aesni_aes_print_block(&plaintext, NULL); + + if (aesni_is_error(status = aesni_aes_print_block(&plaintext, NULL))) + { + print_error(status); + continue; + } } } -- cgit v1.2.3