MCPcopy Create free account
hub / github.com/DFHack/dfhack / MD5Final

Function MD5Final

depends/md5/md5.cpp:97–139  ·  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

95 * 1 0* (64-bit count of bits processed, MSB-first)
96 */
97void MD5Final(unsigned char digest[16], MD5Context *ctx)
98{
99 unsigned count;
100 unsigned char *p;
101
102 /* Compute number of bytes mod 64 */
103 count = (ctx->bits[0] >> 3) & 0x3F;
104
105 /* Set the first char of padding to 0x80. This is safe since there is
106 always at least one byte free */
107 p = ctx->in + count;
108 *p++ = 0x80;
109
110 /* Bytes of padding needed to make 64 bytes */
111 count = 64 - 1 - count;
112
113 /* Pad out to 56 mod 64 */
114 if (count < 8)
115 {
116 /* Two lots of padding: Pad the first block to 64 bytes */
117 memset(p, 0, count);
118 byteReverse(ctx->in, 16);
119 MD5Transform(ctx->buf, (uint32_t *) ctx->in);
120
121 /* Now fill the next block with 56 bytes */
122 memset(ctx->in, 0, 56);
123 }
124 else
125 {
126 /* Pad block to 56 bytes */
127 memset(p, 0, count - 8);
128 }
129 byteReverse(ctx->in, 14);
130
131 /* Append length in bits and transform */
132 ((uint32_t *) ctx->in)[14] = ctx->bits[0];
133 ((uint32_t *) ctx->in)[15] = ctx->bits[1];
134
135 MD5Transform(ctx->buf, (uint32_t *) ctx->in);
136 byteReverse((unsigned char *) ctx->buf, 4);
137 memcpy(digest, ctx->buf, 16);
138 memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
139}
140
141
142/* The four core functions - F1 is optimized somewhat */

Callers 2

hashitMethod · 0.85
getHashFromFileMethod · 0.85

Calls 2

byteReverseFunction · 0.85
MD5TransformFunction · 0.85

Tested by

no test coverage detected