Botan 3.8.1
Crypto and TLS for C&
argon2_ssse3.cpp
Go to the documentation of this file.
1/**
2* (C) 2022 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/argon2.h>
8
9#include <botan/compiler.h>
10#include <botan/internal/simd_2x64.h>
11
12namespace Botan {
13
14namespace {
15
16BOTAN_FORCE_INLINE void blamka_G(SIMD_2x64& A0,
17 SIMD_2x64& A1,
18 SIMD_2x64& B0,
19 SIMD_2x64& B1,
20 SIMD_2x64& C0,
21 SIMD_2x64& C1,
22 SIMD_2x64& D0,
23 SIMD_2x64& D1) {
24 A0 += B0 + SIMD_2x64::mul2_32(A0, B0);
25 A1 += B1 + SIMD_2x64::mul2_32(A1, B1);
26 D0 ^= A0;
27 D1 ^= A1;
28 D0 = D0.rotr<32>();
29 D1 = D1.rotr<32>();
30
31 C0 += D0 + SIMD_2x64::mul2_32(C0, D0);
32 C1 += D1 + SIMD_2x64::mul2_32(C1, D1);
33 B0 ^= C0;
34 B1 ^= C1;
35 B0 = B0.rotr<24>();
36 B1 = B1.rotr<24>();
37
38 A0 += B0 + SIMD_2x64::mul2_32(A0, B0);
39 A1 += B1 + SIMD_2x64::mul2_32(A1, B1);
40 D0 ^= A0;
41 D1 ^= A1;
42 D0 = D0.rotr<16>();
43 D1 = D1.rotr<16>();
44
45 C0 += D0 + SIMD_2x64::mul2_32(C0, D0);
46 C1 += D1 + SIMD_2x64::mul2_32(C1, D1);
47 B0 ^= C0;
48 B1 ^= C1;
49 B0 = B0.rotr<63>();
50 B1 = B1.rotr<63>();
51}
52
53BOTAN_FORCE_INLINE void blamka_R(SIMD_2x64& A0,
54 SIMD_2x64& A1,
55 SIMD_2x64& B0,
56 SIMD_2x64& B1,
57 SIMD_2x64& C0,
58 SIMD_2x64& C1,
59 SIMD_2x64& D0,
60 SIMD_2x64& D1) {
61 blamka_G(A0, A1, B0, B1, C0, C1, D0, D1);
62
63 SIMD_2x64::twist(B0, B1, C0, C1, D0, D1);
64 blamka_G(A0, A1, B0, B1, C0, C1, D0, D1);
65 SIMD_2x64::untwist(B0, B1, C0, C1, D0, D1);
66}
67
68} // namespace
69
70void Argon2::blamka_ssse3(uint64_t N[128], uint64_t T[128]) {
71 for(size_t i = 0; i != 8; ++i) {
72 SIMD_2x64 Tv[8];
73 for(size_t j = 0; j != 4; ++j) {
74 Tv[2 * j] = SIMD_2x64::load_le(&N[16 * i + 4 * j]);
75 Tv[2 * j + 1] = SIMD_2x64::load_le(&N[16 * i + 4 * j + 2]);
76 }
77
78 blamka_R(Tv[0], Tv[1], Tv[2], Tv[3], Tv[4], Tv[5], Tv[6], Tv[7]);
79
80 for(size_t j = 0; j != 4; ++j) {
81 Tv[2 * j].store_le(&T[16 * i + 4 * j]);
82 Tv[2 * j + 1].store_le(&T[16 * i + 4 * j + 2]);
83 }
84 }
85
86 for(size_t i = 0; i != 8; ++i) {
87 SIMD_2x64 Tv[8];
88 for(size_t j = 0; j != 4; ++j) {
89 Tv[2 * j] = SIMD_2x64::load_le(&T[2 * i + 32 * j]);
90 Tv[2 * j + 1] = SIMD_2x64::load_le(&T[2 * i + 32 * j + 16]);
91 }
92
93 blamka_R(Tv[0], Tv[1], Tv[2], Tv[3], Tv[4], Tv[5], Tv[6], Tv[7]);
94
95 for(size_t j = 0; j != 4; ++j) {
96 Tv[2 * j].store_le(&T[2 * i + 32 * j]);
97 Tv[2 * j + 1].store_le(&T[2 * i + 32 * j + 16]);
98 }
99 }
100
101 for(size_t i = 0; i != 128 / 4; ++i) {
102 SIMD_2x64 n0 = SIMD_2x64::load_le(&N[4 * i]);
103 SIMD_2x64 n1 = SIMD_2x64::load_le(&N[4 * i + 2]);
104 SIMD_2x64 t0 = SIMD_2x64::load_le(&T[4 * i]);
105 SIMD_2x64 t1 = SIMD_2x64::load_le(&T[4 * i + 2]);
106
107 n0 ^= t0;
108 n1 ^= t1;
109 n0.store_le(&N[4 * i]);
110 n1.store_le(&N[4 * i + 2]);
111 }
112}
113
114} // namespace Botan
static void untwist(SIMD_2x64 &B0, SIMD_2x64 &B1, SIMD_2x64 &C0, SIMD_2x64 &C1, SIMD_2x64 &D0, SIMD_2x64 &D1)
Definition simd_2x64.h:123
static void twist(SIMD_2x64 &B0, SIMD_2x64 &B1, SIMD_2x64 &C0, SIMD_2x64 &C1, SIMD_2x64 &D0, SIMD_2x64 &D1)
Definition simd_2x64.h:104
static SIMD_2x64 load_le(const void *in)
Definition simd_2x64.h:36
static SIMD_2x64 mul2_32(SIMD_2x64 x, SIMD_2x64 y)
Definition simd_2x64.h:142
#define BOTAN_FORCE_INLINE
Definition compiler.h:85