68 #include "pedigree/kernel/utilities/md5/md5.h" 69 #include "pedigree/kernel/utilities/utility.h" 92 static unsigned char PADDING[64] = {
93 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
94 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
95 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
98 #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 99 #define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 100 #define H(x, y, z) ((x) ^ (y) ^ (z)) 101 #define I(x, y, z) ((y) ^ ((x) | (~z))) 107 #define ROTATE_LEFT(x, n) (((x) << (n)) | (((unsigned int) x) >> (32 - (n)))) 113 #define FF(a, b, c, d, x, s, ac) \ 115 (a) += F((b), (c), (d)) + (x) + (unsigned long int) (ac); \ 116 (a) = ROTATE_LEFT((a), (s)); \ 120 #define GG(a, b, c, d, x, s, ac) \ 122 (a) += G((b), (c), (d)) + (x) + (unsigned long int) (ac); \ 123 (a) = ROTATE_LEFT((a), (s)); \ 126 #define HH(a, b, c, d, x, s, ac) \ 128 (a) += H((b), (c), (d)) + (x) + (unsigned long int) (ac); \ 129 (a) = ROTATE_LEFT((a), (s)); \ 132 #define II(a, b, c, d, x, s, ac) \ 134 (a) += I((b), (c), (d)) + (x) + (unsigned long int) (ac); \ 135 (a) = ROTATE_LEFT((a), (s)); \ 149 unsigned long int a = state[0], b = state[1], c = state[2], d = state[3],
155 FF(a, b, c, d, x[0], S11, 0xd76aa478);
156 FF(d, a, b, c, x[1], S12, 0xe8c7b756);
157 FF(c, d, a, b, x[2], S13, 0x242070db);
158 FF(b, c, d, a, x[3], S14, 0xc1bdceee);
159 FF(a, b, c, d, x[4], S11, 0xf57c0faf);
160 FF(d, a, b, c, x[5], S12, 0x4787c62a);
161 FF(c, d, a, b, x[6], S13, 0xa8304613);
162 FF(b, c, d, a, x[7], S14, 0xfd469501);
163 FF(a, b, c, d, x[8], S11, 0x698098d8);
164 FF(d, a, b, c, x[9], S12, 0x8b44f7af);
165 FF(c, d, a, b, x[10], S13, 0xffff5bb1);
166 FF(b, c, d, a, x[11], S14, 0x895cd7be);
167 FF(a, b, c, d, x[12], S11, 0x6b901122);
168 FF(d, a, b, c, x[13], S12, 0xfd987193);
169 FF(c, d, a, b, x[14], S13, 0xa679438e);
170 FF(b, c, d, a, x[15], S14, 0x49b40821);
173 GG(a, b, c, d, x[1], S21, 0xf61e2562);
174 GG(d, a, b, c, x[6], S22, 0xc040b340);
175 GG(c, d, a, b, x[11], S23, 0x265e5a51);
176 GG(b, c, d, a, x[0], S24, 0xe9b6c7aa);
177 GG(a, b, c, d, x[5], S21, 0xd62f105d);
178 GG(d, a, b, c, x[10], S22, 0x2441453);
179 GG(c, d, a, b, x[15], S23, 0xd8a1e681);
180 GG(b, c, d, a, x[4], S24, 0xe7d3fbc8);
181 GG(a, b, c, d, x[9], S21, 0x21e1cde6);
182 GG(d, a, b, c, x[14], S22, 0xc33707d6);
183 GG(c, d, a, b, x[3], S23, 0xf4d50d87);
185 GG(b, c, d, a, x[8], S24, 0x455a14ed);
186 GG(a, b, c, d, x[13], S21, 0xa9e3e905);
187 GG(d, a, b, c, x[2], S22, 0xfcefa3f8);
188 GG(c, d, a, b, x[7], S23, 0x676f02d9);
189 GG(b, c, d, a, x[12], S24, 0x8d2a4c8a);
192 HH(a, b, c, d, x[5], S31, 0xfffa3942);
193 HH(d, a, b, c, x[8], S32, 0x8771f681);
194 HH(c, d, a, b, x[11], S33, 0x6d9d6122);
195 HH(b, c, d, a, x[14], S34, 0xfde5380c);
196 HH(a, b, c, d, x[1], S31, 0xa4beea44);
197 HH(d, a, b, c, x[4], S32, 0x4bdecfa9);
198 HH(c, d, a, b, x[7], S33, 0xf6bb4b60);
199 HH(b, c, d, a, x[10], S34, 0xbebfbc70);
200 HH(a, b, c, d, x[13], S31, 0x289b7ec6);
201 HH(d, a, b, c, x[0], S32, 0xeaa127fa);
202 HH(c, d, a, b, x[3], S33, 0xd4ef3085);
203 HH(b, c, d, a, x[6], S34, 0x4881d05);
204 HH(a, b, c, d, x[9], S31, 0xd9d4d039);
205 HH(d, a, b, c, x[12], S32, 0xe6db99e5);
206 HH(c, d, a, b, x[15], S33, 0x1fa27cf8);
207 HH(b, c, d, a, x[2], S34, 0xc4ac5665);
210 II(a, b, c, d, x[0], S41, 0xf4292244);
211 II(d, a, b, c, x[7], S42, 0x432aff97);
212 II(c, d, a, b, x[14], S43, 0xab9423a7);
213 II(b, c, d, a, x[5], S44, 0xfc93a039);
214 II(a, b, c, d, x[12], S41, 0x655b59c3);
215 II(d, a, b, c, x[3], S42, 0x8f0ccc92);
216 II(c, d, a, b, x[10], S43, 0xffeff47d);
217 II(b, c, d, a, x[1], S44, 0x85845dd1);
218 II(a, b, c, d, x[8], S41, 0x6fa87e4f);
219 II(d, a, b, c, x[15], S42, 0xfe2ce6e0);
220 II(c, d, a, b, x[6], S43, 0xa3014314);
221 II(b, c, d, a, x[13], S44, 0x4e0811a1);
222 II(a, b, c, d, x[4], S41, 0xf7537e82);
223 II(d, a, b, c, x[11], S42, 0xbd3af235);
224 II(c, d, a, b, x[2], S43, 0x2ad7d2bb);
225 II(b, c, d, a, x[9], S44, 0xeb86d391);
246 unsigned char *output,
unsigned long int *input,
unsigned int len)
250 for (i = 0, j = 0; j < len; i++, j += 4)
252 output[j] = (
unsigned char) (input[i] & 0xff);
253 output[j + 1] = (
unsigned char) ((input[i] >> 8) & 0xff);
254 output[j + 2] = (
unsigned char) ((input[i] >> 16) & 0xff);
255 output[j + 3] = (
unsigned char) ((input[i] >> 24) & 0xff);
267 unsigned long int *output,
unsigned char *input,
unsigned int len)
271 for (i = 0, j = 0; j < len; i++, j += 4)
272 output[i] = ((
unsigned long int) input[j]) |
273 (((
unsigned long int) input[j + 1]) << 8) |
274 (((
unsigned long int) input[j + 2]) << 16) |
275 (((
unsigned long int) input[j + 3]) << 24);
287 MemoryCopy(output, input, len);
300 ByteSet(output, value, len);
313 state[0] = 0x67452301;
314 state[1] = 0xefcdab89;
315 state[2] = 0x98badcfe;
316 state[3] = 0x10325476;
328 unsigned int i, index, partLen;
331 index = (
unsigned int) ((
count[0] >> 3) & 0x3F);
334 if ((
count[0] += ((
unsigned long int) inputLen << 3)) <
335 ((
unsigned long int) inputLen << 3))
338 count[1] += ((
unsigned long int) inputLen >> 29);
339 partLen = 64 - index;
344 if (inputLen >= partLen)
349 for (i = partLen; i + 63 < inputLen; i += 64)
370 unsigned char bits[8];
371 unsigned int index, padLen;
379 index = (
unsigned int) ((
count[0] >> 3) & 0x3f);
380 padLen = (index < 56) ? (56 - index) : (120 - index);
381 Input(PADDING, padLen);
void Input(unsigned char *input, unsigned int inputLen)
Block update operation. Continues an md5 message-digest operation, processing another message block...
void Decode(unsigned long int *output, unsigned char *input, unsigned int len)
Decodes input data into output.
void Encode(unsigned char *output, unsigned long int *input, unsigned int len)
Encodes input data.
unsigned long int count[2]
void MD5Transform(unsigned long int state[4], unsigned char block[64])
Basic transformation. Transforms state based on block.
unsigned long int state[4]
void MD5_memcpy(POINTER output, POINTER input, unsigned int len)
internal memory management
void MD5_memset(POINTER output, int value, unsigned int len)
internal memory management
void Result(unsigned char digest[16])
Finalization ends the md5 message-digest operation, writing the the message digest and zeroizing the ...
void Reset()
Initialization begins an operation, writing a new context.