|
|
@ -43,9 +43,10 @@ void inline Initialize(uint32_t* s) |
|
|
|
s[7] = 0x5be0cd19ul; |
|
|
|
s[7] = 0x5be0cd19ul; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Perform one SHA-256 transformation, processing a 64-byte chunk. */ |
|
|
|
/** Perform a number of SHA-256 transformations, processing 64-byte chunks. */ |
|
|
|
void Transform(uint32_t* s, const unsigned char* chunk) |
|
|
|
void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
while (blocks--) { |
|
|
|
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]; |
|
|
|
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]; |
|
|
|
uint32_t w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15; |
|
|
|
uint32_t w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15; |
|
|
|
|
|
|
|
|
|
|
@ -125,6 +126,8 @@ void Transform(uint32_t* s, const unsigned char* chunk) |
|
|
|
s[5] += f; |
|
|
|
s[5] += f; |
|
|
|
s[6] += g; |
|
|
|
s[6] += g; |
|
|
|
s[7] += h; |
|
|
|
s[7] += h; |
|
|
|
|
|
|
|
chunk += 64; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace sha256
|
|
|
|
} // namespace sha256
|
|
|
@ -147,14 +150,14 @@ CSHA256& CSHA256::Write(const unsigned char* data, size_t len) |
|
|
|
memcpy(buf + bufsize, data, 64 - bufsize); |
|
|
|
memcpy(buf + bufsize, data, 64 - bufsize); |
|
|
|
bytes += 64 - bufsize; |
|
|
|
bytes += 64 - bufsize; |
|
|
|
data += 64 - bufsize; |
|
|
|
data += 64 - bufsize; |
|
|
|
sha256::Transform(s, buf); |
|
|
|
sha256::Transform(s, buf, 1); |
|
|
|
bufsize = 0; |
|
|
|
bufsize = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
while (end >= data + 64) { |
|
|
|
if (end - data >= 64) { |
|
|
|
// Process full chunks directly from the source.
|
|
|
|
size_t blocks = (end - data) / 64; |
|
|
|
sha256::Transform(s, data); |
|
|
|
sha256::Transform(s, data, blocks); |
|
|
|
bytes += 64; |
|
|
|
data += 64 * blocks; |
|
|
|
data += 64; |
|
|
|
bytes += 64 * blocks; |
|
|
|
} |
|
|
|
} |
|
|
|
if (end > data) { |
|
|
|
if (end > data) { |
|
|
|
// Fill the buffer with what remains.
|
|
|
|
// Fill the buffer with what remains.
|
|
|
|