aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/box.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2015-07-06 19:19:18 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2015-07-06 19:19:18 +0300
commit7b46f7bb908cd1c2dfa9d385d404591cfbded053 (patch)
treeb8ba8d7650937442af7a8065d96ac5a42d133e56 /src/box.c
parentadd TODO (diff)
downloadaes-tools-7b46f7bb908cd1c2dfa9d385d404591cfbded053.tar.gz
aes-tools-7b46f7bb908cd1c2dfa9d385d404591cfbded053.zip
code style
Diffstat (limited to 'src/box.c')
-rw-r--r--src/box.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/box.c b/src/box.c
index 7fa59d1..5883629 100644
--- a/src/box.c
+++ b/src/box.c
@@ -29,6 +29,7 @@ AesNI_StatusCode aesni_box_init(
AesNI_StatusCode status = AESNI_SUCCESS;
box->algorithm = aesni_box_algorithms[algorithm];
+
if (aesni_is_error(status = box->algorithm->derive_params(
algorithm_params,
&box->encrypt_params,
@@ -316,6 +317,7 @@ static AesNI_StatusCode aesni_box_encrypt_buffer_partial_block_with_padding(
return status;
void* plaintext_buf = malloc(block_size);
+
if (plaintext_buf == NULL)
return status = aesni_error_memory_allocation(err_details);
@@ -357,6 +359,7 @@ static AesNI_StatusCode aesni_box_encrypt_buffer_partial_block(
return status;
void* plaintext_buf = malloc(block_size);
+
if (plaintext_buf == NULL)
return status = aesni_error_memory_allocation(err_details);
@@ -364,6 +367,7 @@ static AesNI_StatusCode aesni_box_encrypt_buffer_partial_block(
memcpy(plaintext_buf, src, src_size);
void* ciphertext_buf = malloc(block_size);
+
if (ciphertext_buf == NULL)
{
status = aesni_error_memory_allocation(err_details);
@@ -393,12 +397,13 @@ AesNI_StatusCode aesni_box_encrypt_buffer(
size_t* dest_size,
AesNI_ErrorDetails* err_details)
{
+ AesNI_StatusCode status = AESNI_SUCCESS;
+
if (box == NULL)
return aesni_error_null_argument(err_details, "box");
if (dest_size == NULL)
return aesni_error_null_argument(err_details, "dest_size");
- AesNI_StatusCode status = AESNI_SUCCESS;
size_t padding_size = 0;
if (aesni_is_error(status = aesni_box_get_encrypted_buffer_size(
@@ -418,11 +423,15 @@ AesNI_StatusCode aesni_box_encrypt_buffer(
const size_t src_len = src_size / block_size;
- for (size_t i = 0; i < src_len; ++i, (char*) src += block_size, (char*) dest += block_size)
+ for (size_t i = 0; i < src_len; ++i)
+ {
if (aesni_is_error(status = aesni_box_encrypt_buffer_block(
box, src, dest, err_details)))
return status;
+ (char*) src += block_size, (char*) dest += block_size;
+ }
+
if (padding_size == 0)
return aesni_box_encrypt_buffer_partial_block(
box, src, src_size % block_size, dest, err_details);
@@ -518,6 +527,7 @@ static AesNI_StatusCode aesni_box_decrypt_buffer_partial_block(
return status;
void* ciphertext_buf = malloc(block_size);
+
if (ciphertext_buf == NULL)
return status = aesni_error_memory_allocation(err_details);
@@ -525,6 +535,7 @@ static AesNI_StatusCode aesni_box_decrypt_buffer_partial_block(
memcpy(ciphertext_buf, src, src_size);
void* plaintext_buf = malloc(block_size);
+
if (plaintext_buf == NULL)
{
status = aesni_error_memory_allocation(err_details);
@@ -579,11 +590,15 @@ AesNI_StatusCode aesni_box_decrypt_buffer(
const size_t src_len = src_size / block_size;
- for (size_t i = 0; i < src_len; ++i, (char*) src += block_size, (char*) dest += block_size)
+ for (size_t i = 0; i < src_len; ++i)
+ {
if (aesni_is_error(status = aesni_box_decrypt_buffer_block(
box, src, dest, err_details)))
return status;
+ (char*) src += block_size, (char*) dest += block_size;
+ }
+
if (max_padding_size == 0)
{
return aesni_box_decrypt_buffer_partial_block(