1#include "gadgetconfig.h"
14#include "../data/allvars.h"
15#include "../data/dtypes.h"
56static void MD5Update(
MD5_CTX *mdContext,
unsigned char *inBuf,
unsigned int inLen);
58static unsigned char PADDING[64] = {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
64#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
65#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
66#define H(x, y, z) ((x) ^ (y) ^ (z))
67#define I(x, y, z) ((y) ^ ((x) | (~z)))
70#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
74#define FF(a, b, c, d, x, s, ac) \
76 (a) += F((b), (c), (d)) + (x) + (UINT4)(ac); \
77 (a) = ROTATE_LEFT((a), (s)); \
80#define GG(a, b, c, d, x, s, ac) \
82 (a) += G((b), (c), (d)) + (x) + (UINT4)(ac); \
83 (a) = ROTATE_LEFT((a), (s)); \
86#define HH(a, b, c, d, x, s, ac) \
88 (a) += H((b), (c), (d)) + (x) + (UINT4)(ac); \
89 (a) = ROTATE_LEFT((a), (s)); \
92#define II(a, b, c, d, x, s, ac) \
94 (a) += I((b), (c), (d)) + (x) + (UINT4)(ac); \
95 (a) = ROTATE_LEFT((a), (s)); \
101 mdContext->
i[0] = mdContext->
i[1] = (
UINT4)0;
105 mdContext->
buf[0] = (
UINT4)0x67452301;
106 mdContext->
buf[1] = (
UINT4)0xefcdab89;
107 mdContext->
buf[2] = (
UINT4)0x98badcfe;
108 mdContext->
buf[3] = (
UINT4)0x10325476;
115 unsigned int inLen = 0x10000000;
116 if(inLen > inLenLong)
118 MD5Update(mdContext, inBuf, inLen);
124void MD5Update(
MD5_CTX *mdContext,
unsigned char *inBuf,
unsigned int inLen)
131 mdi = (int)((mdContext->
i[0] >> 3) & 0x3F);
134 if((mdContext->
i[0] + ((
UINT4)inLen << 3)) < mdContext->
i[0])
136 mdContext->
i[0] += ((
UINT4)inLen << 3);
137 mdContext->
i[1] += ((
UINT4)inLen >> 29);
142 mdContext->
in[mdi++] = *inBuf++;
147 for(i = 0, ii = 0; i < 16; i++, ii += 4)
148 in[i] = (((
UINT4)mdContext->
in[ii + 3]) << 24) | (((
UINT4)mdContext->
in[ii + 2]) << 16) |
149 (((
UINT4)mdContext->
in[ii + 1]) << 8) | ((
UINT4)mdContext->
in[ii]);
150 Transform(mdContext->
buf, in);
164 in[14] = mdContext->
i[0];
165 in[15] = mdContext->
i[1];
168 mdi = (int)((mdContext->
i[0] >> 3) & 0x3F);
171 padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
172 MD5Update(mdContext, PADDING, padLen);
175 for(i = 0, ii = 0; i < 14; i++, ii += 4)
176 in[i] = (((
UINT4)mdContext->
in[ii + 3]) << 24) | (((
UINT4)mdContext->
in[ii + 2]) << 16) | (((
UINT4)mdContext->
in[ii + 1]) << 8) |
178 Transform(mdContext->
buf, in);
181 for(i = 0, ii = 0; i < 4; i++, ii += 4)
183 mdContext->
digest[ii] = (
unsigned char)(mdContext->
buf[i] & 0xFF);
184 mdContext->
digest[ii + 1] = (
unsigned char)((mdContext->
buf[i] >> 8) & 0xFF);
185 mdContext->
digest[ii + 2] = (
unsigned char)((mdContext->
buf[i] >> 16) & 0xFF);
186 mdContext->
digest[ii + 3] = (
unsigned char)((mdContext->
buf[i] >> 24) & 0xFF);
194 UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
201 FF(a, b, c, d, in[0], S11, 3614090360);
202 FF(d, a, b, c, in[1], S12, 3905402710);
203 FF(c, d, a, b, in[2], S13, 606105819);
204 FF(b, c, d, a, in[3], S14, 3250441966);
205 FF(a, b, c, d, in[4], S11, 4118548399);
206 FF(d, a, b, c, in[5], S12, 1200080426);
207 FF(c, d, a, b, in[6], S13, 2821735955);
208 FF(b, c, d, a, in[7], S14, 4249261313);
209 FF(a, b, c, d, in[8], S11, 1770035416);
210 FF(d, a, b, c, in[9], S12, 2336552879);
211 FF(c, d, a, b, in[10], S13, 4294925233);
212 FF(b, c, d, a, in[11], S14, 2304563134);
213 FF(a, b, c, d, in[12], S11, 1804603682);
214 FF(d, a, b, c, in[13], S12, 4254626195);
215 FF(c, d, a, b, in[14], S13, 2792965006);
216 FF(b, c, d, a, in[15], S14, 1236535329);
223 GG(a, b, c, d, in[1], S21, 4129170786);
224 GG(d, a, b, c, in[6], S22, 3225465664);
225 GG(c, d, a, b, in[11], S23, 643717713);
226 GG(b, c, d, a, in[0], S24, 3921069994);
227 GG(a, b, c, d, in[5], S21, 3593408605);
228 GG(d, a, b, c, in[10], S22, 38016083);
229 GG(c, d, a, b, in[15], S23, 3634488961);
230 GG(b, c, d, a, in[4], S24, 3889429448);
231 GG(a, b, c, d, in[9], S21, 568446438);
232 GG(d, a, b, c, in[14], S22, 3275163606);
233 GG(c, d, a, b, in[3], S23, 4107603335);
234 GG(b, c, d, a, in[8], S24, 1163531501);
235 GG(a, b, c, d, in[13], S21, 2850285829);
236 GG(d, a, b, c, in[2], S22, 4243563512);
237 GG(c, d, a, b, in[7], S23, 1735328473);
238 GG(b, c, d, a, in[12], S24, 2368359562);
245 HH(a, b, c, d, in[5], S31, 4294588738);
246 HH(d, a, b, c, in[8], S32, 2272392833);
247 HH(c, d, a, b, in[11], S33, 1839030562);
248 HH(b, c, d, a, in[14], S34, 4259657740);
249 HH(a, b, c, d, in[1], S31, 2763975236);
250 HH(d, a, b, c, in[4], S32, 1272893353);
251 HH(c, d, a, b, in[7], S33, 4139469664);
252 HH(b, c, d, a, in[10], S34, 3200236656);
253 HH(a, b, c, d, in[13], S31, 681279174);
254 HH(d, a, b, c, in[0], S32, 3936430074);
255 HH(c, d, a, b, in[3], S33, 3572445317);
256 HH(b, c, d, a, in[6], S34, 76029189);
257 HH(a, b, c, d, in[9], S31, 3654602809);
258 HH(d, a, b, c, in[12], S32, 3873151461);
259 HH(c, d, a, b, in[15], S33, 530742520);
260 HH(b, c, d, a, in[2], S34, 3299628645);
267 II(a, b, c, d, in[0], S41, 4096336452);
268 II(d, a, b, c, in[7], S42, 1126891415);
269 II(c, d, a, b, in[14], S43, 2878612391);
270 II(b, c, d, a, in[5], S44, 4237533241);
271 II(a, b, c, d, in[12], S41, 1700485571);
272 II(d, a, b, c, in[3], S42, 2399980690);
273 II(c, d, a, b, in[10], S43, 4293915773);
274 II(b, c, d, a, in[1], S44, 2240044497);
275 II(a, b, c, d, in[8], S41, 1873313359);
276 II(d, a, b, c, in[15], S42, 4264355552);
277 II(c, d, a, b, in[6], S43, 2734768916);
278 II(b, c, d, a, in[13], S44, 1309151649);
279 II(a, b, c, d, in[4], S41, 4149444226);
280 II(d, a, b, c, in[11], S42, 3174756917);
281 II(c, d, a, b, in[2], S43, 718787259);
282 II(b, c, d, a, in[9], S44, 3951481745);
definition and prototypes for MD5 routines
void MD5UpdateLong(MD5_CTX *mdContext, unsigned char *inBuf, unsigned long long inLenLong)
void MD5Init(MD5_CTX *mdContext)
void MD5Final(MD5_CTX *mdContext)