diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-10-20 03:11:50 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-10-20 03:11:50 +0300 |
commit | f9665896e3deb6c449c764ba8b30f700abe36cd5 (patch) | |
tree | 4203b64ccf2fb8ad4d40f20edad8aeff9448ab63 /src | |
parent | add missing `assert`s (diff) | |
download | aes-tools-f9665896e3deb6c449c764ba8b30f700abe36cd5.tar.gz aes-tools-f9665896e3deb6c449c764ba8b30f700abe36cd5.zip |
cxx: implement "boxes"
Diffstat (limited to 'src')
-rw-r--r-- | src/box.c | 60 | ||||
-rw-r--r-- | src/box_aes.c | 109 |
2 files changed, 169 insertions, 0 deletions
@@ -620,3 +620,63 @@ AesNI_StatusCode aesni_box_decrypt_buffer( return status; } } + +AesNI_StatusCode aesni_box_parse_block( + AesNI_BoxBlock* dest, + AesNI_Algorithm algorithm, + const char* src, + AesNI_ErrorDetails* err_details) +{ + if (dest == NULL) + return aesni_error_null_argument(err_details, "dest"); + if (src == NULL) + return aesni_error_null_argument(err_details, "src"); + + return aesni_box_algorithms[algorithm]->parse_block( + dest, src, err_details); +} + +AesNI_StatusCode aesni_box_parse_key( + AesNI_BoxKey* dest, + AesNI_Algorithm algorithm, + const char* src, + AesNI_ErrorDetails* err_details) +{ + if (dest == NULL) + return aesni_error_null_argument(err_details, "dest"); + if (src == NULL) + return aesni_error_null_argument(err_details, "src"); + + return aesni_box_algorithms[algorithm]->parse_key( + dest, src, err_details); +} + +AesNI_StatusCode aesni_box_format_block( + AesNI_BoxBlockString* dest, + AesNI_Algorithm algorithm, + const AesNI_BoxBlock* src, + AesNI_ErrorDetails* err_details) +{ + if (dest == NULL) + return aesni_error_null_argument(err_details, "dest"); + if (src == NULL) + return aesni_error_null_argument(err_details, "src"); + + return aesni_box_algorithms[algorithm]->format_block( + dest, src, err_details); +} + +AesNI_StatusCode aesni_box_format_key( + AesNI_BoxKeyString* dest, + AesNI_Algorithm algorithm, + const AesNI_BoxKey* src, + AesNI_ErrorDetails* err_details) +{ + if (dest == NULL) + return aesni_error_null_argument(err_details, "dest"); + if (src == NULL) + return aesni_error_null_argument(err_details, "src"); + + return aesni_box_algorithms[algorithm]->format_key( + dest, src, err_details); +} diff --git a/src/box_aes.c b/src/box_aes.c index 8468687..62cb4f2 100644 --- a/src/box_aes.c +++ b/src/box_aes.c @@ -58,11 +58,108 @@ static AesNI_StatusCode aesni_box_derive_params_aes256( return AESNI_SUCCESS; } +static AesNI_StatusCode aesni_box_parse_block_aes( + AesNI_BoxBlock* dest, + const char* src, + AesNI_ErrorDetails* err_details) +{ + if (dest == NULL) + return aesni_error_null_argument(err_details, "dest"); + + return aesni_AES_parse_block(&dest->aes_block, src, err_details); +} + +static AesNI_StatusCode aesni_box_parse_key_aes128( + AesNI_BoxKey* dest, + const char* src, + AesNI_ErrorDetails* err_details) +{ + if (dest == NULL) + return aesni_error_null_argument(err_details, "dest"); + + return aesni_AES128_parse_key(&dest->aes128_key, src, err_details); +} + +static AesNI_StatusCode aesni_box_parse_key_aes192( + AesNI_BoxKey* dest, + const char* src, + AesNI_ErrorDetails* err_details) +{ + if (dest == NULL) + return aesni_error_null_argument(err_details, "dest"); + + return aesni_AES192_parse_key(&dest->aes192_key, src, err_details); +} + +static AesNI_StatusCode aesni_box_parse_key_aes256( + AesNI_BoxKey* dest, + const char* src, + AesNI_ErrorDetails* err_details) +{ + if (dest == NULL) + return aesni_error_null_argument(err_details, "dest"); + + return aesni_AES256_parse_key(&dest->aes256_key, src, err_details); +} + +static AesNI_StatusCode aesni_box_format_block_aes( + AesNI_BoxBlockString* dest, + const AesNI_BoxBlock* src, + AesNI_ErrorDetails* err_details) +{ + if (dest == NULL) + return aesni_error_null_argument(err_details, "dest"); + if (src == NULL) + return aesni_error_null_argument(err_details, "src"); + + return aesni_AES128_format_block(&dest->aes, &src->aes_block, err_details); +} + +static AesNI_StatusCode aesni_box_format_key_aes128( + AesNI_BoxKeyString* dest, + const AesNI_BoxKey* src, + AesNI_ErrorDetails* err_details) +{ + if (dest == NULL) + return aesni_error_null_argument(err_details, "dest"); + if (src == NULL) + return aesni_error_null_argument(err_details, "src"); + + return aesni_AES128_format_key(&dest->aes128, &src->aes128_key, err_details); +} + +static AesNI_StatusCode aesni_box_format_key_aes192( + AesNI_BoxKeyString* dest, + const AesNI_BoxKey* src, + AesNI_ErrorDetails* err_details) +{ + if (dest == NULL) + return aesni_error_null_argument(err_details, "dest"); + if (src == NULL) + return aesni_error_null_argument(err_details, "src"); + + return aesni_AES192_format_key(&dest->aes192, &src->aes192_key, err_details); +} + +static AesNI_StatusCode aesni_box_format_key_aes256( + AesNI_BoxKeyString* dest, + const AesNI_BoxKey* src, + AesNI_ErrorDetails* err_details) +{ + if (dest == NULL) + return aesni_error_null_argument(err_details, "dest"); + if (src == NULL) + return aesni_error_null_argument(err_details, "src"); + + return aesni_AES256_format_key(&dest->aes256, &src->aes256_key, err_details); +} + static AesNI_StatusCode aesni_box_xor_block_aes( AesNI_BoxBlock* dest, const AesNI_BoxBlock* src, AesNI_ErrorDetails* err_details) { + dest->aes_block = aesni_AES_xor_blocks(dest->aes_block, src->aes_block); return AESNI_SUCCESS; } @@ -176,6 +273,10 @@ static AesNI_StatusCode aesni_box_decrypt_block_aes256( AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes128 = { &aesni_box_derive_params_aes128, + &aesni_box_parse_block_aes, + &aesni_box_parse_key_aes128, + &aesni_box_format_block_aes, + &aesni_box_format_key_aes128, &aesni_box_encrypt_block_aes128, &aesni_box_decrypt_block_aes128, &aesni_box_xor_block_aes, @@ -188,6 +289,10 @@ AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes128 = AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes192 = { &aesni_box_derive_params_aes192, + &aesni_box_parse_block_aes, + &aesni_box_parse_key_aes192, + &aesni_box_format_block_aes, + &aesni_box_format_key_aes192, &aesni_box_encrypt_block_aes192, &aesni_box_decrypt_block_aes192, &aesni_box_xor_block_aes, @@ -200,6 +305,10 @@ AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes192 = AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes256 = { &aesni_box_derive_params_aes256, + &aesni_box_parse_block_aes, + &aesni_box_parse_key_aes256, + &aesni_box_format_block_aes, + &aesni_box_format_key_aes256, &aesni_box_encrypt_block_aes256, &aesni_box_decrypt_block_aes256, &aesni_box_xor_block_aes, |