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