aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/block/noekeon
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-11-03 10:11:33 -0400
committerJack Lloyd <[email protected]>2016-11-03 10:11:33 -0400
commit1e72720661383466807ac496b941af41d756a2ce (patch)
treecfdc0e8ab355061207345a53904f3606b6457e8b /src/lib/block/noekeon
parent0c1900d1d86c7a8928d29d162e33da49aa55b0f9 (diff)
Move ISA optimized versions under the main algo dir
Previously it made sense for them to be in distinct dirs because they were standalone. However with #580 that is no longer the case, so move them to subdirs. Configure knows that anything underneath a directory has a dependency on the parent dir, so update info.txt files accordingly to remove explicit dependencies where set.
Diffstat (limited to 'src/lib/block/noekeon')
-rw-r--r--src/lib/block/noekeon/noekeon_simd/info.txt6
-rw-r--r--src/lib/block/noekeon/noekeon_simd/noekeon_simd.cpp153
2 files changed, 159 insertions, 0 deletions
diff --git a/src/lib/block/noekeon/noekeon_simd/info.txt b/src/lib/block/noekeon/noekeon_simd/info.txt
new file mode 100644
index 000000000..45ff93467
--- /dev/null
+++ b/src/lib/block/noekeon/noekeon_simd/info.txt
@@ -0,0 +1,6 @@
+define NOEKEON_SIMD 20160903
+
+<requires>
+noekeon
+simd
+</requires>
diff --git a/src/lib/block/noekeon/noekeon_simd/noekeon_simd.cpp b/src/lib/block/noekeon/noekeon_simd/noekeon_simd.cpp
new file mode 100644
index 000000000..e37412b5f
--- /dev/null
+++ b/src/lib/block/noekeon/noekeon_simd/noekeon_simd.cpp
@@ -0,0 +1,153 @@
+/*
+* Noekeon in SIMD
+* (C) 2010 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include <botan/noekeon.h>
+#include <botan/internal/simd_32.h>
+
+namespace Botan {
+
+/*
+* Noekeon's Theta Operation
+*/
+#define NOK_SIMD_THETA(A0, A1, A2, A3, K0, K1, K2, K3) \
+ do { \
+ SIMD_32 T = A0 ^ A2; \
+ SIMD_32 T_l8 = T; \
+ SIMD_32 T_r8 = T; \
+ T_l8.rotate_left(8); \
+ T_r8.rotate_right(8); \
+ T ^= T_l8; \
+ T ^= T_r8; \
+ A1 ^= T; \
+ A3 ^= T; \
+ \
+ A0 ^= K0; \
+ A1 ^= K1; \
+ A2 ^= K2; \
+ A3 ^= K3; \
+ \
+ T = A1 ^ A3; \
+ T_l8 = T; \
+ T_r8 = T; \
+ T_l8.rotate_left(8); \
+ T_r8.rotate_right(8); \
+ T ^= T_l8; \
+ T ^= T_r8; \
+ A0 ^= T; \
+ A2 ^= T; \
+ } while(0)
+
+/*
+* Noekeon's Gamma S-Box Layer
+*/
+#define NOK_SIMD_GAMMA(A0, A1, A2, A3) \
+ do \
+ { \
+ A1 ^= A3.andc(~A2); \
+ A0 ^= A2 & A1; \
+ \
+ SIMD_32 T = A3; \
+ A3 = A0; \
+ A0 = T; \
+ \
+ A2 ^= A0 ^ A1 ^ A3; \
+ \
+ A1 ^= A3.andc(~A2); \
+ A0 ^= A2 & A1; \
+ } while(0)
+
+/*
+* Noekeon Encryption
+*/
+void Noekeon::simd_encrypt_4(const byte in[], byte out[]) const
+ {
+ const SIMD_32 K0 = SIMD_32(m_EK[0]);
+ const SIMD_32 K1 = SIMD_32(m_EK[1]);
+ const SIMD_32 K2 = SIMD_32(m_EK[2]);
+ const SIMD_32 K3 = SIMD_32(m_EK[3]);
+
+ SIMD_32 A0 = SIMD_32::load_be(in );
+ SIMD_32 A1 = SIMD_32::load_be(in + 16);
+ SIMD_32 A2 = SIMD_32::load_be(in + 32);
+ SIMD_32 A3 = SIMD_32::load_be(in + 48);
+
+ SIMD_32::transpose(A0, A1, A2, A3);
+
+ for(size_t i = 0; i != 16; ++i)
+ {
+ A0 ^= SIMD_32(RC[i]);
+
+ NOK_SIMD_THETA(A0, A1, A2, A3, K0, K1, K2, K3);
+
+ A1.rotate_left(1);
+ A2.rotate_left(5);
+ A3.rotate_left(2);
+
+ NOK_SIMD_GAMMA(A0, A1, A2, A3);
+
+ A1.rotate_right(1);
+ A2.rotate_right(5);
+ A3.rotate_right(2);
+ }
+
+ A0 ^= SIMD_32(RC[16]);
+ NOK_SIMD_THETA(A0, A1, A2, A3, K0, K1, K2, K3);
+
+ SIMD_32::transpose(A0, A1, A2, A3);
+
+ A0.store_be(out);
+ A1.store_be(out + 16);
+ A2.store_be(out + 32);
+ A3.store_be(out + 48);
+ }
+
+/*
+* Noekeon Encryption
+*/
+void Noekeon::simd_decrypt_4(const byte in[], byte out[]) const
+ {
+ const SIMD_32 K0 = SIMD_32(m_DK[0]);
+ const SIMD_32 K1 = SIMD_32(m_DK[1]);
+ const SIMD_32 K2 = SIMD_32(m_DK[2]);
+ const SIMD_32 K3 = SIMD_32(m_DK[3]);
+
+ SIMD_32 A0 = SIMD_32::load_be(in );
+ SIMD_32 A1 = SIMD_32::load_be(in + 16);
+ SIMD_32 A2 = SIMD_32::load_be(in + 32);
+ SIMD_32 A3 = SIMD_32::load_be(in + 48);
+
+ SIMD_32::transpose(A0, A1, A2, A3);
+
+ for(size_t i = 0; i != 16; ++i)
+ {
+ NOK_SIMD_THETA(A0, A1, A2, A3, K0, K1, K2, K3);
+
+ A0 ^= SIMD_32(RC[16-i]);
+
+ A1.rotate_left(1);
+ A2.rotate_left(5);
+ A3.rotate_left(2);
+
+ NOK_SIMD_GAMMA(A0, A1, A2, A3);
+
+ A1.rotate_right(1);
+ A2.rotate_right(5);
+ A3.rotate_right(2);
+ }
+
+ NOK_SIMD_THETA(A0, A1, A2, A3, K0, K1, K2, K3);
+ A0 ^= SIMD_32(RC[0]);
+
+ SIMD_32::transpose(A0, A1, A2, A3);
+
+ A0.store_be(out);
+ A1.store_be(out + 16);
+ A2.store_be(out + 32);
+ A3.store_be(out + 48);
+ }
+
+}