diff options
Diffstat (limited to 'src/lib/block/serpent/serpent_avx2/serpent_avx2.cpp')
-rw-r--r-- | src/lib/block/serpent/serpent_avx2/serpent_avx2.cpp | 57 |
1 files changed, 12 insertions, 45 deletions
diff --git a/src/lib/block/serpent/serpent_avx2/serpent_avx2.cpp b/src/lib/block/serpent/serpent_avx2/serpent_avx2.cpp index 028ee77e5..03629a890 100644 --- a/src/lib/block/serpent/serpent_avx2/serpent_avx2.cpp +++ b/src/lib/block/serpent/serpent_avx2/serpent_avx2.cpp @@ -5,54 +5,16 @@ */ #include <botan/internal/serpent.h> -#include <botan/internal/serpent_sbox.h> #include <botan/internal/simd_avx2.h> +#include <botan/internal/serpent_sbox.h> namespace Botan { - -#define key_xor(round, B0, B1, B2, B3) \ - do { \ - B0 ^= SIMD_8x32::splat(m_round_key[4*round ]); \ - B1 ^= SIMD_8x32::splat(m_round_key[4*round+1]); \ - B2 ^= SIMD_8x32::splat(m_round_key[4*round+2]); \ - B3 ^= SIMD_8x32::splat(m_round_key[4*round+3]); \ - } while(0) - -/* -* Serpent's linear transformations -*/ -#define transform(B0, B1, B2, B3) \ - do { \ - B0 = B0.rotl<13>(); \ - B2 = B2.rotl<3>(); \ - B1 ^= B0 ^ B2; \ - B3 ^= B2 ^ B0.shl<3>(); \ - B1 = B1.rotl<1>(); \ - B3 = B3.rotl<7>(); \ - B0 ^= B1 ^ B3; \ - B2 ^= B3 ^ B1.shl<7>(); \ - B0 = B0.rotl<5>(); \ - B2 = B2.rotl<22>(); \ - } while(0) - -#define i_transform(B0, B1, B2, B3) \ - do { \ - B2 = B2.rotr<22>(); \ - B0 = B0.rotr<5>(); \ - B2 ^= B3 ^ B1.shl<7>(); \ - B0 ^= B1 ^ B3; \ - B3 = B3.rotr<7>(); \ - B1 = B1.rotr<1>(); \ - B3 ^= B2 ^ B0.shl<3>(); \ - B1 ^= B0 ^ B2; \ - B2 = B2.rotr<3>(); \ - B0 = B0.rotr<13>(); \ - } while(0) - BOTAN_FUNC_ISA("avx2") void Serpent::avx2_encrypt_8(const uint8_t in[128], uint8_t out[128]) const { + using namespace Botan::Serpent_F; + SIMD_8x32::reset_registers(); SIMD_8x32 B0 = SIMD_8x32::load_le(in); @@ -62,6 +24,8 @@ void Serpent::avx2_encrypt_8(const uint8_t in[128], uint8_t out[128]) const SIMD_8x32::transpose(B0, B1, B2, B3); + const Key_Inserter key_xor(m_round_key.data()); + key_xor( 0,B0,B1,B2,B3); SBoxE0(B0,B1,B2,B3); transform(B0,B1,B2,B3); key_xor( 1,B0,B1,B2,B3); SBoxE1(B0,B1,B2,B3); transform(B0,B1,B2,B3); key_xor( 2,B0,B1,B2,B3); SBoxE2(B0,B1,B2,B3); transform(B0,B1,B2,B3); @@ -70,6 +34,7 @@ void Serpent::avx2_encrypt_8(const uint8_t in[128], uint8_t out[128]) const key_xor( 5,B0,B1,B2,B3); SBoxE5(B0,B1,B2,B3); transform(B0,B1,B2,B3); key_xor( 6,B0,B1,B2,B3); SBoxE6(B0,B1,B2,B3); transform(B0,B1,B2,B3); key_xor( 7,B0,B1,B2,B3); SBoxE7(B0,B1,B2,B3); transform(B0,B1,B2,B3); + key_xor( 8,B0,B1,B2,B3); SBoxE0(B0,B1,B2,B3); transform(B0,B1,B2,B3); key_xor( 9,B0,B1,B2,B3); SBoxE1(B0,B1,B2,B3); transform(B0,B1,B2,B3); key_xor(10,B0,B1,B2,B3); SBoxE2(B0,B1,B2,B3); transform(B0,B1,B2,B3); @@ -78,6 +43,7 @@ void Serpent::avx2_encrypt_8(const uint8_t in[128], uint8_t out[128]) const key_xor(13,B0,B1,B2,B3); SBoxE5(B0,B1,B2,B3); transform(B0,B1,B2,B3); key_xor(14,B0,B1,B2,B3); SBoxE6(B0,B1,B2,B3); transform(B0,B1,B2,B3); key_xor(15,B0,B1,B2,B3); SBoxE7(B0,B1,B2,B3); transform(B0,B1,B2,B3); + key_xor(16,B0,B1,B2,B3); SBoxE0(B0,B1,B2,B3); transform(B0,B1,B2,B3); key_xor(17,B0,B1,B2,B3); SBoxE1(B0,B1,B2,B3); transform(B0,B1,B2,B3); key_xor(18,B0,B1,B2,B3); SBoxE2(B0,B1,B2,B3); transform(B0,B1,B2,B3); @@ -86,6 +52,7 @@ void Serpent::avx2_encrypt_8(const uint8_t in[128], uint8_t out[128]) const key_xor(21,B0,B1,B2,B3); SBoxE5(B0,B1,B2,B3); transform(B0,B1,B2,B3); key_xor(22,B0,B1,B2,B3); SBoxE6(B0,B1,B2,B3); transform(B0,B1,B2,B3); key_xor(23,B0,B1,B2,B3); SBoxE7(B0,B1,B2,B3); transform(B0,B1,B2,B3); + key_xor(24,B0,B1,B2,B3); SBoxE0(B0,B1,B2,B3); transform(B0,B1,B2,B3); key_xor(25,B0,B1,B2,B3); SBoxE1(B0,B1,B2,B3); transform(B0,B1,B2,B3); key_xor(26,B0,B1,B2,B3); SBoxE2(B0,B1,B2,B3); transform(B0,B1,B2,B3); @@ -107,6 +74,8 @@ void Serpent::avx2_encrypt_8(const uint8_t in[128], uint8_t out[128]) const BOTAN_FUNC_ISA("avx2") void Serpent::avx2_decrypt_8(const uint8_t in[128], uint8_t out[128]) const { + using namespace Botan::Serpent_F; + SIMD_8x32::reset_registers(); SIMD_8x32 B0 = SIMD_8x32::load_le(in); @@ -116,6 +85,8 @@ void Serpent::avx2_decrypt_8(const uint8_t in[128], uint8_t out[128]) const SIMD_8x32::transpose(B0, B1, B2, B3); + const Key_Inserter key_xor(m_round_key.data()); + key_xor(32,B0,B1,B2,B3); SBoxD7(B0,B1,B2,B3); key_xor(31,B0,B1,B2,B3); i_transform(B0,B1,B2,B3); SBoxD6(B0,B1,B2,B3); key_xor(30,B0,B1,B2,B3); i_transform(B0,B1,B2,B3); SBoxD5(B0,B1,B2,B3); key_xor(29,B0,B1,B2,B3); @@ -162,8 +133,4 @@ void Serpent::avx2_decrypt_8(const uint8_t in[128], uint8_t out[128]) const SIMD_8x32::zero_registers(); } -#undef key_xor -#undef transform -#undef i_transform - } |