diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-19 09:42:55 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-19 09:42:55 +0300 |
commit | 3716501690fb4e1ddd1af385b4d012cce2d107ac (patch) | |
tree | 1b4f48b22cc980ba7cfb93bd5a83ec5e078157de /src/box_aes.c | |
parent | refactoring (diff) | |
download | aes-tools-3716501690fb4e1ddd1af385b4d012cce2d107ac.tar.gz aes-tools-3716501690fb4e1ddd1af385b4d012cce2d107ac.zip |
add buffer encryption to "boxes"
Diffstat (limited to 'src/box_aes.c')
-rw-r--r-- | src/box_aes.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/box_aes.c b/src/box_aes.c index 12f369d..49c5326 100644 --- a/src/box_aes.c +++ b/src/box_aes.c @@ -9,6 +9,7 @@ #include <aesni/all.h> #include <stdlib.h> +#include <string.h> static AesNI_StatusCode aesni_box_derive_params_aes128( const AesNI_BoxAlgorithmParams* algorithm_params, @@ -82,6 +83,62 @@ static AesNI_StatusCode aesni_box_get_block_size_aes( return AESNI_SUCCESS; } +static AesNI_StatusCode aesni_box_store_block_aes( + void* dest, + const AesNI_BoxBlock* src, + AesNI_ErrorDetails* err_details) +{ + aesni_store_block128(dest, src->aes_block); + return AESNI_SUCCESS; +} + +static AesNI_StatusCode aesni_box_store_partial_block_aes( + void* dest, + const AesNI_BoxBlock* src, + size_t src_size, + AesNI_ErrorDetails* err_details) +{ + __declspec(align(16)) unsigned char buf[16]; + aesni_store_block128(buf, src->aes_block); + memcpy(dest, buf, src_size); + return AESNI_SUCCESS; +} + +static AesNI_StatusCode aesni_box_load_block_aes( + AesNI_BoxBlock* dest, + const void* src, + AesNI_ErrorDetails* err_details) +{ + dest->aes_block = aesni_load_block128(src); + return AESNI_SUCCESS; +} + +static AesNI_StatusCode aesni_box_load_partial_block_aes( + AesNI_BoxBlock* dest, + const void* src, + size_t src_size, + AesNI_ErrorDetails* err_details) +{ + __declspec(align(16)) unsigned char buf[16]; + memset(buf, 0x00, 16); + memcpy(buf, src, src_size); + dest->aes_block = aesni_load_block128_aligned(buf); + return AESNI_SUCCESS; +} + +static AesNI_StatusCode aesni_box_load_block_with_padding_aes( + AesNI_BoxBlock* dest, + const void* src, + size_t src_size, + AesNI_ErrorDetails* err_details) +{ + __declspec(align(16)) unsigned char padding[16]; + memset(padding + src_size, 16 - src_size, 16 - src_size); + memcpy(padding, src, src_size); + dest->aes_block = aesni_load_block128_aligned(padding); + return AESNI_SUCCESS; +} + static AesNI_StatusCode aesni_box_encrypt_block_aes128( const AesNI_BoxBlock* input, const AesNI_BoxEncryptionParams* params, @@ -162,6 +219,11 @@ AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes128 = &aesni_box_xor_block_aes, &aesni_box_next_counter_aes, &aesni_box_get_block_size_aes, + &aesni_box_store_block_aes, + &aesni_box_store_partial_block_aes, + &aesni_box_load_block_aes, + &aesni_box_load_partial_block_aes, + &aesni_box_load_block_with_padding_aes, }; AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes192 = @@ -172,6 +234,11 @@ AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes192 = &aesni_box_xor_block_aes, &aesni_box_next_counter_aes, &aesni_box_get_block_size_aes, + &aesni_box_store_block_aes, + &aesni_box_store_partial_block_aes, + &aesni_box_load_block_aes, + &aesni_box_load_partial_block_aes, + &aesni_box_load_block_with_padding_aes, }; AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes256 = @@ -182,4 +249,9 @@ AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes256 = &aesni_box_xor_block_aes, &aesni_box_next_counter_aes, &aesni_box_get_block_size_aes, + &aesni_box_store_block_aes, + &aesni_box_store_partial_block_aes, + &aesni_box_load_block_aes, + &aesni_box_load_partial_block_aes, + &aesni_box_load_block_with_padding_aes, }; |