aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-11-06 20:27:19 +0000
committerlloyd <[email protected]>2009-11-06 20:27:19 +0000
commitb5d4cf01a893718c8796652f3cf0f68b867bab94 (patch)
tree777e5f74160a2ca93b4d3372145740554a0340bf
parent1ad608c62edfefe6650a113ed40fe6425dd200e1 (diff)
Clean up aes_128_key_expansion
-rw-r--r--src/block/aes_intel/aes_intel.cpp42
1 files changed, 18 insertions, 24 deletions
diff --git a/src/block/aes_intel/aes_intel.cpp b/src/block/aes_intel/aes_intel.cpp
index 0dc44de9a..057728e72 100644
--- a/src/block/aes_intel/aes_intel.cpp
+++ b/src/block/aes_intel/aes_intel.cpp
@@ -14,17 +14,11 @@ namespace {
__m128i aes_128_key_expansion(__m128i key, __m128i key_with_rcon)
{
- key_with_rcon = _mm_shuffle_epi32(key_with_rcon, 0xff);
-
- __m128i T = _mm_slli_si128 (key, 0x4);
- key = _mm_xor_si128 (key, T);
- T = _mm_slli_si128 (T, 0x4);
- key = _mm_xor_si128 (key, T);
- T = _mm_slli_si128 (T, 0x4);
-
- key = _mm_xor_si128 (key, T);
- key = _mm_xor_si128 (key, key_with_rcon);
- return key;
+ key_with_rcon = _mm_shuffle_epi32(key_with_rcon, _MM_SHUFFLE(3,3,3,3));
+ key = _mm_xor_si128(key, _mm_slli_si128(key, 4));
+ key = _mm_xor_si128(key, _mm_slli_si128(key, 4));
+ key = _mm_xor_si128(key, _mm_slli_si128(key, 4));
+ return _mm_xor_si128(key, key_with_rcon);
}
}
@@ -124,23 +118,23 @@ void AES_128_Intel::decrypt_n(const byte in[], byte out[], u32bit blocks) const
/**
* AES Key Schedule
*/
-void AES_128_Intel::key_schedule(const byte key[], u32bit)
+void AES_128_Intel::key_schedule(const byte key[], u32bit length)
{
-#define AES_128_key_exp_with_rcon(K, RCON) \
- aes_128_key_expansion(K, _mm_aeskeygenassist_si128(K, RCON));
+ #define AES_128_key_exp(K, RCON) \
+ aes_128_key_expansion(K, _mm_aeskeygenassist_si128(K, RCON))
__m128i K0 = _mm_loadu_si128((const __m128i*)key);
- __m128i K1 = AES_128_key_exp_with_rcon(K0, 0x01);
- __m128i K2 = AES_128_key_exp_with_rcon(K1, 0x02);
- __m128i K3 = AES_128_key_exp_with_rcon(K2, 0x04);
- __m128i K4 = AES_128_key_exp_with_rcon(K3, 0x08);
- __m128i K5 = AES_128_key_exp_with_rcon(K4, 0x10);
- __m128i K6 = AES_128_key_exp_with_rcon(K5, 0x20);
- __m128i K7 = AES_128_key_exp_with_rcon(K6, 0x40);
- __m128i K8 = AES_128_key_exp_with_rcon(K7, 0x80);
- __m128i K9 = AES_128_key_exp_with_rcon(K8, 0x1B);
- __m128i K10 = AES_128_key_exp_with_rcon(K9, 0x36);
+ __m128i K1 = AES_128_key_exp(K0, 0x01);
+ __m128i K2 = AES_128_key_exp(K1, 0x02);
+ __m128i K3 = AES_128_key_exp(K2, 0x04);
+ __m128i K4 = AES_128_key_exp(K3, 0x08);
+ __m128i K5 = AES_128_key_exp(K4, 0x10);
+ __m128i K6 = AES_128_key_exp(K5, 0x20);
+ __m128i K7 = AES_128_key_exp(K6, 0x40);
+ __m128i K8 = AES_128_key_exp(K7, 0x80);
+ __m128i K9 = AES_128_key_exp(K8, 0x1B);
+ __m128i K10 = AES_128_key_exp(K9, 0x36);
__m128i* EK_mm = (__m128i*)&EK[0];
_mm_storeu_si128(EK_mm , K0);