51 unsigned char digest[16];
103static unsigned char PADDING[64] = {
104 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
105 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
108 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
109 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
110 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
111 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
115#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
116#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
117#define H(x, y, z) ((x) ^ (y) ^ (z))
118#define I(x, y, z) ((y) ^ ((x) | (~z)))
121#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
125#define FF(a, b, c, d, x, s, ac) \
126 {(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
127 (a) = ROTATE_LEFT((a), (s)); \
130#define GG(a, b, c, d, x, s, ac) \
131 {(a) += G((b), (c), (d)) + (x) + (UINT4)(ac); \
132 (a) = ROTATE_LEFT((a), (s)); \
135#define HH(a, b, c, d, x, s, ac) \
136 {(a) += H((b), (c), (d)) + (x) + (UINT4)(ac); \
137 (a) = ROTATE_LEFT((a), (s)); \
140#define II(a, b, c, d, x, s, ac) \
141 {(a) += I((b), (c), (d)) + (x) + (UINT4)(ac); \
142 (a) = ROTATE_LEFT((a), (s)); \
148 mdContext->
i[0] = mdContext->
i[1] = (
UINT4)0;
152 mdContext->
buf[0] = (
UINT4)0x67452301;
153 mdContext->
buf[1] = (
UINT4)0xefcdab89;
154 mdContext->
buf[2] = (
UINT4)0x98badcfe;
155 mdContext->
buf[3] = (
UINT4)0x10325476;
165 mdi = (int)((mdContext->
i[0] >> 3) & 0x3F);
168 if((mdContext->
i[0] + ((
UINT4)inLen << 3)) < mdContext->
i[0])
170 mdContext->
i[0] += ((
UINT4)inLen << 3);
171 mdContext->
i[1] += ((
UINT4)inLen >> 29);
175 mdContext->
in[mdi++] = *inBuf++;
179 for(i = 0, ii = 0; i < 16; i++, ii += 4)
180 in[i] = (((
UINT4)mdContext->
in[ii+3]) << 24) |
181 (((
UINT4)mdContext->
in[ii+2]) << 16) |
182 (((
UINT4)mdContext->
in[ii+1]) << 8) |
184 Transform(mdContext->
buf, in);
198 in[14] = mdContext->
i[0];
199 in[15] = mdContext->
i[1];
202 mdi = (int)((mdContext->
i[0] >> 3) & 0x3F);
205 padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
209 for(i = 0, ii = 0; i < 14; i++, ii += 4)
210 in[i] = (((
UINT4)mdContext->
in[ii+3]) << 24) |
211 (((
UINT4)mdContext->
in[ii+2]) << 16) |
212 (((
UINT4)mdContext->
in[ii+1]) << 8) |
214 Transform(mdContext->
buf, in);
217 for(i = 0, ii = 0; i < 4; i++, ii += 4) {
218 mdContext->
digest[ii] = (
unsigned char)(mdContext->
buf[i] & 0xFF);
220 (
unsigned char)((mdContext->
buf[i] >> 8) & 0xFF);
222 (
unsigned char)((mdContext->
buf[i] >> 16) & 0xFF);
224 (
unsigned char)((mdContext->
buf[i] >> 24) & 0xFF);
230static void Transform(buf, in)
234 UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
241 FF( a, b, c, d, in[ 0],
S11, 3614090360UL);
242 FF( d, a, b, c, in[ 1],
S12, 3905402710UL);
243 FF( c, d, a, b, in[ 2],
S13, 606105819UL);
244 FF( b, c, d, a, in[ 3],
S14, 3250441966UL);
245 FF( a, b, c, d, in[ 4],
S11, 4118548399UL);
246 FF( d, a, b, c, in[ 5],
S12, 1200080426UL);
247 FF( c, d, a, b, in[ 6],
S13, 2821735955UL);
248 FF( b, c, d, a, in[ 7],
S14, 4249261313UL);
249 FF( a, b, c, d, in[ 8],
S11, 1770035416UL);
250 FF( d, a, b, c, in[ 9],
S12, 2336552879UL);
251 FF( c, d, a, b, in[10],
S13, 4294925233UL);
252 FF( b, c, d, a, in[11],
S14, 2304563134UL);
253 FF( a, b, c, d, in[12],
S11, 1804603682UL);
254 FF( d, a, b, c, in[13],
S12, 4254626195UL);
255 FF( c, d, a, b, in[14],
S13, 2792965006UL);
256 FF( b, c, d, a, in[15],
S14, 1236535329UL);
263 GG( a, b, c, d, in[ 1],
S21, 4129170786UL);
264 GG( d, a, b, c, in[ 6],
S22, 3225465664UL);
265 GG( c, d, a, b, in[11],
S23, 643717713UL);
266 GG( b, c, d, a, in[ 0],
S24, 3921069994UL);
267 GG( a, b, c, d, in[ 5],
S21, 3593408605UL);
268 GG( d, a, b, c, in[10],
S22, 38016083UL);
269 GG( c, d, a, b, in[15],
S23, 3634488961UL);
270 GG( b, c, d, a, in[ 4],
S24, 3889429448UL);
271 GG( a, b, c, d, in[ 9],
S21, 568446438UL);
272 GG( d, a, b, c, in[14],
S22, 3275163606UL);
273 GG( c, d, a, b, in[ 3],
S23, 4107603335UL);
274 GG( b, c, d, a, in[ 8],
S24, 1163531501UL);
275 GG( a, b, c, d, in[13],
S21, 2850285829UL);
276 GG( d, a, b, c, in[ 2],
S22, 4243563512UL);
277 GG( c, d, a, b, in[ 7],
S23, 1735328473UL);
278 GG( b, c, d, a, in[12],
S24, 2368359562UL);
285 HH( a, b, c, d, in[ 5],
S31, 4294588738UL);
286 HH( d, a, b, c, in[ 8],
S32, 2272392833UL);
287 HH( c, d, a, b, in[11],
S33, 1839030562UL);
288 HH( b, c, d, a, in[14],
S34, 4259657740UL);
289 HH( a, b, c, d, in[ 1],
S31, 2763975236UL);
290 HH( d, a, b, c, in[ 4],
S32, 1272893353UL);
291 HH( c, d, a, b, in[ 7],
S33, 4139469664UL);
292 HH( b, c, d, a, in[10],
S34, 3200236656UL);
293 HH( a, b, c, d, in[13],
S31, 681279174UL);
294 HH( d, a, b, c, in[ 0],
S32, 3936430074UL);
295 HH( c, d, a, b, in[ 3],
S33, 3572445317UL);
296 HH( b, c, d, a, in[ 6],
S34, 76029189UL);
297 HH( a, b, c, d, in[ 9],
S31, 3654602809UL);
298 HH( d, a, b, c, in[12],
S32, 3873151461UL);
299 HH( c, d, a, b, in[15],
S33, 530742520UL);
300 HH( b, c, d, a, in[ 2],
S34, 3299628645UL);
307 II( a, b, c, d, in[ 0],
S41, 4096336452UL);
308 II( d, a, b, c, in[ 7],
S42, 1126891415UL);
309 II( c, d, a, b, in[14],
S43, 2878612391UL);
310 II( b, c, d, a, in[ 5],
S44, 4237533241UL);
311 II( a, b, c, d, in[12],
S41, 1700485571UL);
312 II( d, a, b, c, in[ 3],
S42, 2399980690UL);
313 II( c, d, a, b, in[10],
S43, 4293915773UL);
314 II( b, c, d, a, in[ 1],
S44, 2240044497UL);
315 II( a, b, c, d, in[ 8],
S41, 1873313359UL);
316 II( d, a, b, c, in[15],
S42, 4264355552UL);
317 II( c, d, a, b, in[ 6],
S43, 2734768916UL);
318 II( b, c, d, a, in[13],
S44, 1309151649UL);
319 II( a, b, c, d, in[ 4],
S41, 4149444226UL);
320 II( d, a, b, c, in[11],
S42, 3174756917UL);
321 II( c, d, a, b, in[ 2],
S43, 718787259UL);
322 II( b, c, d, a, in[ 9],
S44, 3951481745UL);
360#include <sys/types.h>
379 unsigned int len = strlen(inString);
385 if(Digest) memcpy(Digest, mdContext.
digest, 16);
401 if(!FileName || !*FileName)
409 inFile = open(AbsFileName, O_RDONLY, 0600);
417 while((bytes = read(inFile, data, 1024)) != 0)
422 if(Digest) memcpy(Digest, mdContext.
digest, 16);
void ConvertPathType(const char *Source, char *Dest, tPathFormat DestFormat)
#define FF(a, b, c, d, x, s, ac)
#define GG(a, b, c, d, x, s, ac)
#define HH(a, b, c, d, x, s, ac)
void MD5Update(MD5_CTX *, unsigned char *, unsigned int)
bool MD5String(char *inString, byte *Digest)
#define II(a, b, c, d, x, s, ac)
bool MD5File(char *FileName, byte *Digest)