17 uint32_t
inline Ch(uint32_t x, uint32_t y, uint32_t z) {
return z ^ (x & (y ^ z)); }
18 uint32_t
inline Maj(uint32_t x, uint32_t y, uint32_t z) {
return (x & y) | (z & (x | y)); }
19 uint32_t
inline Sigma0(uint32_t x) {
return (x >> 2 | x << 30) ^ (x >> 13 | x << 19) ^ (x >> 22 | x << 10); }
20 uint32_t
inline Sigma1(uint32_t x) {
return (x >> 6 | x << 26) ^ (x >> 11 | x << 21) ^ (x >> 25 | x << 7); }
21 uint32_t
inline sigma0(uint32_t x) {
return (x >> 7 | x << 25) ^ (x >> 18 | x << 14) ^ (x >> 3); }
22 uint32_t
inline sigma1(uint32_t x) {
return (x >> 17 | x << 15) ^ (x >> 19 | x << 13) ^ (x >> 10); }
25 void inline Round(uint32_t a, uint32_t
b, uint32_t c, uint32_t& d, uint32_t e, uint32_t f, uint32_t g, uint32_t& h, uint32_t k, uint32_t w)
27 uint32_t t1 = h +
Sigma1(e) +
Ch(e, f, g) + k + w;
34 void inline Initialize(uint32_t* s)
47 void Transform(uint32_t* s,
const unsigned char* chunk)
49 uint32_t a = s[0],
b = s[1], c = s[2], d = s[3], e = s[4], f = s[5], g = s[6], h = s[7];
50 uint32_t w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15;
52 Round(a,
b, c, d, e, f, g, h, 0x428a2f98, w0 = ReadBE32(chunk + 0));
53 Round(h, a,
b, c, d, e, f, g, 0x71374491, w1 = ReadBE32(chunk + 4));
54 Round(g, h, a,
b, c, d, e, f, 0xb5c0fbcf, w2 = ReadBE32(chunk + 8));
55 Round(f, g, h, a,
b, c, d, e, 0xe9b5dba5, w3 = ReadBE32(chunk + 12));
56 Round(e, f, g, h, a,
b, c, d, 0x3956c25b, w4 = ReadBE32(chunk + 16));
57 Round(d, e, f, g, h, a,
b, c, 0x59f111f1, w5 = ReadBE32(chunk + 20));
58 Round(c, d, e, f, g, h, a,
b, 0x923f82a4, w6 = ReadBE32(chunk + 24));
59 Round(
b, c, d, e, f, g, h, a, 0xab1c5ed5, w7 = ReadBE32(chunk + 28));
60 Round(a,
b, c, d, e, f, g, h, 0xd807aa98, w8 = ReadBE32(chunk + 32));
61 Round(h, a,
b, c, d, e, f, g, 0x12835b01, w9 = ReadBE32(chunk + 36));
62 Round(g, h, a,
b, c, d, e, f, 0x243185be, w10 = ReadBE32(chunk + 40));
63 Round(f, g, h, a,
b, c, d, e, 0x550c7dc3, w11 = ReadBE32(chunk + 44));
64 Round(e, f, g, h, a,
b, c, d, 0x72be5d74, w12 = ReadBE32(chunk + 48));
65 Round(d, e, f, g, h, a,
b, c, 0x80deb1fe, w13 = ReadBE32(chunk + 52));
66 Round(c, d, e, f, g, h, a,
b, 0x9bdc06a7, w14 = ReadBE32(chunk + 56));
67 Round(
b, c, d, e, f, g, h, a, 0xc19bf174, w15 = ReadBE32(chunk + 60));
138 sha256::Initialize(
s);
143 const unsigned char* end = data + len;
144 size_t bufsize =
bytes % 64;
145 if (bufsize && bufsize + len >= 64) {
147 memcpy(
buf + bufsize, data, 64 - bufsize);
148 bytes += 64 - bufsize;
149 data += 64 - bufsize;
150 sha256::Transform(
s,
buf);
153 while (end >= data + 64) {
155 sha256::Transform(
s, data);
169 static const unsigned char pad[64] = {0x80};
170 unsigned char sizedesc[8];
171 WriteBE64(sizedesc,
bytes << 3);
174 WriteBE32(hash,
s[0]);
175 WriteBE32(hash + 4,
s[1]);
176 WriteBE32(hash + 8,
s[2]);
177 WriteBE32(hash + 12,
s[3]);
178 WriteBE32(hash + 16,
s[4]);
179 WriteBE32(hash + 20,
s[5]);
180 WriteBE32(hash + 24,
s[6]);
181 WriteBE32(hash + 28,
s[7]);
187 sha256::Initialize(
s);