| 234 | } |
| 235 | |
| 236 | void MD5Crypt::append(md5_state *pms, const unsigned char *data, int nbytes) |
| 237 | { |
| 238 | const unsigned char *p = data; |
| 239 | unsigned int nbits = (unsigned int)(nbytes << 3); |
| 240 | int left = nbytes, offset = (pms->count[0] >> 3) & 63; |
| 241 | |
| 242 | if (nbytes <= 0) |
| 243 | { |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | // Update the message length |
| 248 | pms->count[1] += nbytes >> 29; |
| 249 | pms->count[0] += nbits; |
| 250 | if (pms->count[0] < nbits) |
| 251 | { |
| 252 | pms->count[1]++; |
| 253 | } |
| 254 | |
| 255 | // Process an initial partial block |
| 256 | if (offset != 0) |
| 257 | { |
| 258 | int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); |
| 259 | memcpy(pms->buf + offset, p, copy); |
| 260 | |
| 261 | if (offset + copy < 64) |
| 262 | { |
| 263 | return; |
| 264 | } |
| 265 | |
| 266 | p += copy; |
| 267 | left -= copy; |
| 268 | process(pms, pms->buf); |
| 269 | } |
| 270 | |
| 271 | // Process full blocks |
| 272 | for (; left >= 64; p += 64, left -= 64) |
| 273 | { |
| 274 | process(pms, p); |
| 275 | } |
| 276 | |
| 277 | // Process a final partial block |
| 278 | if (left != 0) |
| 279 | { |
| 280 | if (left > 63) |
| 281 | { |
| 282 | left = 63; |
| 283 | } |
| 284 | memcpy(pms->buf, p, left); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | void MD5Crypt::finish(md5_state *pms, unsigned char digest[16]) |
| 289 | { |
no test coverage detected