From 32f8a474fdfe5ed1a5a9dfc34fa2dd41e1a6d9c1 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 1 Sep 2015 02:53:39 +0300 Subject: refactoring --- src/box.c | 26 +++++++++++++------------- src/box_aes.c | 58 +++++++++++++++++++++++++++++----------------------------- 2 files changed, 42 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/box.c b/src/box.c index 5883629..5f63063 100644 --- a/src/box.c +++ b/src/box.c @@ -21,7 +21,7 @@ static const AesNI_BoxAlgorithmInterface* aesni_box_algorithms[] = AesNI_StatusCode aesni_box_init( AesNI_Box* box, AesNI_Algorithm algorithm, - const AesNI_BoxAlgorithmParams* algorithm_params, + const AesNI_BoxKey* box_key, AesNI_Mode mode, const AesNI_BoxBlock* iv, AesNI_ErrorDetails* err_details) @@ -30,10 +30,10 @@ AesNI_StatusCode aesni_box_init( box->algorithm = aesni_box_algorithms[algorithm]; - if (aesni_is_error(status = box->algorithm->derive_params( - algorithm_params, - &box->encrypt_params, - &box->decrypt_params, + if (aesni_is_error(status = box->algorithm->calc_round_keys( + box_key, + &box->encryption_keys, + &box->decryption_keys, err_details))) return status; @@ -51,7 +51,7 @@ static AesNI_StatusCode aesni_box_encrypt_block_ecb( AesNI_ErrorDetails* err_details) { return box->algorithm->encrypt_block( - input, &box->encrypt_params, output, err_details); + input, &box->encryption_keys, output, err_details); } static AesNI_StatusCode aesni_box_encrypt_block_cbc( @@ -68,7 +68,7 @@ static AesNI_StatusCode aesni_box_encrypt_block_cbc( return status; if (aesni_is_error(status = box->algorithm->encrypt_block( - &xored_input, &box->encrypt_params, output, err_details))) + &xored_input, &box->encryption_keys, output, err_details))) return status; box->iv = *output; @@ -84,7 +84,7 @@ static AesNI_StatusCode aesni_box_encrypt_block_cfb( AesNI_StatusCode status = AESNI_SUCCESS; if (aesni_is_error(status = box->algorithm->encrypt_block( - &box->iv, &box->encrypt_params, output, err_details))) + &box->iv, &box->encryption_keys, output, err_details))) return status; if (aesni_is_error(status = box->algorithm->xor_block( @@ -104,7 +104,7 @@ static AesNI_StatusCode aesni_box_encrypt_block_ofb( AesNI_StatusCode status = AESNI_SUCCESS; if (aesni_is_error(status = box->algorithm->encrypt_block( - &box->iv, &box->encrypt_params, &box->iv, err_details))) + &box->iv, &box->encryption_keys, &box->iv, err_details))) return status; *output = box->iv; @@ -125,7 +125,7 @@ static AesNI_StatusCode aesni_box_encrypt_block_ctr( AesNI_StatusCode status = AESNI_SUCCESS; if (aesni_is_error(status = box->algorithm->encrypt_block( - &box->iv, &box->encrypt_params, output, err_details))) + &box->iv, &box->encryption_keys, output, err_details))) return status; if (aesni_is_error(status = box->algorithm->xor_block( @@ -171,7 +171,7 @@ static AesNI_StatusCode aesni_box_decrypt_block_ecb( AesNI_ErrorDetails* err_details) { return box->algorithm->decrypt_block( - input, &box->decrypt_params, output, err_details); + input, &box->decryption_keys, output, err_details); } static AesNI_StatusCode aesni_box_decrypt_block_cbc( @@ -183,7 +183,7 @@ static AesNI_StatusCode aesni_box_decrypt_block_cbc( AesNI_StatusCode status = AESNI_SUCCESS; if (aesni_is_error(status = box->algorithm->decrypt_block( - input, &box->decrypt_params, output, err_details))) + input, &box->decryption_keys, output, err_details))) return status; if (aesni_is_error(status = box->algorithm->xor_block( @@ -203,7 +203,7 @@ static AesNI_StatusCode aesni_box_decrypt_block_cfb( AesNI_StatusCode status = AESNI_SUCCESS; if (aesni_is_error(status = box->algorithm->encrypt_block( - &box->iv, &box->encrypt_params, output, err_details))) + &box->iv, &box->encryption_keys, output, err_details))) return status; if (aesni_is_error(status = box->algorithm->xor_block( diff --git a/src/box_aes.c b/src/box_aes.c index 8642f31..8468687 100644 --- a/src/box_aes.c +++ b/src/box_aes.c @@ -12,49 +12,49 @@ #include static AesNI_StatusCode aesni_box_derive_params_aes128( - const AesNI_BoxAlgorithmParams* algorithm_params, - AesNI_BoxEncryptionParams* encrypt_params, - AesNI_BoxDecryptionParams* decrypt_params, + const AesNI_BoxKey* box_key, + AesNI_BoxEncryptionRoundKeys* encryption_keys, + AesNI_BoxDecryptionRoundKeys* decryption_keys, AesNI_ErrorDetails* err_details) { aesni_AES128_expand_key_( - algorithm_params->aes128_key.key, - &encrypt_params->aes128_encryption_keys); + box_key->aes128_key.key, + &encryption_keys->aes128_encryption_keys); aesni_AES128_derive_decryption_keys_( - &encrypt_params->aes128_encryption_keys, - &decrypt_params->aes128_decryption_keys); + &encryption_keys->aes128_encryption_keys, + &decryption_keys->aes128_decryption_keys); return AESNI_SUCCESS; } static AesNI_StatusCode aesni_box_derive_params_aes192( - const AesNI_BoxAlgorithmParams* algorithm_params, - AesNI_BoxEncryptionParams* encrypt_params, - AesNI_BoxDecryptionParams* decrypt_params, + const AesNI_BoxKey* box_key, + AesNI_BoxEncryptionRoundKeys* encryption_keys, + AesNI_BoxDecryptionRoundKeys* decryption_keys, AesNI_ErrorDetails* err_details) { aesni_AES192_expand_key_( - algorithm_params->aes192_key.lo, - algorithm_params->aes192_key.hi, - &encrypt_params->aes192_encryption_keys); + box_key->aes192_key.lo, + box_key->aes192_key.hi, + &encryption_keys->aes192_encryption_keys); aesni_AES192_derive_decryption_keys_( - &encrypt_params->aes192_encryption_keys, - &decrypt_params->aes192_decryption_keys); + &encryption_keys->aes192_encryption_keys, + &decryption_keys->aes192_decryption_keys); return AESNI_SUCCESS; } static AesNI_StatusCode aesni_box_derive_params_aes256( - const AesNI_BoxAlgorithmParams* algorithm_params, - AesNI_BoxEncryptionParams* encrypt_params, - AesNI_BoxDecryptionParams* decrypt_params, + const AesNI_BoxKey* box_key, + AesNI_BoxEncryptionRoundKeys* encryption_keys, + AesNI_BoxDecryptionRoundKeys* decryption_keys, AesNI_ErrorDetails* err_details) { aesni_AES256_expand_key_( - algorithm_params->aes256_key.lo, - algorithm_params->aes256_key.hi, - &encrypt_params->aes256_encryption_keys); + box_key->aes256_key.lo, + box_key->aes256_key.hi, + &encryption_keys->aes256_encryption_keys); aesni_AES256_derive_decryption_keys_( - &encrypt_params->aes256_encryption_keys, - &decrypt_params->aes256_decryption_keys); + &encryption_keys->aes256_encryption_keys, + &decryption_keys->aes256_decryption_keys); return AESNI_SUCCESS; } @@ -103,7 +103,7 @@ static AesNI_StatusCode aesni_box_load_block_aes( static AesNI_StatusCode aesni_box_encrypt_block_aes128( const AesNI_BoxBlock* input, - const AesNI_BoxEncryptionParams* params, + const AesNI_BoxEncryptionRoundKeys* params, AesNI_BoxBlock* output, AesNI_ErrorDetails* err_details) { @@ -115,7 +115,7 @@ static AesNI_StatusCode aesni_box_encrypt_block_aes128( static AesNI_StatusCode aesni_box_decrypt_block_aes128( const AesNI_BoxBlock* input, - const AesNI_BoxDecryptionParams* params, + const AesNI_BoxDecryptionRoundKeys* params, AesNI_BoxBlock* output, AesNI_ErrorDetails* err_details) { @@ -127,7 +127,7 @@ static AesNI_StatusCode aesni_box_decrypt_block_aes128( static AesNI_StatusCode aesni_box_encrypt_block_aes192( const AesNI_BoxBlock* input, - const AesNI_BoxEncryptionParams* params, + const AesNI_BoxEncryptionRoundKeys* params, AesNI_BoxBlock* output, AesNI_ErrorDetails* err_details) { @@ -139,7 +139,7 @@ static AesNI_StatusCode aesni_box_encrypt_block_aes192( static AesNI_StatusCode aesni_box_decrypt_block_aes192( const AesNI_BoxBlock* input, - const AesNI_BoxDecryptionParams* params, + const AesNI_BoxDecryptionRoundKeys* params, AesNI_BoxBlock* output, AesNI_ErrorDetails* err_details) { @@ -151,7 +151,7 @@ static AesNI_StatusCode aesni_box_decrypt_block_aes192( static AesNI_StatusCode aesni_box_encrypt_block_aes256( const AesNI_BoxBlock* input, - const AesNI_BoxEncryptionParams* params, + const AesNI_BoxEncryptionRoundKeys* params, AesNI_BoxBlock* output, AesNI_ErrorDetails* err_details) { @@ -163,7 +163,7 @@ static AesNI_StatusCode aesni_box_encrypt_block_aes256( static AesNI_StatusCode aesni_box_decrypt_block_aes256( const AesNI_BoxBlock* input, - const AesNI_BoxDecryptionParams* params, + const AesNI_BoxDecryptionRoundKeys* params, AesNI_BoxBlock* output, AesNI_ErrorDetails* err_details) { -- cgit v1.2.3