aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/rc4/asm/r4-win32.asm
blob: 70b0f7484cd6d88e44cad0cbf62276c50b392b41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
	; Don't even think of reading this code
	; It was automatically generated by rc4-586.pl
	; Which is a perl program used to generate the x86 assember for
	; any of elf, a.out, BSDI,Win32, or Solaris
	; eric <eay@cryptsoft.com>
	; 
	TITLE	rc4-586.asm
        .386
.model FLAT
_TEXT	SEGMENT
PUBLIC	_RC4

_RC4 PROC NEAR
	; 
	push	ebp
	push	ebx
	mov	ebp,		DWORD PTR 12[esp]
	mov	ebx,		DWORD PTR 16[esp]
	push	esi
	push	edi
	mov	ecx,		DWORD PTR [ebp]
	mov	edx,		DWORD PTR 4[ebp]
	mov	esi,		DWORD PTR 28[esp]
	inc	ecx
	sub	esp,		12
	add	ebp,		8
	and	ecx,		255
	lea	ebx,		DWORD PTR [esi+ebx-8]
	mov	edi,		DWORD PTR 44[esp]
	mov	DWORD PTR 8[esp],ebx
	mov	eax,		DWORD PTR [ecx*4+ebp]
	cmp	ebx,		esi
	jl	$L000end
L001start:
	add	esi,		8
	; Round 0
	add	edx,		eax
	and	edx,		255
	inc	ecx
	mov	ebx,		DWORD PTR [edx*4+ebp]
	mov	DWORD PTR [ecx*4+ebp-4],ebx
	add	ebx,		eax
	and	ecx,		255
	and	ebx,		255
	mov	DWORD PTR [edx*4+ebp],eax
	nop
	mov	ebx,		DWORD PTR [ebx*4+ebp]
	mov	eax,		DWORD PTR [ecx*4+ebp]
	mov	BYTE PTR [esp],	bl
	; Round 1
	add	edx,		eax
	and	edx,		255
	inc	ecx
	mov	ebx,		DWORD PTR [edx*4+ebp]
	mov	DWORD PTR [ecx*4+ebp-4],ebx
	add	ebx,		eax
	and	ecx,		255
	and	ebx,		255
	mov	DWORD PTR [edx*4+ebp],eax
	nop
	mov	ebx,		DWORD PTR [ebx*4+ebp]
	mov	eax,		DWORD PTR [ecx*4+ebp]
	mov	BYTE PTR 1[esp],bl
	; Round 2
	add	edx,		eax
	and	edx,		255
	inc	ecx
	mov	ebx,		DWORD PTR [edx*4+ebp]
	mov	DWORD PTR [ecx*4+ebp-4],ebx
	add	ebx,		eax
	and	ecx,		255
	and	ebx,		255
	mov	DWORD PTR [edx*4+ebp],eax
	nop
	mov	ebx,		DWORD PTR [ebx*4+ebp]
	mov	eax,		DWORD PTR [ecx*4+ebp]
	mov	BYTE PTR 2[esp],bl
	; Round 3
	add	edx,		eax
	and	edx,		255
	inc	ecx
	mov	ebx,		DWORD PTR [edx*4+ebp]
	mov	DWORD PTR [ecx*4+ebp-4],ebx
	add	ebx,		eax
	and	ecx,		255
	and	ebx,		255
	mov	DWORD PTR [edx*4+ebp],eax
	nop
	mov	ebx,		DWORD PTR [ebx*4+ebp]
	mov	eax,		DWORD PTR [ecx*4+ebp]
	mov	BYTE PTR 3[esp],bl
	; Round 4
	add	edx,		eax
	and	edx,		255
	inc	ecx
	mov	ebx,		DWORD PTR [edx*4+ebp]
	mov	DWORD PTR [ecx*4+ebp-4],ebx
	add	ebx,		eax
	and	ecx,		255
	and	ebx,		255
	mov	DWORD PTR [edx*4+ebp],eax
	nop
	mov	ebx,		DWORD PTR [ebx*4+ebp]
	mov	eax,		DWORD PTR [ecx*4+ebp]
	mov	BYTE PTR 4[esp],bl
	; Round 5
	add	edx,		eax
	and	edx,		255
	inc	ecx
	mov	ebx,		DWORD PTR [edx*4+ebp]
	mov	DWORD PTR [ecx*4+ebp-4],ebx
	add	ebx,		eax
	and	ecx,		255
	and	ebx,		255
	mov	DWORD PTR [edx*4+ebp],eax
	nop
	mov	ebx,		DWORD PTR [ebx*4+ebp]
	mov	eax,		DWORD PTR [ecx*4+ebp]
	mov	BYTE PTR 5[esp],bl
	; Round 6
	add	edx,		eax
	and	edx,		255
	inc	ecx
	mov	ebx,		DWORD PTR [edx*4+ebp]
	mov	DWORD PTR [ecx*4+ebp-4],ebx
	add	ebx,		eax
	and	ecx,		255
	and	ebx,		255
	mov	DWORD PTR [edx*4+ebp],eax
	nop
	mov	ebx,		DWORD PTR [ebx*4+ebp]
	mov	eax,		DWORD PTR [ecx*4+ebp]
	mov	BYTE PTR 6[esp],bl
	; Round 7
	add	edx,		eax
	and	edx,		255
	inc	ecx
	mov	ebx,		DWORD PTR [edx*4+ebp]
	mov	DWORD PTR [ecx*4+ebp-4],ebx
	add	ebx,		eax
	and	ecx,		255
	and	ebx,		255
	mov	DWORD PTR [edx*4+ebp],eax
	nop
	mov	ebx,		DWORD PTR [ebx*4+ebp]
	add	edi,		8
	mov	BYTE PTR 7[esp],bl
	; apply the cipher text
	mov	eax,		DWORD PTR [esp]
	mov	ebx,		DWORD PTR [esi-8]
	xor	eax,		ebx
	mov	ebx,		DWORD PTR [esi-4]
	mov	DWORD PTR [edi-8],eax
	mov	eax,		DWORD PTR 4[esp]
	xor	eax,		ebx
	mov	ebx,		DWORD PTR 8[esp]
	mov	DWORD PTR [edi-4],eax
	mov	eax,		DWORD PTR [ecx*4+ebp]
	cmp	esi,		ebx
	jle	L001start
