From 53dfe511dc29beb8d399e95dfa93b6d3baed6b57 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 28 Jul 2015 21:34:15 +0300 Subject: refactoring Namely, rename API functions to facilitate metaprogramming using preprocessor macros. --- src/c/aes128.c | 32 ++++++++++++++++---------------- src/c/aes192.c | 34 +++++++++++++++++----------------- src/c/aes256.c | 40 ++++++++++++++++++++-------------------- 3 files changed, 53 insertions(+), 53 deletions(-) (limited to 'src/c') diff --git a/src/c/aes128.c b/src/c/aes128.c index b2e37ba..a99c8a7 100644 --- a/src/c/aes128.c +++ b/src/c/aes128.c @@ -11,9 +11,9 @@ #include #include -AesNI_Aes_Block __fastcall aesni_aes128_encrypt_block_( - AesNI_Aes_Block plaintext, - const AesNI_Aes128_RoundKeys* encryption_keys) +AesNI_AES_Block __fastcall aesni_AES128_encrypt_block_( + AesNI_AES_Block plaintext, + const AesNI_AES128_RoundKeys* encryption_keys) { plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]); plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[1]); @@ -28,9 +28,9 @@ AesNI_Aes_Block __fastcall aesni_aes128_encrypt_block_( return _mm_aesenclast_si128(plaintext, encryption_keys->keys[10]); } -AesNI_Aes_Block __fastcall aesni_aes128_decrypt_block_( - AesNI_Aes_Block ciphertext, - const AesNI_Aes128_RoundKeys* decryption_keys) +AesNI_AES_Block __fastcall aesni_AES128_decrypt_block_( + AesNI_AES_Block ciphertext, + const AesNI_AES128_RoundKeys* decryption_keys) { ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]); ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[1]); @@ -45,11 +45,11 @@ AesNI_Aes_Block __fastcall aesni_aes128_decrypt_block_( return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[10]); } -static AesNI_Aes_Block __fastcall aesni_aes128_expand_key_assist( - AesNI_Aes_Block prev, - AesNI_Aes_Block hwgen) +static AesNI_AES_Block __fastcall aesni_aes128_expand_key_assist( + AesNI_AES_Block prev, + AesNI_AES_Block hwgen) { - AesNI_Aes_Block tmp = prev; + AesNI_AES_Block tmp = prev; tmp = _mm_slli_si128(tmp, 4); prev = _mm_xor_si128(prev, tmp); @@ -64,9 +64,9 @@ static AesNI_Aes_Block __fastcall aesni_aes128_expand_key_assist( return prev; } -void __fastcall aesni_aes128_expand_key_( - AesNI_Aes_Block key, - AesNI_Aes128_RoundKeys* encryption_keys) +void __fastcall aesni_AES128_expand_key_( + AesNI_AES_Block key, + AesNI_AES128_RoundKeys* encryption_keys) { AesNI_Block128 prev = encryption_keys->keys[0] = key; prev = encryption_keys->keys[1] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x01)); @@ -81,9 +81,9 @@ void __fastcall aesni_aes128_expand_key_( prev = encryption_keys->keys[10] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x36)); } -void __fastcall aesni_aes128_derive_decryption_keys_( - const AesNI_Aes128_RoundKeys* encryption_keys, - AesNI_Aes128_RoundKeys* decryption_keys) +void __fastcall aesni_AES128_derive_decryption_keys_( + const AesNI_AES128_RoundKeys* encryption_keys, + AesNI_AES128_RoundKeys* decryption_keys) { decryption_keys->keys[0] = encryption_keys->keys[10]; decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[9]); diff --git a/src/c/aes192.c b/src/c/aes192.c index 702ee5e..a8ae6cf 100644 --- a/src/c/aes192.c +++ b/src/c/aes192.c @@ -11,9 +11,9 @@ #include #include -AesNI_Aes_Block __fastcall aesni_aes192_encrypt_block_( - AesNI_Aes_Block plaintext, - const AesNI_Aes192_RoundKeys* encryption_keys) +AesNI_AES_Block __fastcall aesni_AES192_encrypt_block_( + AesNI_AES_Block plaintext, + const AesNI_AES192_RoundKeys* encryption_keys) { plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]); plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[1]); @@ -30,9 +30,9 @@ AesNI_Aes_Block __fastcall aesni_aes192_encrypt_block_( return _mm_aesenclast_si128(plaintext, encryption_keys->keys[12]); } -AesNI_Aes_Block __fastcall aesni_aes192_decrypt_block_( - AesNI_Aes_Block ciphertext, - const AesNI_Aes192_RoundKeys* decryption_keys) +AesNI_AES_Block __fastcall aesni_AES192_decrypt_block_( + AesNI_AES_Block ciphertext, + const AesNI_AES192_RoundKeys* decryption_keys) { ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]); ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[1]); @@ -50,11 +50,11 @@ AesNI_Aes_Block __fastcall aesni_aes192_decrypt_block_( } static void __fastcall aesni_aes192_expand_key_assist( - AesNI_Aes_Block* prev_lo, - AesNI_Aes_Block* prev_hi, - AesNI_Aes_Block hwgen) + AesNI_AES_Block* prev_lo, + AesNI_AES_Block* prev_hi, + AesNI_AES_Block hwgen) { - AesNI_Aes_Block tmp = *prev_lo; + AesNI_AES_Block tmp = *prev_lo; tmp = _mm_slli_si128(tmp, 4); *prev_lo = _mm_xor_si128(*prev_lo, tmp); @@ -74,10 +74,10 @@ static void __fastcall aesni_aes192_expand_key_assist( *prev_hi = _mm_xor_si128(*prev_hi, tmp); } -void __fastcall aesni_aes192_expand_key_( - AesNI_Aes_Block key_lo, - AesNI_Aes_Block key_hi, - AesNI_Aes192_RoundKeys* encryption_keys) +void __fastcall aesni_AES192_expand_key_( + AesNI_AES_Block key_lo, + AesNI_AES_Block key_hi, + AesNI_AES192_RoundKeys* encryption_keys) { encryption_keys->keys[0] = key_lo; encryption_keys->keys[1] = key_hi; @@ -114,9 +114,9 @@ void __fastcall aesni_aes192_expand_key_( encryption_keys->keys[12] = key_lo; } -void __fastcall aesni_aes192_derive_decryption_keys_( - const AesNI_Aes192_RoundKeys* encryption_keys, - AesNI_Aes192_RoundKeys* decryption_keys) +void __fastcall aesni_AES192_derive_decryption_keys_( + const AesNI_AES192_RoundKeys* encryption_keys, + AesNI_AES192_RoundKeys* decryption_keys) { decryption_keys->keys[0] = encryption_keys->keys[12]; decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[11]); diff --git a/src/c/aes256.c b/src/c/aes256.c index 243ec03..6099204 100644 --- a/src/c/aes256.c +++ b/src/c/aes256.c @@ -11,9 +11,9 @@ #include #include -AesNI_Aes_Block __fastcall aesni_aes256_encrypt_block_( - AesNI_Aes_Block plaintext, - const AesNI_Aes256_RoundKeys* encryption_keys) +AesNI_AES_Block __fastcall aesni_AES256_encrypt_block_( + AesNI_AES_Block plaintext, + const AesNI_AES256_RoundKeys* encryption_keys) { plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]); plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[1]); @@ -32,9 +32,9 @@ AesNI_Aes_Block __fastcall aesni_aes256_encrypt_block_( return _mm_aesenclast_si128(plaintext, encryption_keys->keys[14]); } -AesNI_Aes_Block __fastcall aesni_aes256_decrypt_block_( - AesNI_Aes_Block ciphertext, - const AesNI_Aes256_RoundKeys* decryption_keys) +AesNI_AES_Block __fastcall aesni_AES256_decrypt_block_( + AesNI_AES_Block ciphertext, + const AesNI_AES256_RoundKeys* decryption_keys) { ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]); ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[1]); @@ -53,12 +53,12 @@ AesNI_Aes_Block __fastcall aesni_aes256_decrypt_block_( return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[14]); } -static AesNI_Aes_Block __fastcall aesni_aes256_expand_key_assist( - AesNI_Aes_Block* prev_lo, - AesNI_Aes_Block* prev_hi, - AesNI_Aes_Block hwgen) +static AesNI_AES_Block __fastcall aesni_aes256_expand_key_assist( + AesNI_AES_Block* prev_lo, + AesNI_AES_Block* prev_hi, + AesNI_AES_Block hwgen) { - AesNI_Aes_Block tmp = *prev_lo; + AesNI_AES_Block tmp = *prev_lo; tmp = _mm_slli_si128(tmp, 4); *prev_lo = _mm_xor_si128(*prev_lo, tmp); @@ -76,13 +76,13 @@ static AesNI_Aes_Block __fastcall aesni_aes256_expand_key_assist( return *prev_hi; } -void __fastcall aesni_aes256_expand_key_( - AesNI_Aes_Block key_lo, - AesNI_Aes_Block key_hi, - AesNI_Aes256_RoundKeys* encryption_keys) +void __fastcall aesni_AES256_expand_key_( + AesNI_AES_Block key_lo, + AesNI_AES_Block key_hi, + AesNI_AES256_RoundKeys* encryption_keys) { - AesNI_Aes_Block prev_lo, prev_hi; - AesNI_Aes_Block hwgen; + AesNI_AES_Block prev_lo, prev_hi; + AesNI_AES_Block hwgen; prev_lo = encryption_keys->keys[0] = key_lo; prev_hi = encryption_keys->keys[1] = key_hi; @@ -140,9 +140,9 @@ void __fastcall aesni_aes256_expand_key_( encryption_keys->keys[14] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); } -void __fastcall aesni_aes256_derive_decryption_keys_( - const AesNI_Aes256_RoundKeys* encryption_keys, - AesNI_Aes256_RoundKeys* decryption_keys) +void __fastcall aesni_AES256_derive_decryption_keys_( + const AesNI_AES256_RoundKeys* encryption_keys, + AesNI_AES256_RoundKeys* decryption_keys) { decryption_keys->keys[0] = encryption_keys->keys[14]; decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[13]); -- cgit v1.2.3