Botan  2.19.1
Crypto and TLS for C++11
shacal2_avx2.cpp
Go to the documentation of this file.
1 /*
2 * (C) 2018 Jack Lloyd
3 *
4 * Botan is released under the Simplified BSD License (see license.txt)
5 */
6 
7 #include <botan/shacal2.h>
8 #include <botan/internal/simd_avx2.h>
9 
10 namespace Botan {
11 
12 namespace {
13 
15  SHACAL2_Fwd(const SIMD_8x32& A, const SIMD_8x32& B, const SIMD_8x32& C, SIMD_8x32& D,
16  const SIMD_8x32& E, const SIMD_8x32& F, const SIMD_8x32& G, SIMD_8x32& H,
17  uint32_t RK)
18  {
19  H += E.rho<6,11,25>() + ((E & F) ^ (~E & G)) + SIMD_8x32::splat(RK);
20  D += H;
21  H += A.rho<2,13,22>() + ((A & B) | ((A | B) & C));
22  }
23 
25  SHACAL2_Rev(const SIMD_8x32& A, const SIMD_8x32& B, const SIMD_8x32& C, SIMD_8x32& D,
26  const SIMD_8x32& E, const SIMD_8x32& F, const SIMD_8x32& G, SIMD_8x32& H,
27  uint32_t RK)
28  {
29  H -= A.rho<2,13,22>() + ((A & B) | ((A | B) & C));
30  D -= H;
31  H -= E.rho<6,11,25>() + ((E & F) ^ (~E & G)) + SIMD_8x32::splat(RK);
32  }
33 
34 }
35 
36 void BOTAN_FUNC_ISA("avx2") SHACAL2::avx2_encrypt_8(const uint8_t in[], uint8_t out[]) const
37  {
39 
44 
49 
50  SIMD_8x32::transpose(A, B, C, D, E, F, G, H);
51 
52  for(size_t r = 0; r != 64; r += 8)
53  {
54  SHACAL2_Fwd(A, B, C, D, E, F, G, H, m_RK[r+0]);
55  SHACAL2_Fwd(H, A, B, C, D, E, F, G, m_RK[r+1]);
56  SHACAL2_Fwd(G, H, A, B, C, D, E, F, m_RK[r+2]);
57  SHACAL2_Fwd(F, G, H, A, B, C, D, E, m_RK[r+3]);
58  SHACAL2_Fwd(E, F, G, H, A, B, C, D, m_RK[r+4]);
59  SHACAL2_Fwd(D, E, F, G, H, A, B, C, m_RK[r+5]);
60  SHACAL2_Fwd(C, D, E, F, G, H, A, B, m_RK[r+6]);
61  SHACAL2_Fwd(B, C, D, E, F, G, H, A, m_RK[r+7]);
62  }
63 
64  SIMD_8x32::transpose(A, B, C, D, E, F, G, H);
65 
66  A.store_be(out);
67  B.store_be(out+32);
68  C.store_be(out+64);
69  D.store_be(out+96);
70 
71  E.store_be(out+128);
72  F.store_be(out+160);
73  G.store_be(out+192);
74  H.store_be(out+224);
75 
77  }
78 
79 BOTAN_FUNC_ISA("avx2") void SHACAL2::avx2_decrypt_8(const uint8_t in[], uint8_t out[]) const
80  {
82 
83  SIMD_8x32 A = SIMD_8x32::load_be(in);
84  SIMD_8x32 B = SIMD_8x32::load_be(in+32);
85  SIMD_8x32 C = SIMD_8x32::load_be(in+64);
86  SIMD_8x32 D = SIMD_8x32::load_be(in+96);
87 
88  SIMD_8x32 E = SIMD_8x32::load_be(in+128);
89  SIMD_8x32 F = SIMD_8x32::load_be(in+160);
90  SIMD_8x32 G = SIMD_8x32::load_be(in+192);
91  SIMD_8x32 H = SIMD_8x32::load_be(in+224);
92 
93  SIMD_8x32::transpose(A, B, C, D, E, F, G, H);
94 
95  for(size_t r = 0; r != 64; r += 8)
96  {
97  SHACAL2_Rev(B, C, D, E, F, G, H, A, m_RK[63-r]);
98  SHACAL2_Rev(C, D, E, F, G, H, A, B, m_RK[62-r]);
99  SHACAL2_Rev(D, E, F, G, H, A, B, C, m_RK[61-r]);
100  SHACAL2_Rev(E, F, G, H, A, B, C, D, m_RK[60-r]);
101  SHACAL2_Rev(F, G, H, A, B, C, D, E, m_RK[59-r]);
102  SHACAL2_Rev(G, H, A, B, C, D, E, F, m_RK[58-r]);
103  SHACAL2_Rev(H, A, B, C, D, E, F, G, m_RK[57-r]);
104  SHACAL2_Rev(A, B, C, D, E, F, G, H, m_RK[56-r]);
105  }
106 
107  SIMD_8x32::transpose(A, B, C, D, E, F, G, H);
108 
109  A.store_be(out);
110  B.store_be(out+32);
111  C.store_be(out+64);
112  D.store_be(out+96);
113 
114  E.store_be(out+128);
115  F.store_be(out+160);
116  G.store_be(out+192);
117  H.store_be(out+224);
118 
120  }
121 
122 }
SIMD_8x32 H
void BOTAN_FUNC_ISA("avx2") SHACAL2 SIMD_8x32 A
static SIMD_8x32 splat(uint32_t B)
Definition: simd_avx2.h:45
#define BOTAN_FORCE_INLINE
Definition: compiler.h:205
SIMD_8x32 D
static void zero_registers()
Definition: simd_avx2.h:273
static void reset_registers()
Definition: simd_avx2.h:267
SIMD_8x32 E
SIMD_8x32 G
SIMD_8x32 B
void store_be(uint8_t out[]) const
Definition: simd_avx2.h:69
#define BOTAN_FUNC_ISA(isa)
Definition: compiler.h:77
Definition: alg_id.cpp:13
SIMD_8x32 F
static void transpose(SIMD_8x32 &B0, SIMD_8x32 &B1, SIMD_8x32 &B2, SIMD_8x32 &B3)
Definition: simd_avx2.h:237
SIMD_8x32 C
static SIMD_8x32 load_be(const uint8_t *in)
Definition: simd_avx2.h:57