Import of old SSLeay release: SSLeay 0.9.0b
[openssl.git] / crypto / rc5 / asm / r5-win32.asm
1         ; Don't even think of reading this code
2         ; It was automatically generated by rc5-586.pl
3         ; Which is a perl program used to generate the x86 assember for
4         ; any of elf, a.out, BSDI,Win32, or Solaris
5         ; eric <eay@cryptsoft.com>
6         ; 
7         TITLE   rc5-586.asm
8         .386
9 .model FLAT
10 _TEXT   SEGMENT
11 PUBLIC  _RC5_32_encrypt
12
13 _RC5_32_encrypt PROC NEAR
14         ; 
15         push    ebp
16         push    esi
17         push    edi
18         mov     edx,            DWORD PTR 16[esp]
19         mov     ebp,            DWORD PTR 20[esp]
20         ; Load the 2 words
21         mov     edi,            DWORD PTR [edx]
22         mov     esi,            DWORD PTR 4[edx]
23         push    ebx
24         mov     ebx,            DWORD PTR [ebp]
25         add     edi,            DWORD PTR 4[ebp]
26         add     esi,            DWORD PTR 8[ebp]
27         xor     edi,            esi
28         mov     eax,            DWORD PTR 12[ebp]
29         mov     ecx,            esi
30         rol     edi,            cl
31         add     edi,            eax
32         xor     esi,            edi
33         mov     eax,            DWORD PTR 16[ebp]
34         mov     ecx,            edi
35         rol     esi,            cl
36         add     esi,            eax
37         xor     edi,            esi
38         mov     eax,            DWORD PTR 20[ebp]
39         mov     ecx,            esi
40         rol     edi,            cl
41         add     edi,            eax
42         xor     esi,            edi
43         mov     eax,            DWORD PTR 24[ebp]
44         mov     ecx,            edi
45         rol     esi,            cl
46         add     esi,            eax
47         xor     edi,            esi
48         mov     eax,            DWORD PTR 28[ebp]
49         mov     ecx,            esi
50         rol     edi,            cl
51         add     edi,            eax
52         xor     esi,            edi
53         mov     eax,            DWORD PTR 32[ebp]
54         mov     ecx,            edi
55         rol     esi,            cl
56         add     esi,            eax
57         xor     edi,            esi
58         mov     eax,            DWORD PTR 36[ebp]
59         mov     ecx,            esi
60         rol     edi,            cl
61         add     edi,            eax
62         xor     esi,            edi
63         mov     eax,            DWORD PTR 40[ebp]
64         mov     ecx,            edi
65         rol     esi,            cl
66         add     esi,            eax
67         xor     edi,            esi
68         mov     eax,            DWORD PTR 44[ebp]
69         mov     ecx,            esi
70         rol     edi,            cl
71         add     edi,            eax
72         xor     esi,            edi
73         mov     eax,            DWORD PTR 48[ebp]
74         mov     ecx,            edi
75         rol     esi,            cl
76         add     esi,            eax
77         xor     edi,            esi
78         mov     eax,            DWORD PTR 52[ebp]
79         mov     ecx,            esi
80         rol     edi,            cl
81         add     edi,            eax
82         xor     esi,            edi
83         mov     eax,            DWORD PTR 56[ebp]
84         mov     ecx,            edi
85         rol     esi,            cl
86         add     esi,            eax
87         xor     edi,            esi
88         mov     eax,            DWORD PTR 60[ebp]
89         mov     ecx,            esi
90         rol     edi,            cl
91         add     edi,            eax
92         xor     esi,            edi
93         mov     eax,            DWORD PTR 64[ebp]
94         mov     ecx,            edi
95         rol     esi,            cl
96         add     esi,            eax
97         xor     edi,            esi
98         mov     eax,            DWORD PTR 68[ebp]
99         mov     ecx,            esi
100         rol     edi,            cl
101         add     edi,            eax
102         xor     esi,            edi
103         mov     eax,            DWORD PTR 72[ebp]
104         mov     ecx,            edi
105         rol     esi,            cl
106         add     esi,            eax
107         cmp     ebx,            8
108         je      $L000rc5_exit
109         xor     edi,            esi
110         mov     eax,            DWORD PTR 76[ebp]
111         mov     ecx,            esi
112         rol     edi,            cl
113         add     edi,            eax
114         xor     esi,            edi
115         mov     eax,            DWORD PTR 80[ebp]
116         mov     ecx,            edi
117         rol     esi,            cl
118         add     esi,            eax
119         xor     edi,            esi
120         mov     eax,            DWORD PTR 84[ebp]
121         mov     ecx,            esi
122         rol     edi,            cl
123         add     edi,            eax
124         xor     esi,            edi
125         mov     eax,            DWORD PTR 88[ebp]
126         mov     ecx,            edi
127         rol     esi,            cl
128         add     esi,            eax
129         xor     edi,            esi
130         mov     eax,            DWORD PTR 92[ebp]
131         mov     ecx,            esi
132         rol     edi,            cl
133         add     edi,            eax
134         xor     esi,            edi
135         mov     eax,            DWORD PTR 96[ebp]
136         mov     ecx,            edi
137         rol     esi,            cl
138         add     esi,            eax
139         xor     edi,            esi
140         mov     eax,            DWORD PTR 100[ebp]
141         mov     ecx,            esi
142         rol     edi,            cl
143         add     edi,            eax
144         xor     esi,            edi
145         mov     eax,            DWORD PTR 104[ebp]
146         mov     ecx,            edi
147         rol     esi,            cl
148         add     esi,            eax
149         cmp     ebx,            12
150         je      $L000rc5_exit
151         xor     edi,            esi
152         mov     eax,            DWORD PTR 108[ebp]
153         mov     ecx,            esi
154         rol     edi,            cl
155         add     edi,            eax
156         xor     esi,            edi
157         mov     eax,            DWORD PTR 112[ebp]
158         mov     ecx,            edi
159         rol     esi,            cl
160         add     esi,            eax
161         xor     edi,            esi
162         mov     eax,            DWORD PTR 116[ebp]
163         mov     ecx,            esi
164         rol     edi,            cl
165         add     edi,            eax
166         xor     esi,            edi
167         mov     eax,            DWORD PTR 120[ebp]
168         mov     ecx,            edi
169         rol     esi,            cl
170         add     esi,            eax
171         xor     edi,            esi
172         mov     eax,            DWORD PTR 124[ebp]
173         mov     ecx,            esi
174         rol     edi,            cl
175         add     edi,            eax
176         xor     esi,            edi
177         mov     eax,            DWORD PTR 128[ebp]
178         mov     ecx,            edi
179         rol     esi,            cl
180         add     esi,            eax
181         xor     edi,            esi
182         mov     eax,            DWORD PTR 132[ebp]
183         mov     ecx,            esi
184         rol     edi,            cl
185         add     edi,            eax
186         xor     esi,            edi
187         mov     eax,            DWORD PTR 136[ebp]
188         mov     ecx,            edi
189         rol     esi,            cl
190         add     esi,            eax
191 $L000rc5_exit:
192         mov     DWORD PTR [edx],edi
193         mov     DWORD PTR 4[edx],esi
194         pop     ebx
195         pop     edi
196         pop     esi
197         pop     ebp
198         ret
199 _RC5_32_encrypt ENDP
200 _TEXT   ENDS
201 _TEXT   SEGMENT
202 PUBLIC  _RC5_32_decrypt
203
204 _RC5_32_decrypt PROC NEAR
205         ; 
206         push    ebp
207         push    esi
208         push    edi
209         mov     edx,            DWORD PTR 16[esp]
210         mov     ebp,            DWORD PTR 20[esp]
211         ; Load the 2 words
212         mov     edi,            DWORD PTR [edx]
213         mov     esi,            DWORD PTR 4[edx]
214         push    ebx
215         mov     ebx,            DWORD PTR [ebp]
216         cmp     ebx,            12
217         je      $L001rc5_dec_12
218         cmp     ebx,            8
219         je      $L002rc5_dec_8
220         mov     eax,            DWORD PTR 136[ebp]
221         sub     esi,            eax
222         mov     ecx,            edi
223         ror     esi,            cl
224         xor     esi,            edi
225         mov     eax,            DWORD PTR 132[ebp]
226         sub     edi,            eax
227         mov     ecx,            esi
228         ror     edi,            cl
229         xor     edi,            esi
230         mov     eax,            DWORD PTR 128[ebp]
231         sub     esi,            eax
232         mov     ecx,            edi
233         ror     esi,            cl
234         xor     esi,            edi
235         mov     eax,            DWORD PTR 124[ebp]
236         sub     edi,            eax
237         mov     ecx,            esi
238         ror     edi,            cl
239         xor     edi,            esi
240         mov     eax,            DWORD PTR 120[ebp]
241         sub     esi,            eax
242         mov     ecx,            edi
243         ror     esi,            cl
244         xor     esi,            edi
245         mov     eax,            DWORD PTR 116[ebp]
246         sub     edi,            eax
247         mov     ecx,            esi
248         ror     edi,            cl
249         xor     edi,            esi
250         mov     eax,            DWORD PTR 112[ebp]
251         sub     esi,            eax
252         mov     ecx,            edi
253         ror     esi,            cl
254         xor     esi,            edi
255         mov     eax,            DWORD PTR 108[ebp]
256         sub     edi,            eax
257         mov     ecx,            esi
258         ror     edi,            cl
259         xor     edi,            esi
260 $L001rc5_dec_12:
261         mov     eax,            DWORD PTR 104[ebp]
262         sub     esi,            eax
263         mov     ecx,            edi
264         ror     esi,            cl
265         xor     esi,            edi
266         mov     eax,            DWORD PTR 100[ebp]
267         sub     edi,            eax
268         mov     ecx,            esi
269         ror     edi,            cl
270         xor     edi,            esi
271         mov     eax,            DWORD PTR 96[ebp]
272         sub     esi,            eax
273         mov     ecx,            edi
274         ror     esi,            cl
275         xor     esi,            edi
276         mov     eax,            DWORD PTR 92[ebp]
277         sub     edi,            eax
278         mov     ecx,            esi
279         ror     edi,            cl
280         xor     edi,            esi
281         mov     eax,            DWORD PTR 88[ebp]
282         sub     esi,            eax
283         mov     ecx,            edi
284         ror     esi,            cl
285         xor     esi,            edi
286         mov     eax,            DWORD PTR 84[ebp]
287         sub     edi,            eax
288         mov     ecx,            esi
289         ror     edi,            cl
290         xor     edi,            esi
291         mov     eax,            DWORD PTR 80[ebp]
292         sub     esi,            eax
293         mov     ecx,            edi
294         ror     esi,            cl
295         xor     esi,            edi
296         mov     eax,            DWORD PTR 76[ebp]
297         sub     edi,            eax
298         mov     ecx,            esi
299         ror     edi,            cl
300         xor     edi,            esi
301 $L002rc5_dec_8:
302         mov     eax,            DWORD PTR 72[ebp]
303         sub     esi,            eax
304         mov     ecx,            edi
305         ror     esi,            cl
306         xor     esi,            edi
307         mov     eax,            DWORD PTR 68[ebp]
308         sub     edi,            eax
309         mov     ecx,            esi
310         ror     edi,            cl
311         xor     edi,            esi
312         mov     eax,            DWORD PTR 64[ebp]
313         sub     esi,            eax
314         mov     ecx,            edi
315         ror     esi,            cl
316         xor     esi,            edi
317         mov     eax,            DWORD PTR 60[ebp]
318         sub     edi,            eax
319         mov     ecx,            esi
320         ror     edi,            cl
321         xor     edi,            esi
322         mov     eax,            DWORD PTR 56[ebp]
323         sub     esi,            eax
324         mov     ecx,            edi
325         ror     esi,            cl
326         xor     esi,            edi
327         mov     eax,            DWORD PTR 52[ebp]
328         sub     edi,            eax
329         mov     ecx,            esi
330         ror     edi,            cl
331         xor     edi,            esi
332         mov     eax,            DWORD PTR 48[ebp]
333         sub     esi,            eax
334         mov     ecx,            edi
335         ror     esi,            cl
336         xor     esi,            edi
337         mov     eax,            DWORD PTR 44[ebp]
338         sub     edi,            eax
339         mov     ecx,            esi
340         ror     edi,            cl
341         xor     edi,            esi
342         mov     eax,            DWORD PTR 40[ebp]
343         sub     esi,            eax
344         mov     ecx,            edi
345         ror     esi,            cl
346         xor     esi,            edi
347         mov     eax,            DWORD PTR 36[ebp]
348         sub     edi,            eax
349         mov     ecx,            esi
350         ror     edi,            cl
351         xor     edi,            esi
352         mov     eax,            DWORD PTR 32[ebp]
353         sub     esi,            eax
354         mov     ecx,            edi
355         ror     esi,            cl
356         xor     esi,            edi
357         mov     eax,            DWORD PTR 28[ebp]
358         sub     edi,            eax
359         mov     ecx,            esi
360         ror     edi,            cl
361         xor     edi,            esi
362         mov     eax,            DWORD PTR 24[ebp]
363         sub     esi,            eax
364         mov     ecx,            edi
365         ror     esi,            cl
366         xor     esi,            edi
367         mov     eax,            DWORD PTR 20[ebp]
368         sub     edi,            eax
369         mov     ecx,            esi
370         ror     edi,            cl
371         xor     edi,            esi
372         mov     eax,            DWORD PTR 16[ebp]
373         sub     esi,            eax
374         mov     ecx,            edi
375         ror     esi,            cl
376         xor     esi,            edi
377         mov     eax,            DWORD PTR 12[ebp]
378         sub     edi,            eax
379         mov     ecx,            esi
380         ror     edi,            cl
381         xor     edi,            esi
382         sub     esi,            DWORD PTR 8[ebp]
383         sub     edi,            DWORD PTR 4[ebp]
384 L003rc5_exit:
385         mov     DWORD PTR [edx],edi
386         mov     DWORD PTR 4[edx],esi
387         pop     ebx
388         pop     edi
389         pop     esi
390         pop     ebp
391         ret
392 _RC5_32_decrypt ENDP
393 _TEXT   ENDS
394 _TEXT   SEGMENT
395 PUBLIC  _RC5_32_cbc_encrypt
396
397 _RC5_32_cbc_encrypt PROC NEAR
398         ; 
399         push    ebp
400         push    ebx
401         push    esi
402         push    edi
403         mov     ebp,            DWORD PTR 28[esp]
404         ; getting iv ptr from parameter 4
405         mov     ebx,            DWORD PTR 36[esp]
406         mov     esi,            DWORD PTR [ebx]
407         mov     edi,            DWORD PTR 4[ebx]
408         push    edi
409         push    esi
410         push    edi
411         push    esi
412         mov     ebx,            esp
413         mov     esi,            DWORD PTR 36[esp]
414         mov     edi,            DWORD PTR 40[esp]
415         ; getting encrypt flag from parameter 5
416         mov     ecx,            DWORD PTR 56[esp]
417         ; get and push parameter 3
418         mov     eax,            DWORD PTR 48[esp]
419         push    eax
420         push    ebx
421         cmp     ecx,            0
422         jz      $L004decrypt
423         and     ebp,            4294967288
424         mov     eax,            DWORD PTR 8[esp]
425         mov     ebx,            DWORD PTR 12[esp]
426         jz      $L005encrypt_finish
427 L006encrypt_loop:
428         mov     ecx,            DWORD PTR [esi]
429         mov     edx,            DWORD PTR 4[esi]
430         xor     eax,            ecx
431         xor     ebx,            edx
432         mov     DWORD PTR 8[esp],eax
433         mov     DWORD PTR 12[esp],ebx
434         call    _RC5_32_encrypt
435         mov     eax,            DWORD PTR 8[esp]
436         mov     ebx,            DWORD PTR 12[esp]
437         mov     DWORD PTR [edi],eax
438         mov     DWORD PTR 4[edi],ebx
439         add     esi,            8
440         add     edi,            8
441         sub     ebp,            8
442         jnz     L006encrypt_loop
443 $L005encrypt_finish:
444         mov     ebp,            DWORD PTR 52[esp]
445         and     ebp,            7
446         jz      $L007finish
447         xor     ecx,            ecx
448         xor     edx,            edx
449         mov     ebp,            DWORD PTR $L008cbc_enc_jmp_table[ebp*4]
450         jmp      ebp
451 L009ej7:
452         mov     dh,             BYTE PTR 6[esi]
453         shl     edx,            8
454 L010ej6:
455         mov     dh,             BYTE PTR 5[esi]
456 L011ej5:
457         mov     dl,             BYTE PTR 4[esi]
458 L012ej4:
459         mov     ecx,            DWORD PTR [esi]
460         jmp     $L013ejend
461 L014ej3:
462         mov     ch,             BYTE PTR 2[esi]
463         shl     ecx,            8
464 L015ej2:
465         mov     ch,             BYTE PTR 1[esi]
466 L016ej1:
467         mov     cl,             BYTE PTR [esi]
468 $L013ejend:
469         xor     eax,            ecx
470         xor     ebx,            edx
471         mov     DWORD PTR 8[esp],eax
472         mov     DWORD PTR 12[esp],ebx
473         call    _RC5_32_encrypt
474         mov     eax,            DWORD PTR 8[esp]
475         mov     ebx,            DWORD PTR 12[esp]
476         mov     DWORD PTR [edi],eax
477         mov     DWORD PTR 4[edi],ebx
478         jmp     $L007finish
479 $L004decrypt:
480         and     ebp,            4294967288
481         mov     eax,            DWORD PTR 16[esp]
482         mov     ebx,            DWORD PTR 20[esp]
483         jz      $L017decrypt_finish
484 L018decrypt_loop:
485         mov     eax,            DWORD PTR [esi]
486         mov     ebx,            DWORD PTR 4[esi]
487         mov     DWORD PTR 8[esp],eax
488         mov     DWORD PTR 12[esp],ebx
489         call    _RC5_32_decrypt
490         mov     eax,            DWORD PTR 8[esp]
491         mov     ebx,            DWORD PTR 12[esp]
492         mov     ecx,            DWORD PTR 16[esp]
493         mov     edx,            DWORD PTR 20[esp]
494         xor     ecx,            eax
495         xor     edx,            ebx
496         mov     eax,            DWORD PTR [esi]
497         mov     ebx,            DWORD PTR 4[esi]
498         mov     DWORD PTR [edi],ecx
499         mov     DWORD PTR 4[edi],edx
500         mov     DWORD PTR 16[esp],eax
501         mov     DWORD PTR 20[esp],ebx
502         add     esi,            8
503         add     edi,            8
504         sub     ebp,            8
505         jnz     L018decrypt_loop
506 $L017decrypt_finish:
507         mov     ebp,            DWORD PTR 52[esp]
508         and     ebp,            7
509         jz      $L007finish
510         mov     eax,            DWORD PTR [esi]
511         mov     ebx,            DWORD PTR 4[esi]
512         mov     DWORD PTR 8[esp],eax
513         mov     DWORD PTR 12[esp],ebx
514         call    _RC5_32_decrypt
515         mov     eax,            DWORD PTR 8[esp]
516         mov     ebx,            DWORD PTR 12[esp]
517         mov     ecx,            DWORD PTR 16[esp]
518         mov     edx,            DWORD PTR 20[esp]
519         xor     ecx,            eax
520         xor     edx,            ebx
521         mov     eax,            DWORD PTR [esi]
522         mov     ebx,            DWORD PTR 4[esi]
523 L019dj7:
524         ror     edx,            16
525         mov     BYTE PTR 6[edi],dl
526         shr     edx,            16
527 L020dj6:
528         mov     BYTE PTR 5[edi],dh
529 L021dj5:
530         mov     BYTE PTR 4[edi],dl
531 L022dj4:
532         mov     DWORD PTR [edi],ecx
533         jmp     $L023djend
534 L024dj3:
535         ror     ecx,            16
536         mov     BYTE PTR 2[edi],cl
537         shl     ecx,            16
538 L025dj2:
539         mov     BYTE PTR 1[esi],ch
540 L026dj1:
541         mov     BYTE PTR [esi], cl
542 $L023djend:
543         jmp     $L007finish
544 $L007finish:
545         mov     ecx,            DWORD PTR 60[esp]
546         add     esp,            24
547         mov     DWORD PTR [ecx],eax
548         mov     DWORD PTR 4[ecx],ebx
549         pop     edi
550         pop     esi
551         pop     ebx
552         pop     ebp
553         ret
554 $L008cbc_enc_jmp_table:
555         DD      0
556         DD      L016ej1
557         DD      L015ej2
558         DD      L014ej3
559         DD      L012ej4
560         DD      L011ej5
561         DD      L010ej6
562         DD      L009ej7
563 L027cbc_dec_jmp_table:
564         DD      0
565         DD      L026dj1
566         DD      L025dj2
567         DD      L024dj3
568         DD      L022dj4
569         DD      L021dj5
570         DD      L020dj6
571         DD      L019dj7
572 _RC5_32_cbc_encrypt ENDP
573 _TEXT   ENDS
574 END