diff options
Diffstat (limited to '')
-rw-r--r-- | src/asm/aes128.asm | 4 | ||||
-rw-r--r-- | src/asm/aes256.asm | 4 | ||||
-rw-r--r-- | src/buffer.c | 20 | ||||
-rw-r--r-- | src/c/aes128.c | 102 | ||||
-rw-r--r-- | src/c/aes192.c | 126 | ||||
-rw-r--r-- | src/c/aes256.c | 134 |
6 files changed, 195 insertions, 195 deletions
diff --git a/src/asm/aes128.asm b/src/asm/aes128.asm index 03a9ace..70d2010 100644 --- a/src/asm/aes128.asm +++ b/src/asm/aes128.asm @@ -167,7 +167,7 @@ aes128_keygen_assist: ret @aesni_aes128_expand_key_@20 endp -@aesni_aes128_derive_decryption_keys_raw@8 proc +@aesni_aes128_derive_decryption_keys_@8 proc movdqa xmm5, [ecx] movdqa xmm4, [ecx + 0A0h] movdqa [edx], xmm4 @@ -197,6 +197,6 @@ aes128_keygen_assist: movdqa [edx + 50h], xmm5 ret -@aesni_aes128_derive_decryption_keys_raw@8 endp +@aesni_aes128_derive_decryption_keys_@8 endp end diff --git a/src/asm/aes256.asm b/src/asm/aes256.asm index f1c3eaf..9f1e735 100644 --- a/src/asm/aes256.asm +++ b/src/asm/aes256.asm @@ -241,7 +241,7 @@ aes256_keygen_assist: ret @aesni_aes256_expand_key_@36 endp -@aesni_aes256_derive_decryption_keys_raw@8 proc +@aesni_aes256_derive_decryption_keys_@8 proc movdqa xmm5, [ecx] movdqa xmm4, [ecx + 0E0h] movdqa [edx], xmm4 @@ -281,6 +281,6 @@ aes256_keygen_assist: movdqa [edx + 70h], xmm5 ret -@aesni_aes256_derive_decryption_keys_raw@8 endp +@aesni_aes256_derive_decryption_keys_@8 endp end diff --git a/src/buffer.c b/src/buffer.c index 983c5cf..80120db 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -18,7 +18,7 @@ AesNI_StatusCode aesni_encrypt_buffer_ecb128( size_t src_size, void* dest, size_t* dest_size, - AesNI_Aes128_RoundKeys* key_schedule, + AesNI_Aes128_RoundKeys* encryption_keys, AesNI_ErrorDetails* err_details) { if (dest_size == NULL) @@ -32,15 +32,15 @@ AesNI_StatusCode aesni_encrypt_buffer_ecb128( return AESNI_SUCCESS; if (src == NULL) return aesni_make_null_argument_error(err_details, "src"); - if (key_schedule == NULL) - return aesni_make_null_argument_error(err_details, "key_schedule"); + if (encryption_keys == NULL) + return aesni_make_null_argument_error(err_details, "encryption_keys"); const size_t src_len = src_size / 16; for (size_t i = 0; i < src_len; ++i, (char*) src += 16, (char*) dest += 16) { AesNI_Block128 plaintext = aesni_load_block128(src); - AesNI_Block128 ciphertext = aesni_aes128_encrypt_block_ecb(plaintext, key_schedule); + AesNI_Block128 ciphertext = aesni_aes128_encrypt_block_ecb(plaintext, encryption_keys); aesni_store_block128(dest, ciphertext); } @@ -57,7 +57,7 @@ AesNI_StatusCode aesni_encrypt_buffer_ecb128( } AesNI_Block128 plaintext = aesni_load_block128(padding); - AesNI_Block128 ciphertext = aesni_aes128_encrypt_block_ecb(plaintext, key_schedule); + AesNI_Block128 ciphertext = aesni_aes128_encrypt_block_ecb(plaintext, encryption_keys); aesni_store_block128(dest, ciphertext); return AESNI_SUCCESS; @@ -80,7 +80,7 @@ AesNI_StatusCode aesni_decrypt_buffer_ecb128( size_t src_size, void* dest, size_t* dest_size, - AesNI_Aes128_RoundKeys* inverted_schedule, + AesNI_Aes128_RoundKeys* decryption_keys, AesNI_ErrorDetails* err_details) { if (dest_size == NULL) @@ -92,20 +92,20 @@ AesNI_StatusCode aesni_decrypt_buffer_ecb128( return 0; if (src == NULL) return aesni_make_null_argument_error(err_details, "src"); - if (inverted_schedule == NULL) - return aesni_make_null_argument_error(err_details, "inverted_schedule"); + if (decryption_keys == NULL) + return aesni_make_null_argument_error(err_details, "decryption_keys"); const size_t src_len = src_size / 16; for (size_t i = 0; i < src_len - 1; ++i, (char*) src += 16, (char*) dest += 16) { AesNI_Block128 ciphertext = aesni_load_block128(src); - AesNI_Block128 plaintext = aesni_aes128_decrypt_block_ecb(ciphertext, inverted_schedule); + AesNI_Block128 plaintext = aesni_aes128_decrypt_block_ecb(ciphertext, decryption_keys); aesni_store_block128(dest, plaintext); } AesNI_Block128 ciphertext = aesni_load_block128(src); - AesNI_Block128 plaintext = aesni_aes128_decrypt_block_ecb(ciphertext, inverted_schedule); + AesNI_Block128 plaintext = aesni_aes128_decrypt_block_ecb(ciphertext, decryption_keys); unsigned char padding[16]; aesni_store_block128(padding, plaintext); 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]; } diff --git a/src/c/aes192.c b/src/c/aes192.c index d6ecea1..6e97637 100644 --- a/src/c/aes192.c +++ b/src/c/aes192.c @@ -12,41 +12,41 @@ #include <wmmintrin.h> AesNI_Block128 __fastcall aesni_aes192_encrypt_block_( - AesNI_Block128 plain, - const AesNI_Aes192_RoundKeys* key_schedule) + AesNI_Block128 plaintext, + const AesNI_Aes192_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]); - plain = _mm_aesenc_si128(plain, key_schedule->keys[10]); - plain = _mm_aesenc_si128(plain, key_schedule->keys[11]); - return _mm_aesenclast_si128(plain, key_schedule->keys[12]); + 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]); + plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[10]); + plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[11]); + return _mm_aesenclast_si128(plaintext, encryption_keys->keys[12]); } AesNI_Block128 __fastcall aesni_aes192_decrypt_block_( - AesNI_Block128 cipher, - const AesNI_Aes192_RoundKeys* inverted_schedule) + AesNI_Block128 ciphertext, + const AesNI_Aes192_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]); - cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[10]); - cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[11]); - return _mm_aesdeclast_si128(cipher, inverted_schedule->keys[12]); + 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]); + ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[10]); + ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[11]); + return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[12]); } static void __fastcall aesni_aes192_expand_key_assist( @@ -77,58 +77,58 @@ static void __fastcall aesni_aes192_expand_key_assist( void __fastcall aesni_aes192_expand_key_( AesNI_Block128 key_lo, AesNI_Block128 key_hi, - AesNI_Aes192_RoundKeys* key_schedule) + AesNI_Aes192_RoundKeys* encryption_keys) { - key_schedule->keys[0] = key_lo; - key_schedule->keys[1] = key_hi; + encryption_keys->keys[0] = key_lo; + encryption_keys->keys[1] = key_hi; aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x01)); - key_schedule->keys[1] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_schedule->keys[1]), _mm_castsi128_pd(key_lo), 0)); - key_schedule->keys[2] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); + encryption_keys->keys[1] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[1]), _mm_castsi128_pd(key_lo), 0)); + encryption_keys->keys[2] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x02)); - key_schedule->keys[3] = key_lo; - key_schedule->keys[4] = key_hi; + encryption_keys->keys[3] = key_lo; + encryption_keys->keys[4] = key_hi; aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x04)); - key_schedule->keys[4] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_schedule->keys[4]), _mm_castsi128_pd(key_lo), 0)); - key_schedule->keys[5] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); + encryption_keys->keys[4] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[4]), _mm_castsi128_pd(key_lo), 0)); + encryption_keys->keys[5] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x08)); - key_schedule->keys[6] = key_lo; - key_schedule->keys[7] = key_hi; + encryption_keys->keys[6] = key_lo; + encryption_keys->keys[7] = key_hi; aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x10)); - key_schedule->keys[7] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_schedule->keys[7]), _mm_castsi128_pd(key_lo), 0)); - key_schedule->keys[8] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); + encryption_keys->keys[7] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[7]), _mm_castsi128_pd(key_lo), 0)); + encryption_keys->keys[8] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x20)); - key_schedule->keys[9] = key_lo; - key_schedule->keys[10] = key_hi; + encryption_keys->keys[9] = key_lo; + encryption_keys->keys[10] = key_hi; aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x40)); - key_schedule->keys[10] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_schedule->keys[10]), _mm_castsi128_pd(key_lo), 0)); - key_schedule->keys[11] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); + encryption_keys->keys[10] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[10]), _mm_castsi128_pd(key_lo), 0)); + encryption_keys->keys[11] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x80)); - key_schedule->keys[12] = key_lo; + encryption_keys->keys[12] = key_lo; } void __fastcall aesni_aes192_derive_decryption_keys_( - const AesNI_Aes192_RoundKeys* key_schedule, - AesNI_Aes192_RoundKeys* inverted_schedule) + const AesNI_Aes192_RoundKeys* encryption_keys, + AesNI_Aes192_RoundKeys* decryption_keys) { - inverted_schedule->keys[0] = key_schedule->keys[12]; - inverted_schedule->keys[1] = _mm_aesimc_si128(key_schedule->keys[11]); - inverted_schedule->keys[2] = _mm_aesimc_si128(key_schedule->keys[10]); - inverted_schedule->keys[3] = _mm_aesimc_si128(key_schedule->keys[9]); - inverted_schedule->keys[4] = _mm_aesimc_si128(key_schedule->keys[8]); - inverted_schedule->keys[5] = _mm_aesimc_si128(key_schedule->keys[7]); - inverted_schedule->keys[6] = _mm_aesimc_si128(key_schedule->keys[6]); - inverted_schedule->keys[7] = _mm_aesimc_si128(key_schedule->keys[5]); - inverted_schedule->keys[8] = _mm_aesimc_si128(key_schedule->keys[4]); - inverted_schedule->keys[9] = _mm_aesimc_si128(key_schedule->keys[3]); - inverted_schedule->keys[10] = _mm_aesimc_si128(key_schedule->keys[2]); - inverted_schedule->keys[11] = _mm_aesimc_si128(key_schedule->keys[1]); - inverted_schedule->keys[12] = key_schedule->keys[0]; + decryption_keys->keys[0] = encryption_keys->keys[12]; + decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[11]); + decryption_keys->keys[2] = _mm_aesimc_si128(encryption_keys->keys[10]); + decryption_keys->keys[3] = _mm_aesimc_si128(encryption_keys->keys[9]); + decryption_keys->keys[4] = _mm_aesimc_si128(encryption_keys->keys[8]); + decryption_keys->keys[5] = _mm_aesimc_si128(encryption_keys->keys[7]); + decryption_keys->keys[6] = _mm_aesimc_si128(encryption_keys->keys[6]); + decryption_keys->keys[7] = _mm_aesimc_si128(encryption_keys->keys[5]); + decryption_keys->keys[8] = _mm_aesimc_si128(encryption_keys->keys[4]); + decryption_keys->keys[9] = _mm_aesimc_si128(encryption_keys->keys[3]); + decryption_keys->keys[10] = _mm_aesimc_si128(encryption_keys->keys[2]); + decryption_keys->keys[11] = _mm_aesimc_si128(encryption_keys->keys[1]); + decryption_keys->keys[12] = encryption_keys->keys[0]; } diff --git a/src/c/aes256.c b/src/c/aes256.c index 05e643e..820010d 100644 --- a/src/c/aes256.c +++ b/src/c/aes256.c @@ -12,45 +12,45 @@ #include <wmmintrin.h> AesNI_Block128 __fastcall aesni_aes256_encrypt_block_( - AesNI_Block128 plain, - const AesNI_Aes256_RoundKeys* key_schedule) + AesNI_Block128 plaintext, + const AesNI_Aes256_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]); - plain = _mm_aesenc_si128(plain, key_schedule->keys[10]); - plain = _mm_aesenc_si128(plain, key_schedule->keys[11]); - plain = _mm_aesenc_si128(plain, key_schedule->keys[12]); - plain = _mm_aesenc_si128(plain, key_schedule->keys[13]); - return _mm_aesenclast_si128(plain, key_schedule->keys[14]); + 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]); + plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[10]); + plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[11]); + plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[12]); + plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[13]); + return _mm_aesenclast_si128(plaintext, encryption_keys->keys[14]); } AesNI_Block128 __fastcall aesni_aes256_decrypt_block_( - AesNI_Block128 cipher, - const AesNI_Aes256_RoundKeys* inverted_schedule) + AesNI_Block128 ciphertext, + const AesNI_Aes256_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]); - cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[10]); - cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[11]); - cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[12]); - cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[13]); - return _mm_aesdeclast_si128(cipher, inverted_schedule->keys[14]); + 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]); + ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[10]); + ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[11]); + ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[12]); + ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[13]); + return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[14]); } static AesNI_Block128 __fastcall aesni_aes256_expand_key_assist( @@ -79,84 +79,84 @@ static AesNI_Block128 __fastcall aesni_aes256_expand_key_assist( void __fastcall aesni_aes256_expand_key_( AesNI_Block128 key_lo, AesNI_Block128 key_hi, - AesNI_Aes256_RoundKeys* key_schedule) + AesNI_Aes256_RoundKeys* encryption_keys) { AesNI_Block128 prev_lo, prev_hi; AesNI_Block128 hwgen; - prev_lo = key_schedule->keys[0] = key_lo; - prev_hi = key_schedule->keys[1] = key_hi; + prev_lo = encryption_keys->keys[0] = key_lo; + prev_hi = encryption_keys->keys[1] = key_hi; hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x01); hwgen = _mm_shuffle_epi32(hwgen, 0xff); - key_schedule->keys[2] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[2] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0); hwgen = _mm_shuffle_epi32(hwgen, 0xaa); - key_schedule->keys[3] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[3] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x02); hwgen = _mm_shuffle_epi32(hwgen, 0xff); - key_schedule->keys[4] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[4] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0); hwgen = _mm_shuffle_epi32(hwgen, 0xaa); - key_schedule->keys[5] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[5] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x04); hwgen = _mm_shuffle_epi32(hwgen, 0xff); - key_schedule->keys[6] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[6] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0); hwgen = _mm_shuffle_epi32(hwgen, 0xaa); - key_schedule->keys[7] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[7] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x08); hwgen = _mm_shuffle_epi32(hwgen, 0xff); - key_schedule->keys[8] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[8] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0); hwgen = _mm_shuffle_epi32(hwgen, 0xaa); - key_schedule->keys[9] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[9] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x10); hwgen = _mm_shuffle_epi32(hwgen, 0xff); - key_schedule->keys[10] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[10] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0); hwgen = _mm_shuffle_epi32(hwgen, 0xaa); - key_schedule->keys[11] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[11] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x20); hwgen = _mm_shuffle_epi32(hwgen, 0xff); - key_schedule->keys[12] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[12] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0); hwgen = _mm_shuffle_epi32(hwgen, 0xaa); - key_schedule->keys[13] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + encryption_keys->keys[13] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x40); hwgen = _mm_shuffle_epi32(hwgen, 0xff); - key_schedule->keys[14] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); + 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* key_schedule, - AesNI_Aes256_RoundKeys* inverted_schedule) + const AesNI_Aes256_RoundKeys* encryption_keys, + AesNI_Aes256_RoundKeys* decryption_keys) { - inverted_schedule->keys[0] = key_schedule->keys[14]; - inverted_schedule->keys[1] = _mm_aesimc_si128(key_schedule->keys[13]); - inverted_schedule->keys[2] = _mm_aesimc_si128(key_schedule->keys[12]); - inverted_schedule->keys[3] = _mm_aesimc_si128(key_schedule->keys[11]); - inverted_schedule->keys[4] = _mm_aesimc_si128(key_schedule->keys[10]); - inverted_schedule->keys[5] = _mm_aesimc_si128(key_schedule->keys[9]); - inverted_schedule->keys[6] = _mm_aesimc_si128(key_schedule->keys[8]); - inverted_schedule->keys[7] = _mm_aesimc_si128(key_schedule->keys[7]); - inverted_schedule->keys[8] = _mm_aesimc_si128(key_schedule->keys[6]); - inverted_schedule->keys[9] = _mm_aesimc_si128(key_schedule->keys[5]); - inverted_schedule->keys[10] = _mm_aesimc_si128(key_schedule->keys[4]); - inverted_schedule->keys[11] = _mm_aesimc_si128(key_schedule->keys[3]); - inverted_schedule->keys[12] = _mm_aesimc_si128(key_schedule->keys[2]); - inverted_schedule->keys[13] = _mm_aesimc_si128(key_schedule->keys[1]); - inverted_schedule->keys[14] = key_schedule->keys[0]; + decryption_keys->keys[0] = encryption_keys->keys[14]; + decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[13]); + decryption_keys->keys[2] = _mm_aesimc_si128(encryption_keys->keys[12]); + decryption_keys->keys[3] = _mm_aesimc_si128(encryption_keys->keys[11]); + decryption_keys->keys[4] = _mm_aesimc_si128(encryption_keys->keys[10]); + decryption_keys->keys[5] = _mm_aesimc_si128(encryption_keys->keys[9]); + decryption_keys->keys[6] = _mm_aesimc_si128(encryption_keys->keys[8]); + decryption_keys->keys[7] = _mm_aesimc_si128(encryption_keys->keys[7]); + decryption_keys->keys[8] = _mm_aesimc_si128(encryption_keys->keys[6]); + decryption_keys->keys[9] = _mm_aesimc_si128(encryption_keys->keys[5]); + decryption_keys->keys[10] = _mm_aesimc_si128(encryption_keys->keys[4]); + decryption_keys->keys[11] = _mm_aesimc_si128(encryption_keys->keys[3]); + decryption_keys->keys[12] = _mm_aesimc_si128(encryption_keys->keys[2]); + decryption_keys->keys[13] = _mm_aesimc_si128(encryption_keys->keys[1]); + decryption_keys->keys[14] = encryption_keys->keys[0]; } |