2 |
- |
1 |
/*
|
|
|
2 |
* rfc1321 requires that I include this. The code is new. The constants
|
|
|
3 |
* all come from the rfc (hence the copyright). We trade a table for the
|
|
|
4 |
* macros in rfc. The total size is a lot less. -- presotto
|
|
|
5 |
*
|
|
|
6 |
* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
|
|
|
7 |
* rights reserved.
|
|
|
8 |
*
|
|
|
9 |
* License to copy and use this software is granted provided that it
|
|
|
10 |
* is identified as the "RSA Data Security, Inc. MD5 Message-Digest
|
|
|
11 |
* Algorithm" in all material mentioning or referencing this software
|
|
|
12 |
* or this function.
|
|
|
13 |
*
|
|
|
14 |
* License is also granted to make and use derivative works provided
|
|
|
15 |
* that such works are identified as "derived from the RSA Data
|
|
|
16 |
* Security, Inc. MD5 Message-Digest Algorithm" in all material
|
|
|
17 |
* mentioning or referencing the derived work.
|
|
|
18 |
*
|
|
|
19 |
* RSA Data Security, Inc. makes no representations concerning either
|
|
|
20 |
* the merchantability of this software or the suitability of this
|
|
|
21 |
* software forany particular purpose. It is provided "as is"
|
|
|
22 |
* without express or implied warranty of any kind.
|
|
|
23 |
* These notices must be retained in any copies of any part of this
|
|
|
24 |
* documentation and/or software.
|
|
|
25 |
*/
|
|
|
26 |
#define S11 7
|
|
|
27 |
#define S12 12
|
|
|
28 |
#define S13 17
|
|
|
29 |
#define S14 22
|
|
|
30 |
|
|
|
31 |
#define S21 5
|
|
|
32 |
#define S22 9
|
|
|
33 |
#define S23 14
|
|
|
34 |
#define S24 20
|
|
|
35 |
|
|
|
36 |
#define S31 4
|
|
|
37 |
#define S32 11
|
|
|
38 |
#define S33 16
|
|
|
39 |
#define S34 23
|
|
|
40 |
|
|
|
41 |
#define S41 6
|
|
|
42 |
#define S42 10
|
|
|
43 |
#define S43 15
|
|
|
44 |
#define S44 21
|
|
|
45 |
|
|
|
46 |
#define PAYME(x) $ ## x
|
|
|
47 |
|
|
|
48 |
/*
|
|
|
49 |
* SI is data
|
|
|
50 |
* a += FN(B,C,D);
|
|
|
51 |
* a += x[sh] + t[sh];
|
|
|
52 |
* a = (a << S11) | (a >> (32 - S11));
|
|
|
53 |
* a += b;
|
|
|
54 |
*/
|
|
|
55 |
|
|
|
56 |
#define BODY1(off,V,FN,SH,A,B,C,D)\
|
|
|
57 |
FN(B,C,D)\
|
|
|
58 |
leal V(A, %edi, 1), A;\
|
|
|
59 |
addl off(%ebp), A;\
|
|
|
60 |
roll PAYME(SH), A;\
|
|
|
61 |
addl B, A;\
|
|
|
62 |
|
|
|
63 |
#define BODY(off,V,FN,SH,A,B,C,D)\
|
|
|
64 |
FN(B,C,D)\
|
|
|
65 |
leal V(A, %edi, 1), A;\
|
|
|
66 |
addl (off)(%ebp), A;\
|
|
|
67 |
roll PAYME(SH), A;\
|
|
|
68 |
addl B,A;\
|
|
|
69 |
|
|
|
70 |
/*
|
|
|
71 |
* fn1 = ((c ^ d) & b) ^ d
|
|
|
72 |
*/
|
|
|
73 |
#define FN1(B,C,D)\
|
|
|
74 |
movl C, %edi;\
|
|
|
75 |
xorl D, %edi;\
|
|
|
76 |
andl B, %edi;\
|
|
|
77 |
xorl D, %edi;\
|
|
|
78 |
|
|
|
79 |
/*
|
|
|
80 |
* fn2 = ((b ^ c) & d) ^ c;
|
|
|
81 |
*/
|
|
|
82 |
#define FN2(B,C,D)\
|
|
|
83 |
movl B, %edi;\
|
|
|
84 |
xorl C, %edi;\
|
|
|
85 |
andl D, %edi;\
|
|
|
86 |
xorl C, %edi;\
|
|
|
87 |
|
|
|
88 |
/*
|
|
|
89 |
* fn3 = b ^ c ^ d;
|
|
|
90 |
*/
|
|
|
91 |
#define FN3(B,C,D)\
|
|
|
92 |
movl B, %edi;\
|
|
|
93 |
xorl C, %edi;\
|
|
|
94 |
xorl D, %edi;\
|
|
|
95 |
|
|
|
96 |
/*
|
|
|
97 |
* fn4 = c ^ (b | ~d);
|
|
|
98 |
*/
|
|
|
99 |
#define FN4(B,C,D)\
|
|
|
100 |
movl D, %edi;\
|
|
|
101 |
xorl $-1, %edi;\
|
|
|
102 |
orl B, %edi;\
|
|
|
103 |
xorl C, %edi;\
|
|
|
104 |
|
|
|
105 |
#define STACKSIZE 20
|
|
|
106 |
|
|
|
107 |
#define DATA (STACKSIZE+8)
|
|
|
108 |
#define LEN (STACKSIZE+12)
|
|
|
109 |
#define STATE (STACKSIZE+16)
|
|
|
110 |
|
|
|
111 |
#define EDATA (STACKSIZE-4)
|
|
|
112 |
#define OLDEBX (STACKSIZE-8)
|
|
|
113 |
#define OLDESI (STACKSIZE-12)
|
|
|
114 |
#define OLDEDI (STACKSIZE-16)
|
|
|
115 |
|
|
|
116 |
.text
|
|
|
117 |
|
|
|
118 |
.p2align 2,0x90
|
|
|
119 |
.globl ___md5block
|
|
|
120 |
___md5block:
|
|
|
121 |
|
|
|
122 |
.p2align 2,0x90
|
|
|
123 |
.globl __md5block
|
|
|
124 |
__md5block:
|
|
|
125 |
|
|
|
126 |
.p2align 2,0x90
|
|
|
127 |
.globl _md5block
|
|
|
128 |
_md5block:
|
|
|
129 |
|
|
|
130 |
.p2align 2,0x90
|
|
|
131 |
.globl md5block
|
|
|
132 |
md5block:
|
|
|
133 |
|
|
|
134 |
/* Prelude */
|
|
|
135 |
pushl %ebp
|
|
|
136 |
subl $(STACKSIZE), %esp
|
|
|
137 |
movl %ebx, OLDEBX(%esp)
|
|
|
138 |
movl %esi, OLDESI(%esp)
|
|
|
139 |
movl %edi, OLDEDI(%esp)
|
|
|
140 |
|
|
|
141 |
movl DATA(%esp), %eax
|
|
|
142 |
addl LEN(%esp), %eax
|
|
|
143 |
movl %eax, EDATA(%esp)
|
|
|
144 |
|
|
|
145 |
movl DATA(%esp), %ebp
|
|
|
146 |
|
|
|
147 |
0:
|
|
|
148 |
movl STATE(%esp), %esi
|
|
|
149 |
movl (%esi), %eax
|
|
|
150 |
movl 4(%esi), %ebx
|
|
|
151 |
movl 8(%esi), %ecx
|
|
|
152 |
movl 12(%esi), %edx
|
|
|
153 |
|
|
|
154 |
BODY1( 0*4,0xd76aa478,FN1,S11,%eax,%ebx,%ecx,%edx)
|
|
|
155 |
BODY1( 1*4,0xe8c7b756,FN1,S12,%edx,%eax,%ebx,%ecx)
|
|
|
156 |
BODY1( 2*4,0x242070db,FN1,S13,%ecx,%edx,%eax,%ebx)
|
|
|
157 |
BODY1( 3*4,0xc1bdceee,FN1,S14,%ebx,%ecx,%edx,%eax)
|
|
|
158 |
|
|
|
159 |
BODY1( 4*4,0xf57c0faf,FN1,S11,%eax,%ebx,%ecx,%edx)
|
|
|
160 |
BODY1( 5*4,0x4787c62a,FN1,S12,%edx,%eax,%ebx,%ecx)
|
|
|
161 |
BODY1( 6*4,0xa8304613,FN1,S13,%ecx,%edx,%eax,%ebx)
|
|
|
162 |
BODY1( 7*4,0xfd469501,FN1,S14,%ebx,%ecx,%edx,%eax)
|
|
|
163 |
|
|
|
164 |
BODY1( 8*4,0x698098d8,FN1,S11,%eax,%ebx,%ecx,%edx)
|
|
|
165 |
BODY1( 9*4,0x8b44f7af,FN1,S12,%edx,%eax,%ebx,%ecx)
|
|
|
166 |
BODY1(10*4,0xffff5bb1,FN1,S13,%ecx,%edx,%eax,%ebx)
|
|
|
167 |
BODY1(11*4,0x895cd7be,FN1,S14,%ebx,%ecx,%edx,%eax)
|
|
|
168 |
|
|
|
169 |
BODY1(12*4,0x6b901122,FN1,S11,%eax,%ebx,%ecx,%edx)
|
|
|
170 |
BODY1(13*4,0xfd987193,FN1,S12,%edx,%eax,%ebx,%ecx)
|
|
|
171 |
BODY1(14*4,0xa679438e,FN1,S13,%ecx,%edx,%eax,%ebx)
|
|
|
172 |
BODY1(15*4,0x49b40821,FN1,S14,%ebx,%ecx,%edx,%eax)
|
|
|
173 |
|
|
|
174 |
|
|
|
175 |
BODY( 1*4,0xf61e2562,FN2,S21,%eax,%ebx,%ecx,%edx)
|
|
|
176 |
BODY( 6*4,0xc040b340,FN2,S22,%edx,%eax,%ebx,%ecx)
|
|
|
177 |
BODY(11*4,0x265e5a51,FN2,S23,%ecx,%edx,%eax,%ebx)
|
|
|
178 |
BODY( 0*4,0xe9b6c7aa,FN2,S24,%ebx,%ecx,%edx,%eax)
|
|
|
179 |
|
|
|
180 |
BODY( 5*4,0xd62f105d,FN2,S21,%eax,%ebx,%ecx,%edx)
|
|
|
181 |
BODY(10*4,0x02441453,FN2,S22,%edx,%eax,%ebx,%ecx)
|
|
|
182 |
BODY(15*4,0xd8a1e681,FN2,S23,%ecx,%edx,%eax,%ebx)
|
|
|
183 |
BODY( 4*4,0xe7d3fbc8,FN2,S24,%ebx,%ecx,%edx,%eax)
|
|
|
184 |
|
|
|
185 |
BODY( 9*4,0x21e1cde6,FN2,S21,%eax,%ebx,%ecx,%edx)
|
|
|
186 |
BODY(14*4,0xc33707d6,FN2,S22,%edx,%eax,%ebx,%ecx)
|
|
|
187 |
BODY( 3*4,0xf4d50d87,FN2,S23,%ecx,%edx,%eax,%ebx)
|
|
|
188 |
BODY( 8*4,0x455a14ed,FN2,S24,%ebx,%ecx,%edx,%eax)
|
|
|
189 |
|
|
|
190 |
BODY(13*4,0xa9e3e905,FN2,S21,%eax,%ebx,%ecx,%edx)
|
|
|
191 |
BODY( 2*4,0xfcefa3f8,FN2,S22,%edx,%eax,%ebx,%ecx)
|
|
|
192 |
BODY( 7*4,0x676f02d9,FN2,S23,%ecx,%edx,%eax,%ebx)
|
|
|
193 |
BODY(12*4,0x8d2a4c8a,FN2,S24,%ebx,%ecx,%edx,%eax)
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
BODY( 5*4,0xfffa3942,FN3,S31,%eax,%ebx,%ecx,%edx)
|
|
|
197 |
BODY( 8*4,0x8771f681,FN3,S32,%edx,%eax,%ebx,%ecx)
|
|
|
198 |
BODY(11*4,0x6d9d6122,FN3,S33,%ecx,%edx,%eax,%ebx)
|
|
|
199 |
BODY(14*4,0xfde5380c,FN3,S34,%ebx,%ecx,%edx,%eax)
|
|
|
200 |
|
|
|
201 |
BODY( 1*4,0xa4beea44,FN3,S31,%eax,%ebx,%ecx,%edx)
|
|
|
202 |
BODY( 4*4,0x4bdecfa9,FN3,S32,%edx,%eax,%ebx,%ecx)
|
|
|
203 |
BODY( 7*4,0xf6bb4b60,FN3,S33,%ecx,%edx,%eax,%ebx)
|
|
|
204 |
BODY(10*4,0xbebfbc70,FN3,S34,%ebx,%ecx,%edx,%eax)
|
|
|
205 |
|
|
|
206 |
BODY(13*4,0x289b7ec6,FN3,S31,%eax,%ebx,%ecx,%edx)
|
|
|
207 |
BODY( 0*4,0xeaa127fa,FN3,S32,%edx,%eax,%ebx,%ecx)
|
|
|
208 |
BODY( 3*4,0xd4ef3085,FN3,S33,%ecx,%edx,%eax,%ebx)
|
|
|
209 |
BODY( 6*4,0x04881d05,FN3,S34,%ebx,%ecx,%edx,%eax)
|
|
|
210 |
|
|
|
211 |
BODY( 9*4,0xd9d4d039,FN3,S31,%eax,%ebx,%ecx,%edx)
|
|
|
212 |
BODY(12*4,0xe6db99e5,FN3,S32,%edx,%eax,%ebx,%ecx)
|
|
|
213 |
BODY(15*4,0x1fa27cf8,FN3,S33,%ecx,%edx,%eax,%ebx)
|
|
|
214 |
BODY( 2*4,0xc4ac5665,FN3,S34,%ebx,%ecx,%edx,%eax)
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
BODY( 0*4,0xf4292244,FN4,S41,%eax,%ebx,%ecx,%edx)
|
|
|
218 |
BODY( 7*4,0x432aff97,FN4,S42,%edx,%eax,%ebx,%ecx)
|
|
|
219 |
BODY(14*4,0xab9423a7,FN4,S43,%ecx,%edx,%eax,%ebx)
|
|
|
220 |
BODY( 5*4,0xfc93a039,FN4,S44,%ebx,%ecx,%edx,%eax)
|
|
|
221 |
|
|
|
222 |
BODY(12*4,0x655b59c3,FN4,S41,%eax,%ebx,%ecx,%edx)
|
|
|
223 |
BODY( 3*4,0x8f0ccc92,FN4,S42,%edx,%eax,%ebx,%ecx)
|
|
|
224 |
BODY(10*4,0xffeff47d,FN4,S43,%ecx,%edx,%eax,%ebx)
|
|
|
225 |
BODY( 1*4,0x85845dd1,FN4,S44,%ebx,%ecx,%edx,%eax)
|
|
|
226 |
|
|
|
227 |
BODY( 8*4,0x6fa87e4f,FN4,S41,%eax,%ebx,%ecx,%edx)
|
|
|
228 |
BODY(15*4,0xfe2ce6e0,FN4,S42,%edx,%eax,%ebx,%ecx)
|
|
|
229 |
BODY( 6*4,0xa3014314,FN4,S43,%ecx,%edx,%eax,%ebx)
|
|
|
230 |
BODY(13*4,0x4e0811a1,FN4,S44,%ebx,%ecx,%edx,%eax)
|
|
|
231 |
|
|
|
232 |
BODY( 4*4,0xf7537e82,FN4,S41,%eax,%ebx,%ecx,%edx)
|
|
|
233 |
BODY(11*4,0xbd3af235,FN4,S42,%edx,%eax,%ebx,%ecx)
|
|
|
234 |
BODY( 2*4,0x2ad7d2bb,FN4,S43,%ecx,%edx,%eax,%ebx)
|
|
|
235 |
BODY( 9*4,0xeb86d391,FN4,S44,%ebx,%ecx,%edx,%eax)
|
|
|
236 |
|
|
|
237 |
addl $(16*4), %ebp
|
|
|
238 |
movl STATE(%esp), %edi
|
|
|
239 |
addl %eax,0(%edi)
|
|
|
240 |
addl %ebx,4(%edi)
|
|
|
241 |
addl %ecx,8(%edi)
|
|
|
242 |
addl %edx,12(%edi)
|
|
|
243 |
|
|
|
244 |
movl EDATA(%esp), %edi
|
|
|
245 |
cmpl %edi, %ebp
|
|
|
246 |
jb 0b
|
|
|
247 |
|
|
|
248 |
/* Postlude */
|
|
|
249 |
movl OLDEBX(%esp), %ebx
|
|
|
250 |
movl OLDESI(%esp), %esi
|
|
|
251 |
movl OLDEDI(%esp), %edi
|
|
|
252 |
addl $(STACKSIZE), %esp
|
|
|
253 |
popl %ebp
|
|
|
254 |
ret
|
|
|
255 |
|