* Update context to reflect the concatenation of another buffer full * of bytes. */
| 47 | * of bytes. |
| 48 | */ |
| 49 | void MD5Update( MD5Context *ctx, unsigned char *buf, unsigned len) |
| 50 | { |
| 51 | uint32_t t; |
| 52 | |
| 53 | /* Update bitcount */ |
| 54 | |
| 55 | t = ctx->bits[0]; |
| 56 | if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t) |
| 57 | ctx->bits[1]++; /* Carry from low to high */ |
| 58 | ctx->bits[1] += len >> 29; |
| 59 | |
| 60 | t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ |
| 61 | |
| 62 | /* Handle any leading odd-sized chunks */ |
| 63 | if (t) |
| 64 | { |
| 65 | unsigned char *p = (unsigned char *) ctx->in + t; |
| 66 | |
| 67 | t = 64 - t; |
| 68 | if (len < t) |
| 69 | { |
| 70 | memcpy(p, buf, len); |
| 71 | return; |
| 72 | } |
| 73 | memcpy(p, buf, t); |
| 74 | byteReverse(ctx->in, 16); |
| 75 | MD5Transform(ctx->buf, (uint32_t *) ctx->in); |
| 76 | buf += t; |
| 77 | len -= t; |
| 78 | } |
| 79 | /* Process data in 64-byte chunks */ |
| 80 | while (len >= 64) |
| 81 | { |
| 82 | memcpy(ctx->in, buf, 64); |
| 83 | byteReverse(ctx->in, 16); |
| 84 | MD5Transform(ctx->buf, (uint32_t *) ctx->in); |
| 85 | buf += 64; |
| 86 | len -= 64; |
| 87 | } |
| 88 | |
| 89 | /* Handle any remaining bytes of data. */ |
| 90 | memcpy(ctx->in, buf, len); |
| 91 | } |
| 92 | |
| 93 | /* |
| 94 | * Final wrapup - pad to 64-byte boundary with the bit pattern |
no test coverage detected