* Final wrapup - pad to 64-byte boundary with the bit pattern * 1 0* (64-bit count of bits processed, MSB-first) */
| 83 | * 1 0* (64-bit count of bits processed, MSB-first) |
| 84 | */ |
| 85 | void md5_final(unsigned char digest[16], md5_ctx *ctx) |
| 86 | { |
| 87 | int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */ |
| 88 | uint8_t *p = (uint8_t *) ctx->in + count; |
| 89 | |
| 90 | /* Set the first char of padding to 0x80. There is always room. */ |
| 91 | *p++ = 0x80; |
| 92 | |
| 93 | /* Bytes of padding needed to make 56 bytes (-8..55) */ |
| 94 | count = 56 - 1 - count; |
| 95 | |
| 96 | if (count < 0) { /* Padding forces an extra block */ |
| 97 | memset(p, 0, count + 8); |
| 98 | byteSwap(ctx->in, 16); |
| 99 | md5_transform(ctx->buf, ctx->in); |
| 100 | p = (uint8_t *) ctx->in; |
| 101 | count = 56; |
| 102 | } |
| 103 | memset(p, 0, count); |
| 104 | byteSwap(ctx->in, 14); |
| 105 | |
| 106 | /* Append length in bits and transform */ |
| 107 | ctx->in[14] = ctx->bytes[0] << 3; |
| 108 | ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29; |
| 109 | md5_transform(ctx->buf, ctx->in); |
| 110 | |
| 111 | byteSwap(ctx->buf, 4); |
| 112 | memcpy(digest, ctx->buf, 16); |
| 113 | memset(ctx, 0, sizeof(md5_ctx)); /* In case it's sensitive */ |
| 114 | } |
| 115 | |
| 116 | /* The four core functions - F1 is optimized somewhat */ |
| 117 |
no test coverage detected
searching dependent graphs…