aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/block/serpent/serpent_simd/serpent_simd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/block/serpent/serpent_simd/serpent_simd.cpp')
-rw-r--r--src/lib/block/serpent/serpent_simd/serpent_simd.cpp53
1 files changed, 9 insertions, 44 deletions
diff --git a/src/lib/block/serpent/serpent_simd/serpent_simd.cpp b/src/lib/block/serpent/serpent_simd/serpent_simd.cpp
index 5d1bc28f2..1a3c85568 100644
--- a/src/lib/block/serpent/serpent_simd/serpent_simd.cpp
+++ b/src/lib/block/serpent/serpent_simd/serpent_simd.cpp
@@ -6,55 +6,18 @@
*/
#include <botan/internal/serpent.h>
-#include <botan/internal/serpent_sbox.h>
#include <botan/internal/simd_32.h>
+#include <botan/internal/serpent_sbox.h>
namespace Botan {
-#define key_xor(round, B0, B1, B2, B3) \
- do { \
- B0 ^= SIMD_4x32::splat(m_round_key[4*round ]); \
- B1 ^= SIMD_4x32::splat(m_round_key[4*round+1]); \
- B2 ^= SIMD_4x32::splat(m_round_key[4*round+2]); \
- B3 ^= SIMD_4x32::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)
-
/*
* SIMD Serpent Encryption of 4 blocks in parallel
*/
void Serpent::simd_encrypt_4(const uint8_t in[64], uint8_t out[64]) const
{
+ using namespace Botan::Serpent_F;
+
SIMD_4x32 B0 = SIMD_4x32::load_le(in);
SIMD_4x32 B1 = SIMD_4x32::load_le(in + 16);
SIMD_4x32 B2 = SIMD_4x32::load_le(in + 32);
@@ -62,6 +25,8 @@ void Serpent::simd_encrypt_4(const uint8_t in[64], uint8_t out[64]) const
SIMD_4x32::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);
@@ -111,6 +76,8 @@ void Serpent::simd_encrypt_4(const uint8_t in[64], uint8_t out[64]) const
*/
void Serpent::simd_decrypt_4(const uint8_t in[64], uint8_t out[64]) const
{
+ using namespace Botan::Serpent_F;
+
SIMD_4x32 B0 = SIMD_4x32::load_le(in);
SIMD_4x32 B1 = SIMD_4x32::load_le(in + 16);
SIMD_4x32 B2 = SIMD_4x32::load_le(in + 32);
@@ -118,6 +85,8 @@ void Serpent::simd_decrypt_4(const uint8_t in[64], uint8_t out[64]) const
SIMD_4x32::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 +131,4 @@ void Serpent::simd_decrypt_4(const uint8_t in[64], uint8_t out[64]) const
B3.store_le(out + 48);
}
-#undef key_xor
-#undef transform
-#undef i_transform
-
}