diff options
Diffstat (limited to 'src/c/aes128.c')
-rw-r--r-- | src/c/aes128.c | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/src/c/aes128.c b/src/c/aes128.c index 49ebc4a..8f2da44 100644 --- a/src/c/aes128.c +++ b/src/c/aes128.c @@ -12,37 +12,37 @@ #include <wmmintrin.h> AesNI_Block128 __fastcall aesni_aes128_encrypt_block_( - AesNI_Block128 plain, - const AesNI_Aes128_RoundKeys* key_schedule) + AesNI_Block128 plaintext, + const AesNI_Aes128_RoundKeys* encryption_keys) { - plain = _mm_xor_si128(plain, key_schedule->keys[0]); - plain = _mm_aesenc_si128(plain, key_schedule->keys[1]); - plain = _mm_aesenc_si128(plain, key_schedule->keys[2]); - plain = _mm_aesenc_si128(plain, key_schedule->keys[3]); - plain = _mm_aesenc_si128(plain, key_schedule->keys[4]); - plain = _mm_aesenc_si128(plain, key_schedule->keys[5]); - plain = _mm_aesenc_si128(plain, key_schedule->keys[6]); - plain = _mm_aesenc_si128(plain, key_schedule->keys[7]); - plain = _mm_aesenc_si128(plain, key_schedule->keys[8]); - plain = _mm_aesenc_si128(plain, key_schedule->keys[9]); - return _mm_aesenclast_si128(plain, key_schedule->keys[10]); + plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]); + plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[1]); + plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[2]); + plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[3]); + plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[4]); + plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[5]); + plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[6]); + plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[7]); + plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[8]); + plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[9]); + return _mm_aesenclast_si128(plaintext, encryption_keys->keys[10]); } AesNI_Block128 __fastcall aesni_aes128_decrypt_block_( - AesNI_Block128 cipher, - const AesNI_Aes128_RoundKeys* inverted_schedule) + AesNI_Block128 ciphertext, + const AesNI_Aes128_RoundKeys* decryption_keys) { - cipher = _mm_xor_si128(cipher, inverted_schedule->keys[0]); - cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[1]); - cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[2]); - cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[3]); - cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[4]); - cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[5]); - cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[6]); - cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[7]); - cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[8]); - cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[9]); - return _mm_aesdeclast_si128(cipher, inverted_schedule->keys[10]); + ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]); + ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[1]); + ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[2]); + ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[3]); + ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[4]); + ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[5]); + ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[6]); + ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[7]); + ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[8]); + ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[9]); + return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[10]); } static AesNI_Block128 __fastcall aesni_aes128_expand_key_assist( @@ -66,34 +66,34 @@ static AesNI_Block128 __fastcall aesni_aes128_expand_key_assist( void __fastcall aesni_aes128_expand_key_( AesNI_Block128 key, - AesNI_Aes128_RoundKeys* key_schedule) + AesNI_Aes128_RoundKeys* encryption_keys) { - AesNI_Block128 prev = key_schedule->keys[0] = key; - prev = key_schedule->keys[1] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x01)); - prev = key_schedule->keys[2] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x02)); - prev = key_schedule->keys[3] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x04)); - prev = key_schedule->keys[4] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x08)); - prev = key_schedule->keys[5] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x10)); - prev = key_schedule->keys[6] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x20)); - prev = key_schedule->keys[7] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x40)); - prev = key_schedule->keys[8] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x80)); - prev = key_schedule->keys[9] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x1b)); - prev = key_schedule->keys[10] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x36)); + AesNI_Block128 prev = encryption_keys->keys[0] = key; + prev = encryption_keys->keys[1] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x01)); + prev = encryption_keys->keys[2] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x02)); + prev = encryption_keys->keys[3] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x04)); + prev = encryption_keys->keys[4] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x08)); + prev = encryption_keys->keys[5] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x10)); + prev = encryption_keys->keys[6] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x20)); + prev = encryption_keys->keys[7] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x40)); + prev = encryption_keys->keys[8] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x80)); + prev = encryption_keys->keys[9] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x1b)); + 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* key_schedule, - AesNI_Aes128_RoundKeys* inverted_schedule) + const AesNI_Aes128_RoundKeys* encryption_keys, + AesNI_Aes128_RoundKeys* decryption_keys) { - inverted_schedule->keys[0] = key_schedule->keys[10]; - inverted_schedule->keys[1] = _mm_aesimc_si128(key_schedule->keys[9]); - inverted_schedule->keys[2] = _mm_aesimc_si128(key_schedule->keys[8]); - inverted_schedule->keys[3] = _mm_aesimc_si128(key_schedule->keys[7]); - inverted_schedule->keys[4] = _mm_aesimc_si128(key_schedule->keys[6]); - inverted_schedule->keys[5] = _mm_aesimc_si128(key_schedule->keys[5]); - inverted_schedule->keys[6] = _mm_aesimc_si128(key_schedule->keys[4]); - inverted_schedule->keys[7] = _mm_aesimc_si128(key_schedule->keys[3]); - inverted_schedule->keys[8] = _mm_aesimc_si128(key_schedule->keys[2]); - inverted_schedule->keys[9] = _mm_aesimc_si128(key_schedule->keys[1]); - inverted_schedule->keys[10] = key_schedule->keys[0]; + decryption_keys->keys[0] = encryption_keys->keys[10]; + decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[9]); + decryption_keys->keys[2] = _mm_aesimc_si128(encryption_keys->keys[8]); + decryption_keys->keys[3] = _mm_aesimc_si128(encryption_keys->keys[7]); + decryption_keys->keys[4] = _mm_aesimc_si128(encryption_keys->keys[6]); + decryption_keys->keys[5] = _mm_aesimc_si128(encryption_keys->keys[5]); + decryption_keys->keys[6] = _mm_aesimc_si128(encryption_keys->keys[4]); + decryption_keys->keys[7] = _mm_aesimc_si128(encryption_keys->keys[3]); + decryption_keys->keys[8] = _mm_aesimc_si128(encryption_keys->keys[2]); + decryption_keys->keys[9] = _mm_aesimc_si128(encryption_keys->keys[1]); + decryption_keys->keys[10] = encryption_keys->keys[0]; } |