5 * rfc1321 requires that I include this. The code is new. The constants
6 * all come from the rfc (hence the copyright). We trade a table for the
7 * macros in rfc. The total size is a lot less. -- presotto
9 * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
12 * License to copy and use this software is granted provided that it
13 * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
14 * Algorithm" in all material mentioning or referencing this software
17 * License is also granted to make and use derivative works provided
18 * that such works are identified as "derived from the RSA Data
19 * Security, Inc. MD5 Message-Digest Algorithm" in all material
20 * mentioning or referencing the derived work.
22 * RSA Data Security, Inc. makes no representations concerning either
23 * the merchantability of this software or the suitability of this
24 * software forany particular purpose. It is provided "as is"
25 * without express or implied warranty of any kind.
26 * These notices must be retained in any copies of any part of this
27 * documentation and/or software.
31 * Rotate ammounts used in the algorithm
56 static u32int md5tab[] =
131 static void decode(u32int*, uchar*, ulong);
132 extern void _md5block(uchar *p, ulong len, u32int *s);
135 _md5block(uchar *p, ulong len, u32int *s)
137 u32int a, b, c, d, sh;
142 for(end = p+len; p < end; p += 64){
152 for(; sh != 16; t += 4){
153 a += ((c ^ d) & b) ^ d;
155 a = (a << S11) | (a >> (32 - S11));
158 d += ((b ^ c) & a) ^ c;
159 d += x[sh + 1] + t[1];
160 d = (d << S12) | (d >> (32 - S12));
163 c += ((a ^ b) & d) ^ b;
164 c += x[sh + 2] + t[2];
165 c = (c << S13) | (c >> (32 - S13));
168 b += ((d ^ a) & c) ^ a;
169 b += x[sh + 3] + t[3];
170 b = (b << S14) | (b >> (32 - S14));
176 for(; sh != 1+20*4; t += 4){
177 a += ((b ^ c) & d) ^ c;
178 a += x[sh & 0xf] + t[0];
179 a = (a << S21) | (a >> (32 - S21));
182 d += ((a ^ b) & c) ^ b;
183 d += x[(sh + 5) & 0xf] + t[1];
184 d = (d << S22) | (d >> (32 - S22));
187 c += ((d ^ a) & b) ^ a;
188 c += x[(sh + 10) & 0xf] + t[2];
189 c = (c << S23) | (c >> (32 - S23));
192 b += ((c ^ d) & a) ^ d;
193 b += x[(sh + 15) & 0xf] + t[3];
194 b = (b << S24) | (b >> (32 - S24));
200 for(; sh != 5+12*4; t += 4){
202 a += x[sh & 0xf] + t[0];
203 a = (a << S31) | (a >> (32 - S31));
207 d += x[(sh + 3) & 0xf] + t[1];
208 d = (d << S32) | (d >> (32 - S32));
212 c += x[(sh + 6) & 0xf] + t[2];
213 c = (c << S33) | (c >> (32 - S33));
217 b += x[(sh + 9) & 0xf] + t[3];
218 b = (b << S34) | (b >> (32 - S34));
224 for(; sh != 28*4; t += 4){
226 a += x[sh & 0xf] + t[0];
227 a = (a << S41) | (a >> (32 - S41));
231 d += x[(sh + 7) & 0xf] + t[1];
232 d = (d << S42) | (d >> (32 - S42));
236 c += x[(sh + 14) & 0xf] + t[2];
237 c = (c << S43) | (c >> (32 - S43));
241 b += x[(sh + 21) & 0xf] + t[3];
242 b = (b << S44) | (b >> (32 - S44));
256 * decodes input (uchar) into output (u32int). Assumes len is
260 decode(u32int *output, uchar *input, ulong len)
264 for(e = input+len; input < e; input += 4)
265 *output++ = input[0] | (input[1] << 8) |
266 (input[2] << 16) | (input[3] << 24);