150void calc(
const void *src,
const int bytelength,
unsigned char *hash)
153 unsigned int result[5] = {0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476,
157 const unsigned char *sarray = (
const unsigned char *)src;
163 const int endOfFullBlocks = bytelength - 64;
165 int currentBlock = 0;
167 while (currentBlock <= endOfFullBlocks)
169 endCurrentBlock = currentBlock + 64;
172 for (
int roundPos = 0; currentBlock < endCurrentBlock;
177 w[roundPos++] = (
unsigned int)sarray[currentBlock + 3] |
178 (((
unsigned int)sarray[currentBlock + 2]) << 8) |
179 (((
unsigned int)sarray[currentBlock + 1]) << 16) |
180 (((
unsigned int)sarray[currentBlock]) << 24);
182 innerHash(result, w);
186 endCurrentBlock = bytelength - currentBlock;
188 int lastBlockBytes = 0;
189 for (; lastBlockBytes < endCurrentBlock; ++lastBlockBytes)
191 w[lastBlockBytes >> 2] |=
192 (
unsigned int)sarray[lastBlockBytes + currentBlock]
193 << ((3 - (lastBlockBytes & 3)) << 3);
195 w[lastBlockBytes >> 2] |= 0x80 << ((3 - (lastBlockBytes & 3)) << 3);
196 if (endCurrentBlock >= 56)
198 innerHash(result, w);
201 w[15] = bytelength << 3;
202 innerHash(result, w);
206 for (
int hashByte = 20; --hashByte >= 0;)
209 (result[hashByte >> 2] >> (((3 - hashByte) & 0x3) << 3)) & 0xff;