diff options
-rw-r--r-- | include/aesni/aes.h | 42 | ||||
-rw-r--r-- | src/box.c | 39 |
2 files changed, 8 insertions, 73 deletions
diff --git a/include/aesni/aes.h b/include/aesni/aes.h index b7a2854..bad5463 100644 --- a/include/aesni/aes.h +++ b/include/aesni/aes.h @@ -410,12 +410,7 @@ static __inline AesNI_Aes_Block __fastcall aesni_aes128_decrypt_block_ofb( AesNI_Aes_Block init_vector, AesNI_Aes_Block* next_init_vector) { - assert(encryption_keys); - assert(next_init_vector); - - AesNI_Aes_Block tmp = aesni_aes128_encrypt_block_(init_vector, encryption_keys); - *next_init_vector = tmp; - return aesni_xor_block128(tmp, ciphertext); + return aesni_aes128_encrypt_block_ofb(ciphertext, encryption_keys, init_vector, next_init_vector); } /** @@ -458,12 +453,7 @@ static __inline AesNI_Aes_Block __fastcall aesni_aes128_decrypt_block_ctr( AesNI_Aes_Block init_vector, AesNI_Aes_Block* next_init_vector) { - assert(encryption_keys); - assert(next_init_vector); - - AesNI_Aes_Block plaintext = aesni_xor_block128(ciphertext, aesni_aes128_encrypt_block_(init_vector, encryption_keys)); - *next_init_vector = aesni_aes_inc_counter(init_vector); - return plaintext; + return aesni_aes128_encrypt_block_ctr(ciphertext, encryption_keys, init_vector, next_init_vector); } /** @@ -668,12 +658,7 @@ static __inline AesNI_Aes_Block __fastcall aesni_aes192_decrypt_block_ofb( AesNI_Aes_Block init_vector, AesNI_Aes_Block* next_init_vector) { - assert(encryption_keys); - assert(next_init_vector); - - AesNI_Aes_Block tmp = aesni_aes192_encrypt_block_(init_vector, encryption_keys); - *next_init_vector = tmp; - return aesni_xor_block128(tmp, ciphertext); + return aesni_aes192_encrypt_block_ofb(ciphertext, encryption_keys, init_vector, next_init_vector); } /** @@ -716,12 +701,7 @@ static __inline AesNI_Aes_Block __fastcall aesni_aes192_decrypt_block_ctr( AesNI_Aes_Block init_vector, AesNI_Aes_Block* next_init_vector) { - assert(encryption_keys); - assert(next_init_vector); - - AesNI_Aes_Block plaintext = aesni_xor_block128(ciphertext, aesni_aes192_encrypt_block_(init_vector, encryption_keys)); - *next_init_vector = aesni_aes_inc_counter(init_vector); - return plaintext; + return aesni_aes192_encrypt_block_ctr(ciphertext, encryption_keys, init_vector, next_init_vector); } /** @@ -926,12 +906,7 @@ static __inline AesNI_Aes_Block __fastcall aesni_aes256_decrypt_block_ofb( AesNI_Aes_Block init_vector, AesNI_Aes_Block* next_init_vector) { - assert(encryption_keys); - assert(next_init_vector); - - AesNI_Aes_Block tmp = aesni_aes256_encrypt_block_(init_vector, encryption_keys); - *next_init_vector = tmp; - return aesni_xor_block128(tmp, ciphertext); + return aesni_aes256_encrypt_block_ofb(ciphertext, encryption_keys, init_vector, next_init_vector); } /** @@ -974,12 +949,7 @@ static __inline AesNI_Aes_Block __fastcall aesni_aes256_decrypt_block_ctr( AesNI_Aes_Block init_vector, AesNI_Aes_Block* next_init_vector) { - assert(encryption_keys); - assert(next_init_vector); - - AesNI_Aes_Block plaintext = aesni_xor_block128(ciphertext, aesni_aes256_encrypt_block_(init_vector, encryption_keys)); - *next_init_vector = aesni_aes_inc_counter(init_vector); - return plaintext; + return aesni_aes256_encrypt_block_ctr(ciphertext, encryption_keys, init_vector, next_init_vector); } #ifdef __cplusplus @@ -234,41 +234,6 @@ static AesNI_StatusCode aesni_box_decrypt_cfb( return status; } -static AesNI_StatusCode aesni_box_decrypt_ofb( - AesNI_Box* box, - const AesNI_BoxBlock* input, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) -{ - AesNI_StatusCode status = box->algorithm_iface->encrypt( - &box->iv, - &box->encrypt_params, - output, - err_details); - if (aesni_is_error(status)) - return status; - - box->iv = *output; - - status = box->algorithm_iface->xor_block( - output, - input, - err_details); - if (aesni_is_error(status)) - return status; - - return status; -} - -static AesNI_StatusCode aesni_box_decrypt_ctr( - AesNI_Box* box, - const AesNI_BoxBlock* input, - AesNI_BoxBlock* output, - AesNI_ErrorDetails* err_details) -{ - return aesni_box_encrypt_ctr(box, input, output, err_details); -} - typedef AesNI_BoxEncryptMode AesNI_BoxDecryptMode; static AesNI_BoxDecryptMode aesni_box_decrypt_mode[] = @@ -276,8 +241,8 @@ static AesNI_BoxDecryptMode aesni_box_decrypt_mode[] = &aesni_box_decrypt_ecb, &aesni_box_decrypt_cbc, &aesni_box_decrypt_cfb, - &aesni_box_decrypt_ofb, - &aesni_box_decrypt_ctr, + &aesni_box_encrypt_ofb, + &aesni_box_encrypt_ctr, }; AesNI_StatusCode aesni_box_decrypt( |