Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
sha256_avx2.cpp
Go to the documentation of this file.
1// Copyright (c) 2017-2019 The Bitcoin developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifdef ENABLE_AVX2
6
7#include <cstdint>
8#include <immintrin.h>
9
10#include <crypto/common.h>
11
12namespace sha256d64_avx2 {
13namespace {
14
15 __m256i inline K(uint32_t x) {
16 return _mm256_set1_epi32(x);
17 }
18
19 __m256i inline Add(__m256i x, __m256i y) {
20 return _mm256_add_epi32(x, y);
21 }
22 __m256i inline Add(__m256i x, __m256i y, __m256i z) {
23 return Add(Add(x, y), z);
24 }
25 __m256i inline Add(__m256i x, __m256i y, __m256i z, __m256i w) {
26 return Add(Add(x, y), Add(z, w));
27 }
28 __m256i inline Add(__m256i x, __m256i y, __m256i z, __m256i w, __m256i v) {
29 return Add(Add(x, y, z), Add(w, v));
30 }
31 __m256i inline Inc(__m256i &x, __m256i y) {
32 x = Add(x, y);
33 return x;
34 }
35 __m256i inline Inc(__m256i &x, __m256i y, __m256i z) {
36 x = Add(x, y, z);
37 return x;
38 }
39 __m256i inline Inc(__m256i &x, __m256i y, __m256i z, __m256i w) {
40 x = Add(x, y, z, w);
41 return x;
42 }
43 __m256i inline Xor(__m256i x, __m256i y) {
44 return _mm256_xor_si256(x, y);
45 }
46 __m256i inline Xor(__m256i x, __m256i y, __m256i z) {
47 return Xor(Xor(x, y), z);
48 }
49 __m256i inline Or(__m256i x, __m256i y) {
50 return _mm256_or_si256(x, y);
51 }
52 __m256i inline And(__m256i x, __m256i y) {
53 return _mm256_and_si256(x, y);
54 }
55 __m256i inline ShR(__m256i x, int n) {
56 return _mm256_srli_epi32(x, n);
57 }
58 __m256i inline ShL(__m256i x, int n) {
59 return _mm256_slli_epi32(x, n);
60 }
61
62 __m256i inline Ch(__m256i x, __m256i y, __m256i z) {
63 return Xor(z, And(x, Xor(y, z)));
64 }
65 __m256i inline Maj(__m256i x, __m256i y, __m256i z) {
66 return Or(And(x, y), And(z, Or(x, y)));
67 }
68 __m256i inline Sigma0(__m256i x) {
69 return Xor(Or(ShR(x, 2), ShL(x, 30)), Or(ShR(x, 13), ShL(x, 19)),
70 Or(ShR(x, 22), ShL(x, 10)));
71 }
72 __m256i inline Sigma1(__m256i x) {
73 return Xor(Or(ShR(x, 6), ShL(x, 26)), Or(ShR(x, 11), ShL(x, 21)),
74 Or(ShR(x, 25), ShL(x, 7)));
75 }
76 __m256i inline sigma0(__m256i x) {
77 return Xor(Or(ShR(x, 7), ShL(x, 25)), Or(ShR(x, 18), ShL(x, 14)),
78 ShR(x, 3));
79 }
80 __m256i inline sigma1(__m256i x) {
81 return Xor(Or(ShR(x, 17), ShL(x, 15)), Or(ShR(x, 19), ShL(x, 13)),
82 ShR(x, 10));
83 }
84
86 inline void __attribute__((always_inline))
88 __m256i g, __m256i &h, __m256i k) {
89 __m256i t1 = Add(h, Sigma1(e), Ch(e, f, g), k);
90 __m256i t2 = Add(Sigma0(a), Maj(a, b, c));
91 d = Add(d, t1);
92 h = Add(t1, t2);
93 }
94
95 __m256i inline Read8(const uint8_t *chunk, int offset) {
97 ReadLE32(chunk + 0 + offset), ReadLE32(chunk + 64 + offset),
98 ReadLE32(chunk + 128 + offset), ReadLE32(chunk + 192 + offset),
99 ReadLE32(chunk + 256 + offset), ReadLE32(chunk + 320 + offset),
100 ReadLE32(chunk + 384 + offset), ReadLE32(chunk + 448 + offset));
101 return _mm256_shuffle_epi8(
102 ret, _mm256_set_epi32(0x0C0D0E0FUL, 0x08090A0BUL, 0x04050607UL,
103 0x00010203UL, 0x0C0D0E0FUL, 0x08090A0BUL,
104 0x04050607UL, 0x00010203UL));
105 }
106
107 inline void Write8(uint8_t *out, int offset, __m256i v) {
109 v, _mm256_set_epi32(0x0C0D0E0FUL, 0x08090A0BUL, 0x04050607UL,
110 0x00010203UL, 0x0C0D0E0FUL, 0x08090A0BUL,
111 0x04050607UL, 0x00010203UL));
112 WriteLE32(out + 0 + offset, _mm256_extract_epi32(v, 7));
113 WriteLE32(out + 32 + offset, _mm256_extract_epi32(v, 6));
114 WriteLE32(out + 64 + offset, _mm256_extract_epi32(v, 5));
115 WriteLE32(out + 96 + offset, _mm256_extract_epi32(v, 4));
116 WriteLE32(out + 128 + offset, _mm256_extract_epi32(v, 3));
117 WriteLE32(out + 160 + offset, _mm256_extract_epi32(v, 2));
118 WriteLE32(out + 192 + offset, _mm256_extract_epi32(v, 1));
119 WriteLE32(out + 224 + offset, _mm256_extract_epi32(v, 0));
120 }
121} // namespace
122
123void Transform_8way(uint8_t *out, const uint8_t *in) {
124 // Transform 1
125 __m256i a = K(0x6a09e667ul);
126 __m256i b = K(0xbb67ae85ul);
127 __m256i c = K(0x3c6ef372ul);
128 __m256i d = K(0xa54ff53aul);
129 __m256i e = K(0x510e527ful);
130 __m256i f = K(0x9b05688cul);
131 __m256i g = K(0x1f83d9abul);
132 __m256i h = K(0x5be0cd19ul);
133
134 __m256i w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14,
135 w15;
136
137 Round(a, b, c, d, e, f, g, h, Add(K(0x428a2f98ul), w0 = Read8(in, 0)));
138 Round(h, a, b, c, d, e, f, g, Add(K(0x71374491ul), w1 = Read8(in, 4)));
139 Round(g, h, a, b, c, d, e, f, Add(K(0xb5c0fbcful), w2 = Read8(in, 8)));
140 Round(f, g, h, a, b, c, d, e, Add(K(0xe9b5dba5ul), w3 = Read8(in, 12)));
141 Round(e, f, g, h, a, b, c, d, Add(K(0x3956c25bul), w4 = Read8(in, 16)));
142 Round(d, e, f, g, h, a, b, c, Add(K(0x59f111f1ul), w5 = Read8(in, 20)));
143 Round(c, d, e, f, g, h, a, b, Add(K(0x923f82a4ul), w6 = Read8(in, 24)));
144 Round(b, c, d, e, f, g, h, a, Add(K(0xab1c5ed5ul), w7 = Read8(in, 28)));
145 Round(a, b, c, d, e, f, g, h, Add(K(0xd807aa98ul), w8 = Read8(in, 32)));
146 Round(h, a, b, c, d, e, f, g, Add(K(0x12835b01ul), w9 = Read8(in, 36)));
147 Round(g, h, a, b, c, d, e, f, Add(K(0x243185beul), w10 = Read8(in, 40)));
148 Round(f, g, h, a, b, c, d, e, Add(K(0x550c7dc3ul), w11 = Read8(in, 44)));
149 Round(e, f, g, h, a, b, c, d, Add(K(0x72be5d74ul), w12 = Read8(in, 48)));
150 Round(d, e, f, g, h, a, b, c, Add(K(0x80deb1feul), w13 = Read8(in, 52)));
151 Round(c, d, e, f, g, h, a, b, Add(K(0x9bdc06a7ul), w14 = Read8(in, 56)));
152 Round(b, c, d, e, f, g, h, a, Add(K(0xc19bf174ul), w15 = Read8(in, 60)));
153 Round(a, b, c, d, e, f, g, h,
154 Add(K(0xe49b69c1ul), Inc(w0, sigma1(w14), w9, sigma0(w1))));
155 Round(h, a, b, c, d, e, f, g,
156 Add(K(0xefbe4786ul), Inc(w1, sigma1(w15), w10, sigma0(w2))));
157 Round(g, h, a, b, c, d, e, f,
158 Add(K(0x0fc19dc6ul), Inc(w2, sigma1(w0), w11, sigma0(w3))));
159 Round(f, g, h, a, b, c, d, e,
160 Add(K(0x240ca1ccul), Inc(w3, sigma1(w1), w12, sigma0(w4))));
161 Round(e, f, g, h, a, b, c, d,
162 Add(K(0x2de92c6ful), Inc(w4, sigma1(w2), w13, sigma0(w5))));
163 Round(d, e, f, g, h, a, b, c,
164 Add(K(0x4a7484aaul), Inc(w5, sigma1(w3), w14, sigma0(w6))));
165 Round(c, d, e, f, g, h, a, b,
166 Add(K(0x5cb0a9dcul), Inc(w6, sigma1(w4), w15, sigma0(w7))));
167 Round(b, c, d, e, f, g, h, a,
168 Add(K(0x76f988daul), Inc(w7, sigma1(w5), w0, sigma0(w8))));
169 Round(a, b, c, d, e, f, g, h,
170 Add(K(0x983e5152ul), Inc(w8, sigma1(w6), w1, sigma0(w9))));
171 Round(h, a, b, c, d, e, f, g,
172 Add(K(0xa831c66dul), Inc(w9, sigma1(w7), w2, sigma0(w10))));
173 Round(g, h, a, b, c, d, e, f,
174 Add(K(0xb00327c8ul), Inc(w10, sigma1(w8), w3, sigma0(w11))));
175 Round(f, g, h, a, b, c, d, e,
176 Add(K(0xbf597fc7ul), Inc(w11, sigma1(w9), w4, sigma0(w12))));
177 Round(e, f, g, h, a, b, c, d,
178 Add(K(0xc6e00bf3ul), Inc(w12, sigma1(w10), w5, sigma0(w13))));
179 Round(d, e, f, g, h, a, b, c,
180 Add(K(0xd5a79147ul), Inc(w13, sigma1(w11), w6, sigma0(w14))));
181 Round(c, d, e, f, g, h, a, b,
182 Add(K(0x06ca6351ul), Inc(w14, sigma1(w12), w7, sigma0(w15))));
183 Round(b, c, d, e, f, g, h, a,
184 Add(K(0x14292967ul), Inc(w15, sigma1(w13), w8, sigma0(w0))));
185 Round(a, b, c, d, e, f, g, h,
186 Add(K(0x27b70a85ul), Inc(w0, sigma1(w14), w9, sigma0(w1))));
187 Round(h, a, b, c, d, e, f, g,
188 Add(K(0x2e1b2138ul), Inc(w1, sigma1(w15), w10, sigma0(w2))));
189 Round(g, h, a, b, c, d, e, f,
190 Add(K(0x4d2c6dfcul), Inc(w2, sigma1(w0), w11, sigma0(w3))));
191 Round(f, g, h, a, b, c, d, e,
192 Add(K(0x53380d13ul), Inc(w3, sigma1(w1), w12, sigma0(w4))));
193 Round(e, f, g, h, a, b, c, d,
194 Add(K(0x650a7354ul), Inc(w4, sigma1(w2), w13, sigma0(w5))));
195 Round(d, e, f, g, h, a, b, c,
196 Add(K(0x766a0abbul), Inc(w5, sigma1(w3), w14, sigma0(w6))));
197 Round(c, d, e, f, g, h, a, b,
198 Add(K(0x81c2c92eul), Inc(w6, sigma1(w4), w15, sigma0(w7))));
199 Round(b, c, d, e, f, g, h, a,
200 Add(K(0x92722c85ul), Inc(w7, sigma1(w5), w0, sigma0(w8))));
201 Round(a, b, c, d, e, f, g, h,
202 Add(K(0xa2bfe8a1ul), Inc(w8, sigma1(w6), w1, sigma0(w9))));
203 Round(h, a, b, c, d, e, f, g,
204 Add(K(0xa81a664bul), Inc(w9, sigma1(w7), w2, sigma0(w10))));
205 Round(g, h, a, b, c, d, e, f,
206 Add(K(0xc24b8b70ul), Inc(w10, sigma1(w8), w3, sigma0(w11))));
207 Round(f, g, h, a, b, c, d, e,
208 Add(K(0xc76c51a3ul), Inc(w11, sigma1(w9), w4, sigma0(w12))));
209 Round(e, f, g, h, a, b, c, d,
210 Add(K(0xd192e819ul), Inc(w12, sigma1(w10), w5, sigma0(w13))));
211 Round(d, e, f, g, h, a, b, c,
212 Add(K(0xd6990624ul), Inc(w13, sigma1(w11), w6, sigma0(w14))));
213 Round(c, d, e, f, g, h, a, b,
214 Add(K(0xf40e3585ul), Inc(w14, sigma1(w12), w7, sigma0(w15))));
215 Round(b, c, d, e, f, g, h, a,
216 Add(K(0x106aa070ul), Inc(w15, sigma1(w13), w8, sigma0(w0))));
217 Round(a, b, c, d, e, f, g, h,
218 Add(K(0x19a4c116ul), Inc(w0, sigma1(w14), w9, sigma0(w1))));
219 Round(h, a, b, c, d, e, f, g,
220 Add(K(0x1e376c08ul), Inc(w1, sigma1(w15), w10, sigma0(w2))));
221 Round(g, h, a, b, c, d, e, f,
222 Add(K(0x2748774cul), Inc(w2, sigma1(w0), w11, sigma0(w3))));
223 Round(f, g, h, a, b, c, d, e,
224 Add(K(0x34b0bcb5ul), Inc(w3, sigma1(w1), w12, sigma0(w4))));
225 Round(e, f, g, h, a, b, c, d,
226 Add(K(0x391c0cb3ul), Inc(w4, sigma1(w2), w13, sigma0(w5))));
227 Round(d, e, f, g, h, a, b, c,
228 Add(K(0x4ed8aa4aul), Inc(w5, sigma1(w3), w14, sigma0(w6))));
229 Round(c, d, e, f, g, h, a, b,
230 Add(K(0x5b9cca4ful), Inc(w6, sigma1(w4), w15, sigma0(w7))));
231 Round(b, c, d, e, f, g, h, a,
232 Add(K(0x682e6ff3ul), Inc(w7, sigma1(w5), w0, sigma0(w8))));
233 Round(a, b, c, d, e, f, g, h,
234 Add(K(0x748f82eeul), Inc(w8, sigma1(w6), w1, sigma0(w9))));
235 Round(h, a, b, c, d, e, f, g,
236 Add(K(0x78a5636ful), Inc(w9, sigma1(w7), w2, sigma0(w10))));
237 Round(g, h, a, b, c, d, e, f,
238 Add(K(0x84c87814ul), Inc(w10, sigma1(w8), w3, sigma0(w11))));
239 Round(f, g, h, a, b, c, d, e,
240 Add(K(0x8cc70208ul), Inc(w11, sigma1(w9), w4, sigma0(w12))));
241 Round(e, f, g, h, a, b, c, d,
242 Add(K(0x90befffaul), Inc(w12, sigma1(w10), w5, sigma0(w13))));
243 Round(d, e, f, g, h, a, b, c,
244 Add(K(0xa4506cebul), Inc(w13, sigma1(w11), w6, sigma0(w14))));
245 Round(c, d, e, f, g, h, a, b,
246 Add(K(0xbef9a3f7ul), Inc(w14, sigma1(w12), w7, sigma0(w15))));
247 Round(b, c, d, e, f, g, h, a,
248 Add(K(0xc67178f2ul), Inc(w15, sigma1(w13), w8, sigma0(w0))));
249
250 a = Add(a, K(0x6a09e667ul));
251 b = Add(b, K(0xbb67ae85ul));
252 c = Add(c, K(0x3c6ef372ul));
253 d = Add(d, K(0xa54ff53aul));
254 e = Add(e, K(0x510e527ful));
255 f = Add(f, K(0x9b05688cul));
256 g = Add(g, K(0x1f83d9abul));
257 h = Add(h, K(0x5be0cd19ul));
258
259 __m256i t0 = a, t1 = b, t2 = c, t3 = d, t4 = e, t5 = f, t6 = g, t7 = h;
260
261 // Transform 2
262 Round(a, b, c, d, e, f, g, h, K(0xc28a2f98ul));
263 Round(h, a, b, c, d, e, f, g, K(0x71374491ul));
264 Round(g, h, a, b, c, d, e, f, K(0xb5c0fbcful));
265 Round(f, g, h, a, b, c, d, e, K(0xe9b5dba5ul));
266 Round(e, f, g, h, a, b, c, d, K(0x3956c25bul));
267 Round(d, e, f, g, h, a, b, c, K(0x59f111f1ul));
268 Round(c, d, e, f, g, h, a, b, K(0x923f82a4ul));
269 Round(b, c, d, e, f, g, h, a, K(0xab1c5ed5ul));
270 Round(a, b, c, d, e, f, g, h, K(0xd807aa98ul));
271 Round(h, a, b, c, d, e, f, g, K(0x12835b01ul));
272 Round(g, h, a, b, c, d, e, f, K(0x243185beul));
273 Round(f, g, h, a, b, c, d, e, K(0x550c7dc3ul));
274 Round(e, f, g, h, a, b, c, d, K(0x72be5d74ul));
275 Round(d, e, f, g, h, a, b, c, K(0x80deb1feul));
276 Round(c, d, e, f, g, h, a, b, K(0x9bdc06a7ul));
277 Round(b, c, d, e, f, g, h, a, K(0xc19bf374ul));
278 Round(a, b, c, d, e, f, g, h, K(0x649b69c1ul));
279 Round(h, a, b, c, d, e, f, g, K(0xf0fe4786ul));
280 Round(g, h, a, b, c, d, e, f, K(0x0fe1edc6ul));
281 Round(f, g, h, a, b, c, d, e, K(0x240cf254ul));
282 Round(e, f, g, h, a, b, c, d, K(0x4fe9346ful));
283 Round(d, e, f, g, h, a, b, c, K(0x6cc984beul));
284 Round(c, d, e, f, g, h, a, b, K(0x61b9411eul));
285 Round(b, c, d, e, f, g, h, a, K(0x16f988faul));
286 Round(a, b, c, d, e, f, g, h, K(0xf2c65152ul));
287 Round(h, a, b, c, d, e, f, g, K(0xa88e5a6dul));
288 Round(g, h, a, b, c, d, e, f, K(0xb019fc65ul));
289 Round(f, g, h, a, b, c, d, e, K(0xb9d99ec7ul));
290 Round(e, f, g, h, a, b, c, d, K(0x9a1231c3ul));
291 Round(d, e, f, g, h, a, b, c, K(0xe70eeaa0ul));
292 Round(c, d, e, f, g, h, a, b, K(0xfdb1232bul));
293 Round(b, c, d, e, f, g, h, a, K(0xc7353eb0ul));
294 Round(a, b, c, d, e, f, g, h, K(0x3069bad5ul));
295 Round(h, a, b, c, d, e, f, g, K(0xcb976d5ful));
296 Round(g, h, a, b, c, d, e, f, K(0x5a0f118ful));
297 Round(f, g, h, a, b, c, d, e, K(0xdc1eeefdul));
298 Round(e, f, g, h, a, b, c, d, K(0x0a35b689ul));
299 Round(d, e, f, g, h, a, b, c, K(0xde0b7a04ul));
300 Round(c, d, e, f, g, h, a, b, K(0x58f4ca9dul));
301 Round(b, c, d, e, f, g, h, a, K(0xe15d5b16ul));
302 Round(a, b, c, d, e, f, g, h, K(0x007f3e86ul));
303 Round(h, a, b, c, d, e, f, g, K(0x37088980ul));
304 Round(g, h, a, b, c, d, e, f, K(0xa507ea32ul));
305 Round(f, g, h, a, b, c, d, e, K(0x6fab9537ul));
306 Round(e, f, g, h, a, b, c, d, K(0x17406110ul));
307 Round(d, e, f, g, h, a, b, c, K(0x0d8cd6f1ul));
308 Round(c, d, e, f, g, h, a, b, K(0xcdaa3b6dul));
309 Round(b, c, d, e, f, g, h, a, K(0xc0bbbe37ul));
310 Round(a, b, c, d, e, f, g, h, K(0x83613bdaul));
311 Round(h, a, b, c, d, e, f, g, K(0xdb48a363ul));
312 Round(g, h, a, b, c, d, e, f, K(0x0b02e931ul));
313 Round(f, g, h, a, b, c, d, e, K(0x6fd15ca7ul));
314 Round(e, f, g, h, a, b, c, d, K(0x521afacaul));
315 Round(d, e, f, g, h, a, b, c, K(0x31338431ul));
316 Round(c, d, e, f, g, h, a, b, K(0x6ed41a95ul));
317 Round(b, c, d, e, f, g, h, a, K(0x6d437890ul));
318 Round(a, b, c, d, e, f, g, h, K(0xc39c91f2ul));
319 Round(h, a, b, c, d, e, f, g, K(0x9eccabbdul));
320 Round(g, h, a, b, c, d, e, f, K(0xb5c9a0e6ul));
321 Round(f, g, h, a, b, c, d, e, K(0x532fb63cul));
322 Round(e, f, g, h, a, b, c, d, K(0xd2c741c6ul));
323 Round(d, e, f, g, h, a, b, c, K(0x07237ea3ul));
324 Round(c, d, e, f, g, h, a, b, K(0xa4954b68ul));
325 Round(b, c, d, e, f, g, h, a, K(0x4c191d76ul));
326
327 w0 = Add(t0, a);
328 w1 = Add(t1, b);
329 w2 = Add(t2, c);
330 w3 = Add(t3, d);
331 w4 = Add(t4, e);
332 w5 = Add(t5, f);
333 w6 = Add(t6, g);
334 w7 = Add(t7, h);
335
336 // Transform 3
337 a = K(0x6a09e667ul);
338 b = K(0xbb67ae85ul);
339 c = K(0x3c6ef372ul);
340 d = K(0xa54ff53aul);
341 e = K(0x510e527ful);
342 f = K(0x9b05688cul);
343 g = K(0x1f83d9abul);
344 h = K(0x5be0cd19ul);
345
346 Round(a, b, c, d, e, f, g, h, Add(K(0x428a2f98ul), w0));
347 Round(h, a, b, c, d, e, f, g, Add(K(0x71374491ul), w1));
348 Round(g, h, a, b, c, d, e, f, Add(K(0xb5c0fbcful), w2));
349 Round(f, g, h, a, b, c, d, e, Add(K(0xe9b5dba5ul), w3));
350 Round(e, f, g, h, a, b, c, d, Add(K(0x3956c25bul), w4));
351 Round(d, e, f, g, h, a, b, c, Add(K(0x59f111f1ul), w5));
352 Round(c, d, e, f, g, h, a, b, Add(K(0x923f82a4ul), w6));
353 Round(b, c, d, e, f, g, h, a, Add(K(0xab1c5ed5ul), w7));
354 Round(a, b, c, d, e, f, g, h, K(0x5807aa98ul));
355 Round(h, a, b, c, d, e, f, g, K(0x12835b01ul));
356 Round(g, h, a, b, c, d, e, f, K(0x243185beul));
357 Round(f, g, h, a, b, c, d, e, K(0x550c7dc3ul));
358 Round(e, f, g, h, a, b, c, d, K(0x72be5d74ul));
359 Round(d, e, f, g, h, a, b, c, K(0x80deb1feul));
360 Round(c, d, e, f, g, h, a, b, K(0x9bdc06a7ul));
361 Round(b, c, d, e, f, g, h, a, K(0xc19bf274ul));
362 Round(a, b, c, d, e, f, g, h, Add(K(0xe49b69c1ul), Inc(w0, sigma0(w1))));
363 Round(h, a, b, c, d, e, f, g,
364 Add(K(0xefbe4786ul), Inc(w1, K(0xa00000ul), sigma0(w2))));
365 Round(g, h, a, b, c, d, e, f,
366 Add(K(0x0fc19dc6ul), Inc(w2, sigma1(w0), sigma0(w3))));
367 Round(f, g, h, a, b, c, d, e,
368 Add(K(0x240ca1ccul), Inc(w3, sigma1(w1), sigma0(w4))));
369 Round(e, f, g, h, a, b, c, d,
370 Add(K(0x2de92c6ful), Inc(w4, sigma1(w2), sigma0(w5))));
371 Round(d, e, f, g, h, a, b, c,
372 Add(K(0x4a7484aaul), Inc(w5, sigma1(w3), sigma0(w6))));
373 Round(c, d, e, f, g, h, a, b,
374 Add(K(0x5cb0a9dcul), Inc(w6, sigma1(w4), K(0x100ul), sigma0(w7))));
375 Round(b, c, d, e, f, g, h, a,
376 Add(K(0x76f988daul), Inc(w7, sigma1(w5), w0, K(0x11002000ul))));
377 Round(a, b, c, d, e, f, g, h,
378 Add(K(0x983e5152ul), w8 = Add(K(0x80000000ul), sigma1(w6), w1)));
379 Round(h, a, b, c, d, e, f, g,
380 Add(K(0xa831c66dul), w9 = Add(sigma1(w7), w2)));
381 Round(g, h, a, b, c, d, e, f,
382 Add(K(0xb00327c8ul), w10 = Add(sigma1(w8), w3)));
383 Round(f, g, h, a, b, c, d, e,
384 Add(K(0xbf597fc7ul), w11 = Add(sigma1(w9), w4)));
385 Round(e, f, g, h, a, b, c, d,
386 Add(K(0xc6e00bf3ul), w12 = Add(sigma1(w10), w5)));
387 Round(d, e, f, g, h, a, b, c,
388 Add(K(0xd5a79147ul), w13 = Add(sigma1(w11), w6)));
389 Round(c, d, e, f, g, h, a, b,
390 Add(K(0x06ca6351ul), w14 = Add(sigma1(w12), w7, K(0x400022ul))));
391 Round(b, c, d, e, f, g, h, a,
392 Add(K(0x14292967ul),
393 w15 = Add(K(0x100ul), sigma1(w13), w8, sigma0(w0))));
394 Round(a, b, c, d, e, f, g, h,
395 Add(K(0x27b70a85ul), Inc(w0, sigma1(w14), w9, sigma0(w1))));
396 Round(h, a, b, c, d, e, f, g,
397 Add(K(0x2e1b2138ul), Inc(w1, sigma1(w15), w10, sigma0(w2))));
398 Round(g, h, a, b, c, d, e, f,
399 Add(K(0x4d2c6dfcul), Inc(w2, sigma1(w0), w11, sigma0(w3))));
400 Round(f, g, h, a, b, c, d, e,
401 Add(K(0x53380d13ul), Inc(w3, sigma1(w1), w12, sigma0(w4))));
402 Round(e, f, g, h, a, b, c, d,
403 Add(K(0x650a7354ul), Inc(w4, sigma1(w2), w13, sigma0(w5))));
404 Round(d, e, f, g, h, a, b, c,
405 Add(K(0x766a0abbul), Inc(w5, sigma1(w3), w14, sigma0(w6))));
406 Round(c, d, e, f, g, h, a, b,
407 Add(K(0x81c2c92eul), Inc(w6, sigma1(w4), w15, sigma0(w7))));
408 Round(b, c, d, e, f, g, h, a,
409 Add(K(0x92722c85ul), Inc(w7, sigma1(w5), w0, sigma0(w8))));
410 Round(a, b, c, d, e, f, g, h,
411 Add(K(0xa2bfe8a1ul), Inc(w8, sigma1(w6), w1, sigma0(w9))));
412 Round(h, a, b, c, d, e, f, g,
413 Add(K(0xa81a664bul), Inc(w9, sigma1(w7), w2, sigma0(w10))));
414 Round(g, h, a, b, c, d, e, f,
415 Add(K(0xc24b8b70ul), Inc(w10, sigma1(w8), w3, sigma0(w11))));
416 Round(f, g, h, a, b, c, d, e,
417 Add(K(0xc76c51a3ul), Inc(w11, sigma1(w9), w4, sigma0(w12))));
418 Round(e, f, g, h, a, b, c, d,
419 Add(K(0xd192e819ul), Inc(w12, sigma1(w10), w5, sigma0(w13))));
420 Round(d, e, f, g, h, a, b, c,
421 Add(K(0xd6990624ul), Inc(w13, sigma1(w11), w6, sigma0(w14))));
422 Round(c, d, e, f, g, h, a, b,
423 Add(K(0xf40e3585ul), Inc(w14, sigma1(w12), w7, sigma0(w15))));
424 Round(b, c, d, e, f, g, h, a,
425 Add(K(0x106aa070ul), Inc(w15, sigma1(w13), w8, sigma0(w0))));
426 Round(a, b, c, d, e, f, g, h,
427 Add(K(0x19a4c116ul), Inc(w0, sigma1(w14), w9, sigma0(w1))));
428 Round(h, a, b, c, d, e, f, g,
429 Add(K(0x1e376c08ul), Inc(w1, sigma1(w15), w10, sigma0(w2))));
430 Round(g, h, a, b, c, d, e, f,
431 Add(K(0x2748774cul), Inc(w2, sigma1(w0), w11, sigma0(w3))));
432 Round(f, g, h, a, b, c, d, e,
433 Add(K(0x34b0bcb5ul), Inc(w3, sigma1(w1), w12, sigma0(w4))));
434 Round(e, f, g, h, a, b, c, d,
435 Add(K(0x391c0cb3ul), Inc(w4, sigma1(w2), w13, sigma0(w5))));
436 Round(d, e, f, g, h, a, b, c,
437 Add(K(0x4ed8aa4aul), Inc(w5, sigma1(w3), w14, sigma0(w6))));
438 Round(c, d, e, f, g, h, a, b,
439 Add(K(0x5b9cca4ful), Inc(w6, sigma1(w4), w15, sigma0(w7))));
440 Round(b, c, d, e, f, g, h, a,
441 Add(K(0x682e6ff3ul), Inc(w7, sigma1(w5), w0, sigma0(w8))));
442 Round(a, b, c, d, e, f, g, h,
443 Add(K(0x748f82eeul), Inc(w8, sigma1(w6), w1, sigma0(w9))));
444 Round(h, a, b, c, d, e, f, g,
445 Add(K(0x78a5636ful), Inc(w9, sigma1(w7), w2, sigma0(w10))));
446 Round(g, h, a, b, c, d, e, f,
447 Add(K(0x84c87814ul), Inc(w10, sigma1(w8), w3, sigma0(w11))));
448 Round(f, g, h, a, b, c, d, e,
449 Add(K(0x8cc70208ul), Inc(w11, sigma1(w9), w4, sigma0(w12))));
450 Round(e, f, g, h, a, b, c, d,
451 Add(K(0x90befffaul), Inc(w12, sigma1(w10), w5, sigma0(w13))));
452 Round(d, e, f, g, h, a, b, c,
453 Add(K(0xa4506cebul), Inc(w13, sigma1(w11), w6, sigma0(w14))));
454 Round(c, d, e, f, g, h, a, b,
455 Add(K(0xbef9a3f7ul), w14, sigma1(w12), w7, sigma0(w15)));
456 Round(b, c, d, e, f, g, h, a,
457 Add(K(0xc67178f2ul), w15, sigma1(w13), w8, sigma0(w0)));
458
459 // Output
460 Write8(out, 0, Add(a, K(0x6a09e667ul)));
461 Write8(out, 4, Add(b, K(0xbb67ae85ul)));
462 Write8(out, 8, Add(c, K(0x3c6ef372ul)));
463 Write8(out, 12, Add(d, K(0xa54ff53aul)));
464 Write8(out, 16, Add(e, K(0x510e527ful)));
465 Write8(out, 20, Add(f, K(0x9b05688cul)));
466 Write8(out, 24, Add(g, K(0x1f83d9abul)));
467 Write8(out, 28, Add(h, K(0x5be0cd19ul)));
468}
469} // namespace sha256d64_avx2
470
471#endif
static void WriteLE32(uint8_t *ptr, uint32_t x)
Definition common.h:40
static uint32_t ReadLE32(const uint8_t *ptr)
Definition common.h:23
#define sigma1(x)
Definition hash_impl.h:22
#define Maj(x, y, z)
Definition hash_impl.h:18
#define Round(a, b, c, d, e, f, g, h, k, w)
Definition hash_impl.h:24
#define Sigma0(x)
Definition hash_impl.h:19
#define sigma0(x)
Definition hash_impl.h:21
#define Sigma1(x)
Definition hash_impl.h:20
#define Ch(x, y, z)
Definition hash_impl.h:17
void Transform_8way(uint8_t *out, const uint8_t *in)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85