From 9fd5d023f9231f1c5f8ec7241aaf31d624334422 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Wed, 20 Sep 2017 20:27:58 -0400 Subject: [PATCH] Load r5 mask once for key expansion --- rijndael-simd.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/rijndael-simd.cpp b/rijndael-simd.cpp index f1472a9f..9f8102df 100644 --- a/rijndael-simd.cpp +++ b/rijndael-simd.cpp @@ -1060,22 +1060,23 @@ static inline T1 VectorDecryptLast(const T1& state, const T2& key) ////////////////////////////////////////////////////////////////// /* Round constants */ +CRYPTOPP_ALIGN_DATA(16) static const uint32_t s_rcon[3][4] = { {0x01<<24,0x01<<24,0x01<<24,0x01<<24}, /* 1 */ {0x1b<<24,0x1b<<24,0x1b<<24,0x1b<<24}, /* 9 */ {0x36<<24,0x36<<24,0x36<<24,0x36<<24} /* 10 */ }; +/* Permute mask */ +CRYPTOPP_ALIGN_DATA(16) static const uint32_t s_mask[4] = { 0x0d0e0f0c, 0x0d0e0f0c, 0x0d0e0f0c, 0x0d0e0f0c }; static inline uint8x16_p8 -Rijndael_Subkey_POWER8(uint8x16_p8 r1, const uint8x16_p8 r4) +Rijndael_Subkey_POWER8(uint8x16_p8 r1, const uint8x16_p8 r4, const uint8x16_p8 r5) { - const uint8x16_p8 r5 = (uint8x16_p8)VectorLoad(s_mask); const uint8x16_p8 r0 = {0}; - uint8x16_p8 r3, r6; r3 = vec_perm(r1, r1, r5); /* line 1 */ @@ -1104,12 +1105,13 @@ void Rijndael_UncheckedSetKey_POWER8(word32* rk, size_t keyLen, const word32* rc if (keyLen == 16) { uint8_t* skptr = (uint8_t*)rk; - uint8x16_p8 r1 = (uint8x16_p8)VectorLoadKey((uint8_t*)skptr); - uint8x16_p8 r4 = (uint8x16_p8)VectorLoad(s_rcon[0]); + uint8x16_p8 r1 = (uint8x16_p8)VectorLoad((uint8_t*)skptr); + uint8x16_p8 r4 = (uint8x16_p8)VectorLoadKey(s_rcon[0]); + uint8x16_p8 r5 = (uint8x16_p8)VectorLoadKey(s_mask); for (unsigned int i=0; i