From 35f3497d371a0a05098fcfdbe6e40d91095ef06c Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 11 Jun 2015 03:25:03 +0300 Subject: add error codes & messages to the library --- include/aesni/all.h | 1 + include/aesni/buffer.h | 14 ++++++++++---- include/aesni/error.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 include/aesni/error.h (limited to 'include') diff --git a/include/aesni/all.h b/include/aesni/all.h index 1360320..4653eca 100644 --- a/include/aesni/all.h +++ b/include/aesni/all.h @@ -11,4 +11,5 @@ #include "block.h" #include "buffer.h" #include "data.h" +#include "error.h" #include "raw.h" diff --git a/include/aesni/buffer.h b/include/aesni/buffer.h index daafc3e..13f19da 100644 --- a/include/aesni/buffer.h +++ b/include/aesni/buffer.h @@ -8,6 +8,8 @@ #pragma once +#include "error.h" + #include #ifdef __cplusplus @@ -15,16 +17,20 @@ extern "C" { #endif -size_t aesni_encrypt_buffer_ecb128( +int aesni_encrypt_buffer_ecb128( const void* src, size_t src_size, void* dest, - AesNI_KeySchedule128* key_schedule); -size_t aesni_decrypt_buffer_ecb128( + size_t* dest_size, + AesNI_KeySchedule128* key_schedule, + AesNI_ErrorDetails*); +int aesni_decrypt_buffer_ecb128( const void* src, size_t src_size, void* dest, - AesNI_KeySchedule128* inverted_schedule); + size_t* dest_size, + AesNI_KeySchedule128* inverted_schedule, + AesNI_ErrorDetails*); #ifdef __cplusplus } diff --git a/include/aesni/error.h b/include/aesni/error.h new file mode 100644 index 0000000..54d3d34 --- /dev/null +++ b/include/aesni/error.h @@ -0,0 +1,50 @@ +/** + * \file + * \author Egor Tensin + * \date 2015 + * \copyright This file is licensed under the terms of the MIT License. + * See LICENSE.txt for details. + */ + +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef enum +{ + AESNI_ERROR_SUCCESS, + + AESNI_ERROR_NULL_ARGUMENT, + + AESNI_ERROR_INVALID_PKCS7_PADDING, +} +AesNI_ErrorCode; + +const char* aesni_strerror(AesNI_ErrorCode); + +typedef struct +{ + AesNI_ErrorCode ec; + + union + { + struct + { + char arg_name[32]; + } + null_arg; + } + params; +} +AesNI_ErrorDetails; + +void aesni_make_error_success(AesNI_ErrorDetails*); +void aesni_make_error_null_argument(AesNI_ErrorDetails*, const char* arg_name); +void aesni_make_error_invalid_pkcs7_padding(AesNI_ErrorDetails*); + +#ifdef __cplusplus +} +#endif -- cgit v1.2.3