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