$L000end:
	; Round 0
	add	ebx,		8
	inc	esi
	cmp	ebx,		esi
	jl	$L002finished
	mov	DWORD PTR 8[esp],ebx
	add	edx,		eax
	and	edx,		255
	inc	ecx
	mov	ebx,		DWORD PTR [edx*4+ebp]
	mov	DWORD PTR [ecx*4+ebp-4],ebx
	add	ebx,		eax
	and	ecx,		255
	and	ebx,		255
	mov	DWORD PTR [edx*4+ebp],eax
	nop
	mov	ebx,		DWORD PTR [ebx*4+ebp]
	mov	eax,		DWORD PTR [ecx*4+ebp]
	mov	bh,		BYTE PTR [esi-1]
	xor	bl,		bh
	mov	BYTE PTR [edi],	bl
	; Round 1
	mov	ebx,		DWORD PTR 8[esp]
	cmp	ebx,		esi
	jle	$L002finished
	inc	esi
	add	edx,		eax
	and	edx,		255
	inc	ecx
	mov	ebx,		DWORD PTR [edx*4+ebp]
	mov	DWORD PTR [ecx*4+ebp-4],ebx
	add	ebx,		eax
	and	ecx,		255
	and	ebx,		255
	mov	DWORD PTR [edx*4+ebp],eax
	nop
	mov	ebx,		DWORD PTR [ebx*4+ebp]
	mov	eax,		DWORD PTR [ecx*4+ebp]
	mov	bh,		BYTE PTR [esi-1]
	xor	bl,		bh
	mov	BYTE PTR 1[edi],bl
	; Round 2
	mov	ebx,		DWORD PTR 8[esp]
	cmp	ebx,		esi
	jle	$L002finished
	inc	esi
	add	edx,		eax
	and	edx,		255
	inc	ecx
	mov	ebx,		DWORD PTR [edx*4+ebp]
	mov	DWORD PTR [ecx*4+ebp-4],ebx
	add	ebx,		eax
	and	ecx,		255
	and	ebx,		255
	mov	DWORD PTR [edx*4+ebp],eax
	nop
	mov	ebx,		DWORD PTR [ebx*4+ebp]
	mov	eax,		DWORD PTR [ecx*4+ebp]
	mov	bh,		BYTE PTR [esi-1]
	xor	bl,		bh
	mov	BYTE PTR 2[edi],bl
	; Round 3
	mov	ebx,		DWORD PTR 8[esp]
	cmp	ebx,		esi
	jle	$L002finished
	inc	esi
	add	edx,		eax
	and	edx,		255
	inc	ecx
	mov	ebx,		DWORD PTR [edx*4+ebp]
	mov	DWORD PTR [ecx*4+ebp-4],ebx
	add	ebx,		eax
	and	ecx,		255
	and	ebx,		255
	mov	DWORD PTR [edx*4+ebp],eax
	nop
	mov	ebx,		DWORD PTR [ebx*4+ebp]
	mov	eax,		DWORD PTR [ecx*4+ebp]
	mov	bh,		BYTE PTR [esi-1]
	xor	bl,		bh
	mov	BYTE PTR 3[edi],bl
	; Round 4
	mov	ebx,		DWORD PTR 8[esp]
	cmp	ebx,		esi
	jle	$L002finished
	inc	esi
	add	edx,		eax
	and	edx,		255
	inc	ecx
	mov	ebx,		DWORD PTR [edx*4+ebp]
	mov	DWORD PTR [ecx*4+ebp-4],ebx
	add	ebx,		eax
	and	ecx,		255
	and	ebx,		255
	mov	DWORD PTR [edx*4+ebp],eax
	nop
	mov	ebx,		DWORD PTR [ebx*4+ebp]
	mov	eax,		DWORD PTR [ecx*4+ebp]
	mov	bh,		BYTE PTR [esi-1]
	xor	bl,		bh
	mov	BYTE PTR 4[edi],bl
	; Round 5
	mov	ebx,		DWORD PTR 8[esp]
	cmp	ebx,		esi
	jle	$L002finished
	inc	esi
	add	edx,		eax
	and	edx,		255
	inc	ecx
	mov	ebx,		DWORD PTR [edx*4+ebp]
	mov	DWORD PTR [ecx*4+ebp-4],ebx
	add	ebx,		eax
	and	ecx,		255
	and	ebx,		255
	mov	DWORD PTR [edx*4+ebp],eax
	nop
	mov	ebx,		DWORD PTR [ebx*4+ebp]
	mov	eax,		DWORD PTR [ecx*4+ebp]
	mov	bh,		BYTE PTR [esi-1]
	xor	bl,		bh
	mov	BYTE PTR 5[edi],bl
	; Round 6
	mov	ebx,		DWORD PTR 8[esp]
	cmp	ebx,		esi
	jle	$L002finished
	inc	esi
	add	edx,		eax
	and	edx,		255
	inc	ecx
	mov	ebx,		DWORD PTR [edx*4+ebp]
	mov	DWORD PTR [ecx*4+ebp-4],ebx
	add	ebx,		eax
	and	ecx,		255
	and	ebx,		255
	mov	DWORD PTR [edx*4+ebp],eax
	nop
	mov	ebx,		DWORD PTR [ebx*4+ebp]
	mov	bh,		BYTE PTR [esi-1]
	xor	bl,		bh
	mov	BYTE PTR 6[edi],bl
$L002finished:
	dec	ecx
	add	esp,		12
	mov	DWORD PTR [ebp-4],edx
	mov	BYTE PTR [ebp-8],cl
	pop	edi
	pop	esi
	pop	ebx
	pop	ebp
	ret
_RC4 ENDP
_TEXT	ENDS
END