MCPcopy Create free account
hub / github.com/VirtualGL/virtualgl / MD5Final

Function MD5Final

util/md5.c:134–174  ·  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

132 * 1 0* (64-bit count of bits processed, MSB-first)
133 */
134void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
135{
136 unsigned int count;
137 unsigned char *p;
138 uint32 *in32 = (uint32 *)ctx->in;
139
140 /* Compute number of bytes mod 64 */
141 count = (ctx->bits[0] >> 3) & 0x3F;
142
143 /* Set the first char of padding to 0x80. This is safe since there is
144 always at least one byte free */
145 p = ctx->in + count;
146 *p++ = 0x80;
147
148 /* Bytes of padding needed to make 64 bytes */
149 count = 64 - 1 - count;
150
151 /* Pad out to 56 mod 64 */
152 if (count < 8) {
153 /* Two lots of padding: Pad the first block to 64 bytes */
154 memset(p, 0, count);
155 byteReverse(ctx->in, 16);
156 MD5Transform(ctx->buf, (uint32 *)ctx->in);
157
158 /* Now fill the next block with 56 bytes */
159 memset(ctx->in, 0, 56);
160 } else {
161 /* Pad block to 56 bytes */
162 memset(p, 0, count - 8);
163 }
164 byteReverse(ctx->in, 14);
165
166 /* Append length in bits and transform */
167 in32[14] = ctx->bits[0];
168 in32[15] = ctx->bits[1];
169
170 MD5Transform(ctx->buf, (uint32 *)ctx->in);
171 byteReverse((unsigned char *)ctx->buf, 4);
172 memcpy(digest, ctx->buf, 16);
173 memset(ctx, 0, sizeof(struct MD5Context)); /* In case it's sensitive */
174}
175
176
177/* The four core functions - F1 is optimized somewhat */

Callers 1

MD5EndFunction · 0.85

Calls 2

byteReverseFunction · 0.85
MD5TransformFunction · 0.85

Tested by

no test coverage detected