sha256_sse41.cpp raw

   1  // Copyright (c) 2018-present The Bitcoin Core 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 <attributes.h>
  11  #include <crypto/common.h>
  12  
  13  namespace sha256d64_sse41 {
  14  namespace {
  15  
  16  __m128i inline K(uint32_t x) { return _mm_set1_epi32(x); }
  17  
  18  __m128i inline Add(__m128i x, __m128i y) { return _mm_add_epi32(x, y); }
  19  __m128i inline Add(__m128i x, __m128i y, __m128i z) { return Add(Add(x, y), z); }
  20  __m128i inline Add(__m128i x, __m128i y, __m128i z, __m128i w) { return Add(Add(x, y), Add(z, w)); }
  21  __m128i inline Add(__m128i x, __m128i y, __m128i z, __m128i w, __m128i v) { return Add(Add(x, y, z), Add(w, v)); }
  22  __m128i inline Inc(__m128i& x, __m128i y) { x = Add(x, y); return x; }
  23  __m128i inline Inc(__m128i& x, __m128i y, __m128i z) { x = Add(x, y, z); return x; }
  24  __m128i inline Inc(__m128i& x, __m128i y, __m128i z, __m128i w) { x = Add(x, y, z, w); return x; }
  25  __m128i inline Xor(__m128i x, __m128i y) { return _mm_xor_si128(x, y); }
  26  __m128i inline Xor(__m128i x, __m128i y, __m128i z) { return Xor(Xor(x, y), z); }
  27  __m128i inline Or(__m128i x, __m128i y) { return _mm_or_si128(x, y); }
  28  __m128i inline And(__m128i x, __m128i y) { return _mm_and_si128(x, y); }
  29  __m128i inline ShR(__m128i x, int n) { return _mm_srli_epi32(x, n); }
  30  __m128i inline ShL(__m128i x, int n) { return _mm_slli_epi32(x, n); }
  31  
  32  __m128i inline Ch(__m128i x, __m128i y, __m128i z) { return Xor(z, And(x, Xor(y, z))); }
  33  __m128i inline Maj(__m128i x, __m128i y, __m128i z) { return Or(And(x, y), And(z, Or(x, y))); }
  34  __m128i inline Sigma0(__m128i x) { return Xor(Or(ShR(x, 2), ShL(x, 30)), Or(ShR(x, 13), ShL(x, 19)), Or(ShR(x, 22), ShL(x, 10))); }
  35  __m128i inline Sigma1(__m128i x) { return Xor(Or(ShR(x, 6), ShL(x, 26)), Or(ShR(x, 11), ShL(x, 21)), Or(ShR(x, 25), ShL(x, 7))); }
  36  __m128i inline sigma0(__m128i x) { return Xor(Or(ShR(x, 7), ShL(x, 25)), Or(ShR(x, 18), ShL(x, 14)), ShR(x, 3)); }
  37  __m128i inline sigma1(__m128i x) { return Xor(Or(ShR(x, 17), ShL(x, 15)), Or(ShR(x, 19), ShL(x, 13)), ShR(x, 10)); }
  38  
  39  /** One round of SHA-256. */
  40  void ALWAYS_INLINE Round(__m128i a, __m128i b, __m128i c, __m128i& d, __m128i e, __m128i f, __m128i g, __m128i& h, __m128i k)
  41  {
  42      __m128i t1 = Add(h, Sigma1(e), Ch(e, f, g), k);
  43      __m128i t2 = Add(Sigma0(a), Maj(a, b, c));
  44      d = Add(d, t1);
  45      h = Add(t1, t2);
  46  }
  47  
  48  __m128i inline Read4(const unsigned char* chunk, int offset) {
  49      __m128i ret = _mm_set_epi32(
  50          ReadLE32(chunk + 0 + offset),
  51          ReadLE32(chunk + 64 + offset),
  52          ReadLE32(chunk + 128 + offset),
  53          ReadLE32(chunk + 192 + offset)
  54      );
  55      return _mm_shuffle_epi8(ret, _mm_set_epi32(0x0C0D0E0FUL, 0x08090A0BUL, 0x04050607UL, 0x00010203UL));
  56  }
  57  
  58  void inline Write4(unsigned char* out, int offset, __m128i v) {
  59      v = _mm_shuffle_epi8(v, _mm_set_epi32(0x0C0D0E0FUL, 0x08090A0BUL, 0x04050607UL, 0x00010203UL));
  60      WriteLE32(out + 0 + offset, _mm_extract_epi32(v, 3));
  61      WriteLE32(out + 32 + offset, _mm_extract_epi32(v, 2));
  62      WriteLE32(out + 64 + offset, _mm_extract_epi32(v, 1));
  63      WriteLE32(out + 96 + offset, _mm_extract_epi32(v, 0));
  64  }
  65  
  66  }
  67  
  68  void Transform_4way(unsigned char* out, const unsigned char* in)
  69  {
  70      // Transform 1
  71      __m128i a = K(0x6a09e667ul);
  72      __m128i b = K(0xbb67ae85ul);
  73      __m128i c = K(0x3c6ef372ul);
  74      __m128i d = K(0xa54ff53aul);
  75      __m128i e = K(0x510e527ful);
  76      __m128i f = K(0x9b05688cul);
  77      __m128i g = K(0x1f83d9abul);
  78      __m128i h = K(0x5be0cd19ul);
  79  
  80      __m128i w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15;
  81  
  82      Round(a, b, c, d, e, f, g, h, Add(K(0x428a2f98ul), w0 = Read4(in, 0)));
  83      Round(h, a, b, c, d, e, f, g, Add(K(0x71374491ul), w1 = Read4(in, 4)));
  84      Round(g, h, a, b, c, d, e, f, Add(K(0xb5c0fbcful), w2 = Read4(in, 8)));
  85      Round(f, g, h, a, b, c, d, e, Add(K(0xe9b5dba5ul), w3 = Read4(in, 12)));
  86      Round(e, f, g, h, a, b, c, d, Add(K(0x3956c25bul), w4 = Read4(in, 16)));
  87      Round(d, e, f, g, h, a, b, c, Add(K(0x59f111f1ul), w5 = Read4(in, 20)));
  88      Round(c, d, e, f, g, h, a, b, Add(K(0x923f82a4ul), w6 = Read4(in, 24)));
  89      Round(b, c, d, e, f, g, h, a, Add(K(0xab1c5ed5ul), w7 = Read4(in, 28)));
  90      Round(a, b, c, d, e, f, g, h, Add(K(0xd807aa98ul), w8 = Read4(in, 32)));
  91      Round(h, a, b, c, d, e, f, g, Add(K(0x12835b01ul), w9 = Read4(in, 36)));
  92      Round(g, h, a, b, c, d, e, f, Add(K(0x243185beul), w10 = Read4(in, 40)));
  93      Round(f, g, h, a, b, c, d, e, Add(K(0x550c7dc3ul), w11 = Read4(in, 44)));
  94      Round(e, f, g, h, a, b, c, d, Add(K(0x72be5d74ul), w12 = Read4(in, 48)));
  95      Round(d, e, f, g, h, a, b, c, Add(K(0x80deb1feul), w13 = Read4(in, 52)));
  96      Round(c, d, e, f, g, h, a, b, Add(K(0x9bdc06a7ul), w14 = Read4(in, 56)));
  97      Round(b, c, d, e, f, g, h, a, Add(K(0xc19bf174ul), w15 = Read4(in, 60)));
  98      Round(a, b, c, d, e, f, g, h, Add(K(0xe49b69c1ul), Inc(w0, sigma1(w14), w9, sigma0(w1))));
  99      Round(h, a, b, c, d, e, f, g, Add(K(0xefbe4786ul), Inc(w1, sigma1(w15), w10, sigma0(w2))));
 100      Round(g, h, a, b, c, d, e, f, Add(K(0x0fc19dc6ul), Inc(w2, sigma1(w0), w11, sigma0(w3))));
 101      Round(f, g, h, a, b, c, d, e, Add(K(0x240ca1ccul), Inc(w3, sigma1(w1), w12, sigma0(w4))));
 102      Round(e, f, g, h, a, b, c, d, Add(K(0x2de92c6ful), Inc(w4, sigma1(w2), w13, sigma0(w5))));
 103      Round(d, e, f, g, h, a, b, c, Add(K(0x4a7484aaul), Inc(w5, sigma1(w3), w14, sigma0(w6))));
 104      Round(c, d, e, f, g, h, a, b, Add(K(0x5cb0a9dcul), Inc(w6, sigma1(w4), w15, sigma0(w7))));
 105      Round(b, c, d, e, f, g, h, a, Add(K(0x76f988daul), Inc(w7, sigma1(w5), w0, sigma0(w8))));
 106      Round(a, b, c, d, e, f, g, h, Add(K(0x983e5152ul), Inc(w8, sigma1(w6), w1, sigma0(w9))));
 107      Round(h, a, b, c, d, e, f, g, Add(K(0xa831c66dul), Inc(w9, sigma1(w7), w2, sigma0(w10))));
 108      Round(g, h, a, b, c, d, e, f, Add(K(0xb00327c8ul), Inc(w10, sigma1(w8), w3, sigma0(w11))));
 109      Round(f, g, h, a, b, c, d, e, Add(K(0xbf597fc7ul), Inc(w11, sigma1(w9), w4, sigma0(w12))));
 110      Round(e, f, g, h, a, b, c, d, Add(K(0xc6e00bf3ul), Inc(w12, sigma1(w10), w5, sigma0(w13))));
 111      Round(d, e, f, g, h, a, b, c, Add(K(0xd5a79147ul), Inc(w13, sigma1(w11), w6, sigma0(w14))));
 112      Round(c, d, e, f, g, h, a, b, Add(K(0x06ca6351ul), Inc(w14, sigma1(w12), w7, sigma0(w15))));
 113      Round(b, c, d, e, f, g, h, a, Add(K(0x14292967ul), Inc(w15, sigma1(w13), w8, sigma0(w0))));
 114      Round(a, b, c, d, e, f, g, h, Add(K(0x27b70a85ul), Inc(w0, sigma1(w14), w9, sigma0(w1))));
 115      Round(h, a, b, c, d, e, f, g, Add(K(0x2e1b2138ul), Inc(w1, sigma1(w15), w10, sigma0(w2))));
 116      Round(g, h, a, b, c, d, e, f, Add(K(0x4d2c6dfcul), Inc(w2, sigma1(w0), w11, sigma0(w3))));
 117      Round(f, g, h, a, b, c, d, e, Add(K(0x53380d13ul), Inc(w3, sigma1(w1), w12, sigma0(w4))));
 118      Round(e, f, g, h, a, b, c, d, Add(K(0x650a7354ul), Inc(w4, sigma1(w2), w13, sigma0(w5))));
 119      Round(d, e, f, g, h, a, b, c, Add(K(0x766a0abbul), Inc(w5, sigma1(w3), w14, sigma0(w6))));
 120      Round(c, d, e, f, g, h, a, b, Add(K(0x81c2c92eul), Inc(w6, sigma1(w4), w15, sigma0(w7))));
 121      Round(b, c, d, e, f, g, h, a, Add(K(0x92722c85ul), Inc(w7, sigma1(w5), w0, sigma0(w8))));
 122      Round(a, b, c, d, e, f, g, h, Add(K(0xa2bfe8a1ul), Inc(w8, sigma1(w6), w1, sigma0(w9))));
 123      Round(h, a, b, c, d, e, f, g, Add(K(0xa81a664bul), Inc(w9, sigma1(w7), w2, sigma0(w10))));
 124      Round(g, h, a, b, c, d, e, f, Add(K(0xc24b8b70ul), Inc(w10, sigma1(w8), w3, sigma0(w11))));
 125      Round(f, g, h, a, b, c, d, e, Add(K(0xc76c51a3ul), Inc(w11, sigma1(w9), w4, sigma0(w12))));
 126      Round(e, f, g, h, a, b, c, d, Add(K(0xd192e819ul), Inc(w12, sigma1(w10), w5, sigma0(w13))));
 127      Round(d, e, f, g, h, a, b, c, Add(K(0xd6990624ul), Inc(w13, sigma1(w11), w6, sigma0(w14))));
 128      Round(c, d, e, f, g, h, a, b, Add(K(0xf40e3585ul), Inc(w14, sigma1(w12), w7, sigma0(w15))));
 129      Round(b, c, d, e, f, g, h, a, Add(K(0x106aa070ul), Inc(w15, sigma1(w13), w8, sigma0(w0))));
 130      Round(a, b, c, d, e, f, g, h, Add(K(0x19a4c116ul), Inc(w0, sigma1(w14), w9, sigma0(w1))));
 131      Round(h, a, b, c, d, e, f, g, Add(K(0x1e376c08ul), Inc(w1, sigma1(w15), w10, sigma0(w2))));
 132      Round(g, h, a, b, c, d, e, f, Add(K(0x2748774cul), Inc(w2, sigma1(w0), w11, sigma0(w3))));
 133      Round(f, g, h, a, b, c, d, e, Add(K(0x34b0bcb5ul), Inc(w3, sigma1(w1), w12, sigma0(w4))));
 134      Round(e, f, g, h, a, b, c, d, Add(K(0x391c0cb3ul), Inc(w4, sigma1(w2), w13, sigma0(w5))));
 135      Round(d, e, f, g, h, a, b, c, Add(K(0x4ed8aa4aul), Inc(w5, sigma1(w3), w14, sigma0(w6))));
 136      Round(c, d, e, f, g, h, a, b, Add(K(0x5b9cca4ful), Inc(w6, sigma1(w4), w15, sigma0(w7))));
 137      Round(b, c, d, e, f, g, h, a, Add(K(0x682e6ff3ul), Inc(w7, sigma1(w5), w0, sigma0(w8))));
 138      Round(a, b, c, d, e, f, g, h, Add(K(0x748f82eeul), Inc(w8, sigma1(w6), w1, sigma0(w9))));
 139      Round(h, a, b, c, d, e, f, g, Add(K(0x78a5636ful), Inc(w9, sigma1(w7), w2, sigma0(w10))));
 140      Round(g, h, a, b, c, d, e, f, Add(K(0x84c87814ul), Inc(w10, sigma1(w8), w3, sigma0(w11))));
 141      Round(f, g, h, a, b, c, d, e, Add(K(0x8cc70208ul), Inc(w11, sigma1(w9), w4, sigma0(w12))));
 142      Round(e, f, g, h, a, b, c, d, Add(K(0x90befffaul), Inc(w12, sigma1(w10), w5, sigma0(w13))));
 143      Round(d, e, f, g, h, a, b, c, Add(K(0xa4506cebul), Inc(w13, sigma1(w11), w6, sigma0(w14))));
 144      Round(c, d, e, f, g, h, a, b, Add(K(0xbef9a3f7ul), Inc(w14, sigma1(w12), w7, sigma0(w15))));
 145      Round(b, c, d, e, f, g, h, a, Add(K(0xc67178f2ul), Inc(w15, sigma1(w13), w8, sigma0(w0))));
 146  
 147      a = Add(a, K(0x6a09e667ul));
 148      b = Add(b, K(0xbb67ae85ul));
 149      c = Add(c, K(0x3c6ef372ul));
 150      d = Add(d, K(0xa54ff53aul));
 151      e = Add(e, K(0x510e527ful));
 152      f = Add(f, K(0x9b05688cul));
 153      g = Add(g, K(0x1f83d9abul));
 154      h = Add(h, K(0x5be0cd19ul));
 155  
 156      __m128i t0 = a, t1 = b, t2 = c, t3 = d, t4 = e, t5 = f, t6 = g, t7 = h;
 157  
 158      // Transform 2
 159      Round(a, b, c, d, e, f, g, h, K(0xc28a2f98ul));
 160      Round(h, a, b, c, d, e, f, g, K(0x71374491ul));
 161      Round(g, h, a, b, c, d, e, f, K(0xb5c0fbcful));
 162      Round(f, g, h, a, b, c, d, e, K(0xe9b5dba5ul));
 163      Round(e, f, g, h, a, b, c, d, K(0x3956c25bul));
 164      Round(d, e, f, g, h, a, b, c, K(0x59f111f1ul));
 165      Round(c, d, e, f, g, h, a, b, K(0x923f82a4ul));
 166      Round(b, c, d, e, f, g, h, a, K(0xab1c5ed5ul));
 167      Round(a, b, c, d, e, f, g, h, K(0xd807aa98ul));
 168      Round(h, a, b, c, d, e, f, g, K(0x12835b01ul));
 169      Round(g, h, a, b, c, d, e, f, K(0x243185beul));
 170      Round(f, g, h, a, b, c, d, e, K(0x550c7dc3ul));
 171      Round(e, f, g, h, a, b, c, d, K(0x72be5d74ul));
 172      Round(d, e, f, g, h, a, b, c, K(0x80deb1feul));
 173      Round(c, d, e, f, g, h, a, b, K(0x9bdc06a7ul));
 174      Round(b, c, d, e, f, g, h, a, K(0xc19bf374ul));
 175      Round(a, b, c, d, e, f, g, h, K(0x649b69c1ul));
 176      Round(h, a, b, c, d, e, f, g, K(0xf0fe4786ul));
 177      Round(g, h, a, b, c, d, e, f, K(0x0fe1edc6ul));
 178      Round(f, g, h, a, b, c, d, e, K(0x240cf254ul));
 179      Round(e, f, g, h, a, b, c, d, K(0x4fe9346ful));
 180      Round(d, e, f, g, h, a, b, c, K(0x6cc984beul));
 181      Round(c, d, e, f, g, h, a, b, K(0x61b9411eul));
 182      Round(b, c, d, e, f, g, h, a, K(0x16f988faul));
 183      Round(a, b, c, d, e, f, g, h, K(0xf2c65152ul));
 184      Round(h, a, b, c, d, e, f, g, K(0xa88e5a6dul));
 185      Round(g, h, a, b, c, d, e, f, K(0xb019fc65ul));
 186      Round(f, g, h, a, b, c, d, e, K(0xb9d99ec7ul));
 187      Round(e, f, g, h, a, b, c, d, K(0x9a1231c3ul));
 188      Round(d, e, f, g, h, a, b, c, K(0xe70eeaa0ul));
 189      Round(c, d, e, f, g, h, a, b, K(0xfdb1232bul));
 190      Round(b, c, d, e, f, g, h, a, K(0xc7353eb0ul));
 191      Round(a, b, c, d, e, f, g, h, K(0x3069bad5ul));
 192      Round(h, a, b, c, d, e, f, g, K(0xcb976d5ful));
 193      Round(g, h, a, b, c, d, e, f, K(0x5a0f118ful));
 194      Round(f, g, h, a, b, c, d, e, K(0xdc1eeefdul));
 195      Round(e, f, g, h, a, b, c, d, K(0x0a35b689ul));
 196      Round(d, e, f, g, h, a, b, c, K(0xde0b7a04ul));
 197      Round(c, d, e, f, g, h, a, b, K(0x58f4ca9dul));
 198      Round(b, c, d, e, f, g, h, a, K(0xe15d5b16ul));
 199      Round(a, b, c, d, e, f, g, h, K(0x007f3e86ul));
 200      Round(h, a, b, c, d, e, f, g, K(0x37088980ul));
 201      Round(g, h, a, b, c, d, e, f, K(0xa507ea32ul));
 202      Round(f, g, h, a, b, c, d, e, K(0x6fab9537ul));
 203      Round(e, f, g, h, a, b, c, d, K(0x17406110ul));
 204      Round(d, e, f, g, h, a, b, c, K(0x0d8cd6f1ul));
 205      Round(c, d, e, f, g, h, a, b, K(0xcdaa3b6dul));
 206      Round(b, c, d, e, f, g, h, a, K(0xc0bbbe37ul));
 207      Round(a, b, c, d, e, f, g, h, K(0x83613bdaul));
 208      Round(h, a, b, c, d, e, f, g, K(0xdb48a363ul));
 209      Round(g, h, a, b, c, d, e, f, K(0x0b02e931ul));
 210      Round(f, g, h, a, b, c, d, e, K(0x6fd15ca7ul));
 211      Round(e, f, g, h, a, b, c, d, K(0x521afacaul));
 212      Round(d, e, f, g, h, a, b, c, K(0x31338431ul));
 213      Round(c, d, e, f, g, h, a, b, K(0x6ed41a95ul));
 214      Round(b, c, d, e, f, g, h, a, K(0x6d437890ul));
 215      Round(a, b, c, d, e, f, g, h, K(0xc39c91f2ul));
 216      Round(h, a, b, c, d, e, f, g, K(0x9eccabbdul));
 217      Round(g, h, a, b, c, d, e, f, K(0xb5c9a0e6ul));
 218      Round(f, g, h, a, b, c, d, e, K(0x532fb63cul));
 219      Round(e, f, g, h, a, b, c, d, K(0xd2c741c6ul));
 220      Round(d, e, f, g, h, a, b, c, K(0x07237ea3ul));
 221      Round(c, d, e, f, g, h, a, b, K(0xa4954b68ul));
 222      Round(b, c, d, e, f, g, h, a, K(0x4c191d76ul));
 223  
 224      w0 = Add(t0, a);
 225      w1 = Add(t1, b);
 226      w2 = Add(t2, c);
 227      w3 = Add(t3, d);
 228      w4 = Add(t4, e);
 229      w5 = Add(t5, f);
 230      w6 = Add(t6, g);
 231      w7 = Add(t7, h);
 232  
 233      // Transform 3
 234      a = K(0x6a09e667ul);
 235      b = K(0xbb67ae85ul);
 236      c = K(0x3c6ef372ul);
 237      d = K(0xa54ff53aul);
 238      e = K(0x510e527ful);
 239      f = K(0x9b05688cul);
 240      g = K(0x1f83d9abul);
 241      h = K(0x5be0cd19ul);
 242  
 243      Round(a, b, c, d, e, f, g, h, Add(K(0x428a2f98ul), w0));
 244      Round(h, a, b, c, d, e, f, g, Add(K(0x71374491ul), w1));
 245      Round(g, h, a, b, c, d, e, f, Add(K(0xb5c0fbcful), w2));
 246      Round(f, g, h, a, b, c, d, e, Add(K(0xe9b5dba5ul), w3));
 247      Round(e, f, g, h, a, b, c, d, Add(K(0x3956c25bul), w4));
 248      Round(d, e, f, g, h, a, b, c, Add(K(0x59f111f1ul), w5));
 249      Round(c, d, e, f, g, h, a, b, Add(K(0x923f82a4ul), w6));
 250      Round(b, c, d, e, f, g, h, a, Add(K(0xab1c5ed5ul), w7));
 251      Round(a, b, c, d, e, f, g, h, K(0x5807aa98ul));
 252      Round(h, a, b, c, d, e, f, g, K(0x12835b01ul));
 253      Round(g, h, a, b, c, d, e, f, K(0x243185beul));
 254      Round(f, g, h, a, b, c, d, e, K(0x550c7dc3ul));
 255      Round(e, f, g, h, a, b, c, d, K(0x72be5d74ul));
 256      Round(d, e, f, g, h, a, b, c, K(0x80deb1feul));
 257      Round(c, d, e, f, g, h, a, b, K(0x9bdc06a7ul));
 258      Round(b, c, d, e, f, g, h, a, K(0xc19bf274ul));
 259      Round(a, b, c, d, e, f, g, h, Add(K(0xe49b69c1ul), Inc(w0, sigma0(w1))));
 260      Round(h, a, b, c, d, e, f, g, Add(K(0xefbe4786ul), Inc(w1, K(0xa00000ul), sigma0(w2))));
 261      Round(g, h, a, b, c, d, e, f, Add(K(0x0fc19dc6ul), Inc(w2, sigma1(w0), sigma0(w3))));
 262      Round(f, g, h, a, b, c, d, e, Add(K(0x240ca1ccul), Inc(w3, sigma1(w1), sigma0(w4))));
 263      Round(e, f, g, h, a, b, c, d, Add(K(0x2de92c6ful), Inc(w4, sigma1(w2), sigma0(w5))));
 264      Round(d, e, f, g, h, a, b, c, Add(K(0x4a7484aaul), Inc(w5, sigma1(w3), sigma0(w6))));
 265      Round(c, d, e, f, g, h, a, b, Add(K(0x5cb0a9dcul), Inc(w6, sigma1(w4), K(0x100ul), sigma0(w7))));
 266      Round(b, c, d, e, f, g, h, a, Add(K(0x76f988daul), Inc(w7, sigma1(w5), w0, K(0x11002000ul))));
 267      Round(a, b, c, d, e, f, g, h, Add(K(0x983e5152ul), w8 = Add(K(0x80000000ul), sigma1(w6), w1)));
 268      Round(h, a, b, c, d, e, f, g, Add(K(0xa831c66dul), w9 = Add(sigma1(w7), w2)));
 269      Round(g, h, a, b, c, d, e, f, Add(K(0xb00327c8ul), w10 = Add(sigma1(w8), w3)));
 270      Round(f, g, h, a, b, c, d, e, Add(K(0xbf597fc7ul), w11 = Add(sigma1(w9), w4)));
 271      Round(e, f, g, h, a, b, c, d, Add(K(0xc6e00bf3ul), w12 = Add(sigma1(w10), w5)));
 272      Round(d, e, f, g, h, a, b, c, Add(K(0xd5a79147ul), w13 = Add(sigma1(w11), w6)));
 273      Round(c, d, e, f, g, h, a, b, Add(K(0x06ca6351ul), w14 = Add(sigma1(w12), w7, K(0x400022ul))));
 274      Round(b, c, d, e, f, g, h, a, Add(K(0x14292967ul), w15 = Add(K(0x100ul), sigma1(w13), w8, sigma0(w0))));
 275      Round(a, b, c, d, e, f, g, h, Add(K(0x27b70a85ul), Inc(w0, sigma1(w14), w9, sigma0(w1))));
 276      Round(h, a, b, c, d, e, f, g, Add(K(0x2e1b2138ul), Inc(w1, sigma1(w15), w10, sigma0(w2))));
 277      Round(g, h, a, b, c, d, e, f, Add(K(0x4d2c6dfcul), Inc(w2, sigma1(w0), w11, sigma0(w3))));
 278      Round(f, g, h, a, b, c, d, e, Add(K(0x53380d13ul), Inc(w3, sigma1(w1), w12, sigma0(w4))));
 279      Round(e, f, g, h, a, b, c, d, Add(K(0x650a7354ul), Inc(w4, sigma1(w2), w13, sigma0(w5))));
 280      Round(d, e, f, g, h, a, b, c, Add(K(0x766a0abbul), Inc(w5, sigma1(w3), w14, sigma0(w6))));
 281      Round(c, d, e, f, g, h, a, b, Add(K(0x81c2c92eul), Inc(w6, sigma1(w4), w15, sigma0(w7))));
 282      Round(b, c, d, e, f, g, h, a, Add(K(0x92722c85ul), Inc(w7, sigma1(w5), w0, sigma0(w8))));
 283      Round(a, b, c, d, e, f, g, h, Add(K(0xa2bfe8a1ul), Inc(w8, sigma1(w6), w1, sigma0(w9))));
 284      Round(h, a, b, c, d, e, f, g, Add(K(0xa81a664bul), Inc(w9, sigma1(w7), w2, sigma0(w10))));
 285      Round(g, h, a, b, c, d, e, f, Add(K(0xc24b8b70ul), Inc(w10, sigma1(w8), w3, sigma0(w11))));
 286      Round(f, g, h, a, b, c, d, e, Add(K(0xc76c51a3ul), Inc(w11, sigma1(w9), w4, sigma0(w12))));
 287      Round(e, f, g, h, a, b, c, d, Add(K(0xd192e819ul), Inc(w12, sigma1(w10), w5, sigma0(w13))));
 288      Round(d, e, f, g, h, a, b, c, Add(K(0xd6990624ul), Inc(w13, sigma1(w11), w6, sigma0(w14))));
 289      Round(c, d, e, f, g, h, a, b, Add(K(0xf40e3585ul), Inc(w14, sigma1(w12), w7, sigma0(w15))));
 290      Round(b, c, d, e, f, g, h, a, Add(K(0x106aa070ul), Inc(w15, sigma1(w13), w8, sigma0(w0))));
 291      Round(a, b, c, d, e, f, g, h, Add(K(0x19a4c116ul), Inc(w0, sigma1(w14), w9, sigma0(w1))));
 292      Round(h, a, b, c, d, e, f, g, Add(K(0x1e376c08ul), Inc(w1, sigma1(w15), w10, sigma0(w2))));
 293      Round(g, h, a, b, c, d, e, f, Add(K(0x2748774cul), Inc(w2, sigma1(w0), w11, sigma0(w3))));
 294      Round(f, g, h, a, b, c, d, e, Add(K(0x34b0bcb5ul), Inc(w3, sigma1(w1), w12, sigma0(w4))));
 295      Round(e, f, g, h, a, b, c, d, Add(K(0x391c0cb3ul), Inc(w4, sigma1(w2), w13, sigma0(w5))));
 296      Round(d, e, f, g, h, a, b, c, Add(K(0x4ed8aa4aul), Inc(w5, sigma1(w3), w14, sigma0(w6))));
 297      Round(c, d, e, f, g, h, a, b, Add(K(0x5b9cca4ful), Inc(w6, sigma1(w4), w15, sigma0(w7))));
 298      Round(b, c, d, e, f, g, h, a, Add(K(0x682e6ff3ul), Inc(w7, sigma1(w5), w0, sigma0(w8))));
 299      Round(a, b, c, d, e, f, g, h, Add(K(0x748f82eeul), Inc(w8, sigma1(w6), w1, sigma0(w9))));
 300      Round(h, a, b, c, d, e, f, g, Add(K(0x78a5636ful), Inc(w9, sigma1(w7), w2, sigma0(w10))));
 301      Round(g, h, a, b, c, d, e, f, Add(K(0x84c87814ul), Inc(w10, sigma1(w8), w3, sigma0(w11))));
 302      Round(f, g, h, a, b, c, d, e, Add(K(0x8cc70208ul), Inc(w11, sigma1(w9), w4, sigma0(w12))));
 303      Round(e, f, g, h, a, b, c, d, Add(K(0x90befffaul), Inc(w12, sigma1(w10), w5, sigma0(w13))));
 304      Round(d, e, f, g, h, a, b, c, Add(K(0xa4506cebul), Inc(w13, sigma1(w11), w6, sigma0(w14))));
 305      Round(c, d, e, f, g, h, a, b, Add(K(0xbef9a3f7ul), w14, sigma1(w12), w7, sigma0(w15)));
 306      Round(b, c, d, e, f, g, h, a, Add(K(0xc67178f2ul), w15, sigma1(w13), w8, sigma0(w0)));
 307  
 308      // Output
 309      Write4(out, 0, Add(a, K(0x6a09e667ul)));
 310      Write4(out, 4, Add(b, K(0xbb67ae85ul)));
 311      Write4(out, 8, Add(c, K(0x3c6ef372ul)));
 312      Write4(out, 12, Add(d, K(0xa54ff53aul)));
 313      Write4(out, 16, Add(e, K(0x510e527ful)));
 314      Write4(out, 20, Add(f, K(0x9b05688cul)));
 315      Write4(out, 24, Add(g, K(0x1f83d9abul)));
 316      Write4(out, 28, Add(h, K(0x5be0cd19ul)));
 317  }
 318  
 319  }
 320  
 321  #endif
 322