diff options
author | Jack Lloyd <[email protected]> | 2020-10-09 20:34:56 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2020-10-09 20:34:56 -0400 |
commit | c7b26c732bcd8830c47aaf7fda40e5b028cfb280 (patch) | |
tree | d2da3490f4a2e78af0d8de2b0d86ba2d97b65e10 /src/lib | |
parent | 42891f601f06b00f1866b36b4678e242fa8c3627 (diff) | |
parent | 805c141086ab80c97e5b38fc63411634314e4544 (diff) |
Merge GH #2418 Batch InvMixColumns so SIMD can be used
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/block/aes/aes.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/lib/block/aes/aes.cpp b/src/lib/block/aes/aes.cpp index bf7ffd120..88d6e9027 100644 --- a/src/lib/block/aes/aes.cpp +++ b/src/lib/block/aes/aes.cpp @@ -649,6 +649,14 @@ inline uint32_t InvMixColumn(uint32_t s1) return s14 ^ rotr<8>(s9) ^ rotr<16>(s13) ^ rotr<24>(s11); } +void InvMixColumn_x4(uint32_t x[4]) + { + x[0] = InvMixColumn(x[0]); + x[1] = InvMixColumn(x[1]); + x[2] = InvMixColumn(x[2]); + x[3] = InvMixColumn(x[3]); + } + uint32_t SE_word(uint32_t x) { uint32_t I[8] = { 0 }; @@ -682,6 +690,9 @@ void aes_key_schedule(const uint8_t key[], size_t length, const size_t rounds = (length / 4) + 6; + // Help the optimizer + BOTAN_ASSERT_NOMSG(rounds == 10 || rounds == 12 || rounds == 14); + CT::poison(key, length); EK.resize(length + 28); @@ -705,21 +716,18 @@ void aes_key_schedule(const uint8_t key[], size_t length, } } - DK[0] = EK[4*rounds ]; - DK[1] = EK[4*rounds+1]; - DK[2] = EK[4*rounds+2]; - DK[3] = EK[4*rounds+3]; - - for(size_t i = 4; i != 4*rounds; ++i) + for(size_t i = 0; i != 4*(rounds+1); i += 4) { - const uint32_t K = EK[4*rounds - 4*(i/4) + (i%4)]; - DK[i] = InvMixColumn(K); + DK[i ] = EK[4*rounds - i ]; + DK[i+1] = EK[4*rounds - i+1]; + DK[i+2] = EK[4*rounds - i+2]; + DK[i+3] = EK[4*rounds - i+3]; } - DK[4*rounds ] = EK[0]; - DK[4*rounds+1] = EK[1]; - DK[4*rounds+2] = EK[2]; - DK[4*rounds+3] = EK[3]; + for(size_t i = 4; i != 4*rounds; i += 4) + { + InvMixColumn_x4(&DK[i]); + } if(bswap_keys) { |