aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/buffer.c57
1 files changed, 15 insertions, 42 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 71ebad2..74ff519 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -13,7 +13,7 @@
static unsigned char FULL_BLOCK_PADDING[16] = { 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 };
-int aesni_encrypt_buffer_ecb128(
+AesNI_StatusCode aesni_encrypt_buffer_ecb128(
const void* src,
size_t src_size,
void* dest,
@@ -22,29 +22,18 @@ int aesni_encrypt_buffer_ecb128(
AesNI_ErrorDetails* err_details)
{
if (dest_size == NULL)
- {
- aesni_make_error_null_argument(err_details, "dest_size");
- return 1;
- }
+ return aesni_make_error_null_argument(err_details, "dest_size");
const size_t rem_size = src_size % 16;
const size_t padding_size = 16 - rem_size;
*dest_size = src_size + padding_size;
if (dest == NULL)
- return 0;
-
+ return AESNI_SUCCESS;
if (src == NULL)
- {
- aesni_make_error_null_argument(err_details, "src");
- return 1;
- }
-
+ return aesni_make_error_null_argument(err_details, "src");
if (key_schedule == NULL)
- {
- aesni_make_error_null_argument(err_details, "key_schedule");
- return 1;
- }
+ return aesni_make_error_null_argument(err_details, "key_schedule");
const size_t src_len = src_size / 16;
@@ -71,7 +60,7 @@ int aesni_encrypt_buffer_ecb128(
AesNI_Block128 ciphertext = aesni_encrypt_block_ecb128(plaintext, key_schedule);
aesni_store_block128(dest, ciphertext);
- return 0;
+ return AESNI_SUCCESS;
}
static unsigned char get_pkcs7_padding_size(const unsigned char* padding)
@@ -86,7 +75,7 @@ static unsigned char get_pkcs7_padding_size(const unsigned char* padding)
return padding[15];
}
-int aesni_decrypt_buffer_ecb128(
+AesNI_StatusCode aesni_decrypt_buffer_ecb128(
const void* src,
size_t src_size,
void* dest,
@@ -95,27 +84,16 @@ int aesni_decrypt_buffer_ecb128(
AesNI_ErrorDetails* err_details)
{
if (dest_size == NULL)
- {
- aesni_make_error_null_argument(err_details, "dest_size");
- return 1;
- }
+ return aesni_make_error_null_argument(err_details, "dest_size");
*dest_size = src_size;
if (dest == NULL)
return 0;
-
if (src == NULL)
- {
- aesni_make_error_null_argument(err_details, "src");
- return 1;
- }
-
+ return aesni_make_error_null_argument(err_details, "src");
if (inverted_schedule == NULL)
- {
- aesni_make_error_null_argument(err_details, "inverted_schedule");
- return 1;
- }
+ return aesni_make_error_null_argument(err_details, "inverted_schedule");
const size_t src_len = src_size / 16;
@@ -134,14 +112,9 @@ int aesni_decrypt_buffer_ecb128(
unsigned char padding_size = get_pkcs7_padding_size(padding);
if (padding_size == 0)
- {
- aesni_make_error_invalid_pkcs7_padding(err_details);
- return 1;
- }
- else
- {
- memcpy(dest, padding, 16 - padding_size);
- *dest_size -= padding_size;
- return 0;
- }
+ return aesni_make_error_invalid_pkcs7_padding(err_details);
+
+ memcpy(dest, padding, 16 - padding_size);
+ *dest_size -= padding_size;
+ return AESNI_SUCCESS;
}