MCPcopy Create free account
hub / github.com/acl-dev/acl / md5_final

Function md5_final

lib_acl_cpp/samples/md5/md5_c.cpp:85–114  ·  view source on GitHub ↗

* Final wrapup - pad to 64-byte boundary with the bit pattern * 1 0* (64-bit count of bits processed, MSB-first) */

Source from the content-addressed store, hash-verified

83 * 1 0* (64-bit count of bits processed, MSB-first)
84 */
85void 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

Callers 2

md5_keyFunction · 0.85
md5_stringFunction · 0.85

Calls 3

md5_transformFunction · 0.85
memcpyFunction · 0.85
byteSwapFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…