127 {
128
129 unsigned int result[5] = { 0x67452301, 0xefcdab89, 0x98badcfe,
130 0x10325476, 0xc3d2e1f0 };
131
132
133 unsigned char const * sarray = (unsigned char const *) src;
134
135
136 unsigned int w[80];
137
138
139
140 size_t endCurrentBlock;
141 size_t currentBlock = 0;
142
143 if (bytelength >= 64) {
144 size_t const endOfFullBlocks = bytelength - 64;
145
146 while (currentBlock <= endOfFullBlocks) {
147 endCurrentBlock = currentBlock + 64;
148
149
150 for (int roundPos = 0; currentBlock < endCurrentBlock; currentBlock += 4)
151 {
152
153
154 w[roundPos++] = (unsigned int) sarray[currentBlock + 3]
155 | (((unsigned int) sarray[currentBlock + 2]) << 8)
156 | (((unsigned int) sarray[currentBlock + 1]) << 16)
157 | (((unsigned int) sarray[currentBlock]) << 24);
158 }
159 innerHash(result, w);
160 }
161 }
162
163
164 endCurrentBlock = bytelength - currentBlock;
165 clearWBuffert(w);
166 size_t lastBlockBytes = 0;
167 for (;lastBlockBytes < endCurrentBlock; ++lastBlockBytes) {
168 w[lastBlockBytes >> 2] |= (unsigned int) sarray[lastBlockBytes + currentBlock] << ((3 - (lastBlockBytes & 3)) << 3);
169 }
170
171 w[lastBlockBytes >> 2] |= 0x80 << ((3 - (lastBlockBytes & 3)) << 3);
172 if (endCurrentBlock >= 56) {
173 innerHash(result, w);
174 clearWBuffert(w);
175 }
176 w[15] = bytelength << 3;
177 innerHash(result, w);
178
179
180
181 for (int hashByte = 20; --hashByte >= 0;) {
182 hash[hashByte] = (result[hashByte >> 2] >> (((3 - hashByte) & 0x3) << 3)) & 0xff;
183 }
184}