bf_cbc.S revision 1.1.6.2 1 1.1.6.2 jdolecek /* $NetBSD: bf_cbc.S,v 1.1.6.2 2002/02/07 07:09:48 jdolecek Exp $ */
2 1.1.6.2 jdolecek
3 1.1.6.2 jdolecek /* Copyright (C) 1995-1998 Eric Young (eay (at) cryptsoft.com)
4 1.1.6.2 jdolecek * All rights reserved.
5 1.1.6.2 jdolecek *
6 1.1.6.2 jdolecek * This package is an SSL implementation written
7 1.1.6.2 jdolecek * by Eric Young (eay (at) cryptsoft.com).
8 1.1.6.2 jdolecek * The implementation was written so as to conform with Netscapes SSL.
9 1.1.6.2 jdolecek *
10 1.1.6.2 jdolecek * This library is free for commercial and non-commercial use as long as
11 1.1.6.2 jdolecek * the following conditions are aheared to. The following conditions
12 1.1.6.2 jdolecek * apply to all code found in this distribution, be it the RC4, RSA,
13 1.1.6.2 jdolecek * lhash, DES, etc., code; not just the SSL code. The SSL documentation
14 1.1.6.2 jdolecek * included with this distribution is covered by the same copyright terms
15 1.1.6.2 jdolecek * except that the holder is Tim Hudson (tjh (at) cryptsoft.com).
16 1.1.6.2 jdolecek *
17 1.1.6.2 jdolecek * Copyright remains Eric Young's, and as such any Copyright notices in
18 1.1.6.2 jdolecek * the code are not to be removed.
19 1.1.6.2 jdolecek * If this package is used in a product, Eric Young should be given attribution
20 1.1.6.2 jdolecek * as the author of the parts of the library used.
21 1.1.6.2 jdolecek * This can be in the form of a textual message at program startup or
22 1.1.6.2 jdolecek * in documentation (online or textual) provided with the package.
23 1.1.6.2 jdolecek *
24 1.1.6.2 jdolecek * Redistribution and use in source and binary forms, with or without
25 1.1.6.2 jdolecek * modification, are permitted provided that the following conditions
26 1.1.6.2 jdolecek * are met:
27 1.1.6.2 jdolecek * 1. Redistributions of source code must retain the copyright
28 1.1.6.2 jdolecek * notice, this list of conditions and the following disclaimer.
29 1.1.6.2 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
30 1.1.6.2 jdolecek * notice, this list of conditions and the following disclaimer in the
31 1.1.6.2 jdolecek * documentation and/or other materials provided with the distribution.
32 1.1.6.2 jdolecek * 3. All advertising materials mentioning features or use of this software
33 1.1.6.2 jdolecek * must display the following acknowledgement:
34 1.1.6.2 jdolecek * "This product includes cryptographic software written by
35 1.1.6.2 jdolecek * Eric Young (eay (at) cryptsoft.com)"
36 1.1.6.2 jdolecek * The word 'cryptographic' can be left out if the rouines from the library
37 1.1.6.2 jdolecek * being used are not cryptographic related :-).
38 1.1.6.2 jdolecek * 4. If you include any Windows specific code (or a derivative thereof) from
39 1.1.6.2 jdolecek * the apps directory (application code) you must include an acknowledgement:
40 1.1.6.2 jdolecek * "This product includes software written by Tim Hudson (tjh (at) cryptsoft.com)"
41 1.1.6.2 jdolecek *
42 1.1.6.2 jdolecek * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
43 1.1.6.2 jdolecek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 1.1.6.2 jdolecek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 1.1.6.2 jdolecek * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
46 1.1.6.2 jdolecek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 1.1.6.2 jdolecek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 1.1.6.2 jdolecek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 1.1.6.2 jdolecek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 1.1.6.2 jdolecek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 1.1.6.2 jdolecek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 1.1.6.2 jdolecek * SUCH DAMAGE.
53 1.1.6.2 jdolecek *
54 1.1.6.2 jdolecek * The licence and distribution terms for any publically available version or
55 1.1.6.2 jdolecek * derivative of this code cannot be changed. i.e. this code cannot simply be
56 1.1.6.2 jdolecek * copied and put under another distribution licence
57 1.1.6.2 jdolecek * [including the GNU Public Licence.]
58 1.1.6.2 jdolecek */
59 1.1.6.2 jdolecek
60 1.1.6.2 jdolecek /*
61 1.1.6.2 jdolecek * Modified from the output of `perl bf-686.pl elf' by
62 1.1.6.2 jdolecek * Thor Lancelot Simon <tls (at) netbsd.org>
63 1.1.6.2 jdolecek */
64 1.1.6.2 jdolecek
65 1.1.6.2 jdolecek #include <i386/include/asm.h>
66 1.1.6.2 jdolecek
67 1.1.6.2 jdolecek ENTRY(BF_cbc_encrypt)
68 1.1.6.2 jdolecek
69 1.1.6.2 jdolecek pushl %ebp
70 1.1.6.2 jdolecek pushl %ebx
71 1.1.6.2 jdolecek pushl %esi
72 1.1.6.2 jdolecek pushl %edi
73 1.1.6.2 jdolecek movl 28(%esp), %ebp
74 1.1.6.2 jdolecek # getting iv ptr from parameter 4
75 1.1.6.2 jdolecek movl 36(%esp), %ebx
76 1.1.6.2 jdolecek movl (%ebx), %esi
77 1.1.6.2 jdolecek movl 4(%ebx), %edi
78 1.1.6.2 jdolecek pushl %edi
79 1.1.6.2 jdolecek pushl %esi
80 1.1.6.2 jdolecek pushl %edi
81 1.1.6.2 jdolecek pushl %esi
82 1.1.6.2 jdolecek movl %esp, %ebx
83 1.1.6.2 jdolecek movl 36(%esp), %esi
84 1.1.6.2 jdolecek movl 40(%esp), %edi
85 1.1.6.2 jdolecek # getting encrypt flag from parameter 5
86 1.1.6.2 jdolecek movl 56(%esp), %ecx
87 1.1.6.2 jdolecek # get and push parameter 3
88 1.1.6.2 jdolecek movl 48(%esp), %eax
89 1.1.6.2 jdolecek pushl %eax
90 1.1.6.2 jdolecek pushl %ebx
91 1.1.6.2 jdolecek cmpl $0, %ecx
92 1.1.6.2 jdolecek jz .L000decrypt
93 1.1.6.2 jdolecek andl $4294967288, %ebp
94 1.1.6.2 jdolecek movl 8(%esp), %eax
95 1.1.6.2 jdolecek movl 12(%esp), %ebx
96 1.1.6.2 jdolecek jz .L001encrypt_finish
97 1.1.6.2 jdolecek .L002encrypt_loop:
98 1.1.6.2 jdolecek movl (%esi), %ecx
99 1.1.6.2 jdolecek movl 4(%esi), %edx
100 1.1.6.2 jdolecek xorl %ecx, %eax
101 1.1.6.2 jdolecek xorl %edx, %ebx
102 1.1.6.2 jdolecek .byte 15
103 1.1.6.2 jdolecek .byte 200 # bswapl %eax
104 1.1.6.2 jdolecek .byte 15
105 1.1.6.2 jdolecek .byte 203 # bswapl %ebx
106 1.1.6.2 jdolecek movl %eax, 8(%esp)
107 1.1.6.2 jdolecek movl %ebx, 12(%esp)
108 1.1.6.2 jdolecek call _C_LABEL(BF_encrypt)
109 1.1.6.2 jdolecek movl 8(%esp), %eax
110 1.1.6.2 jdolecek movl 12(%esp), %ebx
111 1.1.6.2 jdolecek .byte 15
112 1.1.6.2 jdolecek .byte 200 # bswapl %eax
113 1.1.6.2 jdolecek .byte 15
114 1.1.6.2 jdolecek .byte 203 # bswapl %ebx
115 1.1.6.2 jdolecek movl %eax, (%edi)
116 1.1.6.2 jdolecek movl %ebx, 4(%edi)
117 1.1.6.2 jdolecek addl $8, %esi
118 1.1.6.2 jdolecek addl $8, %edi
119 1.1.6.2 jdolecek subl $8, %ebp
120 1.1.6.2 jdolecek jnz .L002encrypt_loop
121 1.1.6.2 jdolecek .L001encrypt_finish:
122 1.1.6.2 jdolecek movl 52(%esp), %ebp
123 1.1.6.2 jdolecek andl $7, %ebp
124 1.1.6.2 jdolecek jz .L003finish
125 1.1.6.2 jdolecek xorl %ecx, %ecx
126 1.1.6.2 jdolecek xorl %edx, %edx
127 1.1.6.2 jdolecek movl .L004cbc_enc_jmp_table(,%ebp,4),%ebp
128 1.1.6.2 jdolecek jmp *%ebp
129 1.1.6.2 jdolecek .L005ej7:
130 1.1.6.2 jdolecek movb 6(%esi), %dh
131 1.1.6.2 jdolecek sall $8, %edx
132 1.1.6.2 jdolecek .L006ej6:
133 1.1.6.2 jdolecek movb 5(%esi), %dh
134 1.1.6.2 jdolecek .L007ej5:
135 1.1.6.2 jdolecek movb 4(%esi), %dl
136 1.1.6.2 jdolecek .L008ej4:
137 1.1.6.2 jdolecek movl (%esi), %ecx
138 1.1.6.2 jdolecek jmp .L009ejend
139 1.1.6.2 jdolecek .L010ej3:
140 1.1.6.2 jdolecek movb 2(%esi), %ch
141 1.1.6.2 jdolecek sall $8, %ecx
142 1.1.6.2 jdolecek .L011ej2:
143 1.1.6.2 jdolecek movb 1(%esi), %ch
144 1.1.6.2 jdolecek .L012ej1:
145 1.1.6.2 jdolecek movb (%esi), %cl
146 1.1.6.2 jdolecek .L009ejend:
147 1.1.6.2 jdolecek xorl %ecx, %eax
148 1.1.6.2 jdolecek xorl %edx, %ebx
149 1.1.6.2 jdolecek .byte 15
150 1.1.6.2 jdolecek .byte 200 # bswapl %eax
151 1.1.6.2 jdolecek .byte 15
152 1.1.6.2 jdolecek .byte 203 # bswapl %ebx
153 1.1.6.2 jdolecek movl %eax, 8(%esp)
154 1.1.6.2 jdolecek movl %ebx, 12(%esp)
155 1.1.6.2 jdolecek call _C_LABEL(BF_encrypt)
156 1.1.6.2 jdolecek movl 8(%esp), %eax
157 1.1.6.2 jdolecek movl 12(%esp), %ebx
158 1.1.6.2 jdolecek .byte 15
159 1.1.6.2 jdolecek .byte 200 # bswapl %eax
160 1.1.6.2 jdolecek .byte 15
161 1.1.6.2 jdolecek .byte 203 # bswapl %ebx
162 1.1.6.2 jdolecek movl %eax, (%edi)
163 1.1.6.2 jdolecek movl %ebx, 4(%edi)
164 1.1.6.2 jdolecek jmp .L003finish
165 1.1.6.2 jdolecek .align 16
166 1.1.6.2 jdolecek .L000decrypt:
167 1.1.6.2 jdolecek andl $4294967288, %ebp
168 1.1.6.2 jdolecek movl 16(%esp), %eax
169 1.1.6.2 jdolecek movl 20(%esp), %ebx
170 1.1.6.2 jdolecek jz .L013decrypt_finish
171 1.1.6.2 jdolecek .L014decrypt_loop:
172 1.1.6.2 jdolecek movl (%esi), %eax
173 1.1.6.2 jdolecek movl 4(%esi), %ebx
174 1.1.6.2 jdolecek .byte 15
175 1.1.6.2 jdolecek .byte 200 # bswapl %eax
176 1.1.6.2 jdolecek .byte 15
177 1.1.6.2 jdolecek .byte 203 # bswapl %ebx
178 1.1.6.2 jdolecek movl %eax, 8(%esp)
179 1.1.6.2 jdolecek movl %ebx, 12(%esp)
180 1.1.6.2 jdolecek call _C_LABEL(BF_decrypt)
181 1.1.6.2 jdolecek movl 8(%esp), %eax
182 1.1.6.2 jdolecek movl 12(%esp), %ebx
183 1.1.6.2 jdolecek .byte 15
184 1.1.6.2 jdolecek .byte 200 # bswapl %eax
185 1.1.6.2 jdolecek .byte 15
186 1.1.6.2 jdolecek .byte 203 # bswapl %ebx
187 1.1.6.2 jdolecek movl 16(%esp), %ecx
188 1.1.6.2 jdolecek movl 20(%esp), %edx
189 1.1.6.2 jdolecek xorl %eax, %ecx
190 1.1.6.2 jdolecek xorl %ebx, %edx
191 1.1.6.2 jdolecek movl (%esi), %eax
192 1.1.6.2 jdolecek movl 4(%esi), %ebx
193 1.1.6.2 jdolecek movl %ecx, (%edi)
194 1.1.6.2 jdolecek movl %edx, 4(%edi)
195 1.1.6.2 jdolecek movl %eax, 16(%esp)
196 1.1.6.2 jdolecek movl %ebx, 20(%esp)
197 1.1.6.2 jdolecek addl $8, %esi
198 1.1.6.2 jdolecek addl $8, %edi
199 1.1.6.2 jdolecek subl $8, %ebp
200 1.1.6.2 jdolecek jnz .L014decrypt_loop
201 1.1.6.2 jdolecek .L013decrypt_finish:
202 1.1.6.2 jdolecek movl 52(%esp), %ebp
203 1.1.6.2 jdolecek andl $7, %ebp
204 1.1.6.2 jdolecek jz .L003finish
205 1.1.6.2 jdolecek movl (%esi), %eax
206 1.1.6.2 jdolecek movl 4(%esi), %ebx
207 1.1.6.2 jdolecek .byte 15
208 1.1.6.2 jdolecek .byte 200 # bswapl %eax
209 1.1.6.2 jdolecek .byte 15
210 1.1.6.2 jdolecek .byte 203 # bswapl %ebx
211 1.1.6.2 jdolecek movl %eax, 8(%esp)
212 1.1.6.2 jdolecek movl %ebx, 12(%esp)
213 1.1.6.2 jdolecek call _C_LABEL(BF_decrypt)
214 1.1.6.2 jdolecek movl 8(%esp), %eax
215 1.1.6.2 jdolecek movl 12(%esp), %ebx
216 1.1.6.2 jdolecek .byte 15
217 1.1.6.2 jdolecek .byte 200 # bswapl %eax
218 1.1.6.2 jdolecek .byte 15
219 1.1.6.2 jdolecek .byte 203 # bswapl %ebx
220 1.1.6.2 jdolecek movl 16(%esp), %ecx
221 1.1.6.2 jdolecek movl 20(%esp), %edx
222 1.1.6.2 jdolecek xorl %eax, %ecx
223 1.1.6.2 jdolecek xorl %ebx, %edx
224 1.1.6.2 jdolecek movl (%esi), %eax
225 1.1.6.2 jdolecek movl 4(%esi), %ebx
226 1.1.6.2 jdolecek .L015dj7:
227 1.1.6.2 jdolecek rorl $16, %edx
228 1.1.6.2 jdolecek movb %dl, 6(%edi)
229 1.1.6.2 jdolecek shrl $16, %edx
230 1.1.6.2 jdolecek .L016dj6:
231 1.1.6.2 jdolecek movb %dh, 5(%edi)
232 1.1.6.2 jdolecek .L017dj5:
233 1.1.6.2 jdolecek movb %dl, 4(%edi)
234 1.1.6.2 jdolecek .L018dj4:
235 1.1.6.2 jdolecek movl %ecx, (%edi)
236 1.1.6.2 jdolecek jmp .L019djend
237 1.1.6.2 jdolecek .L020dj3:
238 1.1.6.2 jdolecek rorl $16, %ecx
239 1.1.6.2 jdolecek movb %cl, 2(%edi)
240 1.1.6.2 jdolecek sall $16, %ecx
241 1.1.6.2 jdolecek .L021dj2:
242 1.1.6.2 jdolecek movb %ch, 1(%esi)
243 1.1.6.2 jdolecek .L022dj1:
244 1.1.6.2 jdolecek movb %cl, (%esi)
245 1.1.6.2 jdolecek .L019djend:
246 1.1.6.2 jdolecek jmp .L003finish
247 1.1.6.2 jdolecek .align 16
248 1.1.6.2 jdolecek .L003finish:
249 1.1.6.2 jdolecek movl 60(%esp), %ecx
250 1.1.6.2 jdolecek addl $24, %esp
251 1.1.6.2 jdolecek movl %eax, (%ecx)
252 1.1.6.2 jdolecek movl %ebx, 4(%ecx)
253 1.1.6.2 jdolecek popl %edi
254 1.1.6.2 jdolecek popl %esi
255 1.1.6.2 jdolecek popl %ebx
256 1.1.6.2 jdolecek popl %ebp
257 1.1.6.2 jdolecek ret
258 1.1.6.2 jdolecek .align 16
259 1.1.6.2 jdolecek .L004cbc_enc_jmp_table:
260 1.1.6.2 jdolecek .long 0
261 1.1.6.2 jdolecek .long .L012ej1
262 1.1.6.2 jdolecek .long .L011ej2
263 1.1.6.2 jdolecek .long .L010ej3
264 1.1.6.2 jdolecek .long .L008ej4
265 1.1.6.2 jdolecek .long .L007ej5
266 1.1.6.2 jdolecek .long .L006ej6
267 1.1.6.2 jdolecek .long .L005ej7
268 1.1.6.2 jdolecek .align 16
269 1.1.6.2 jdolecek .L023cbc_dec_jmp_table:
270 1.1.6.2 jdolecek .long 0
271 1.1.6.2 jdolecek .long .L022dj1
272 1.1.6.2 jdolecek .long .L021dj2
273 1.1.6.2 jdolecek .long .L020dj3
274 1.1.6.2 jdolecek .long .L018dj4
275 1.1.6.2 jdolecek .long .L017dj5
276 1.1.6.2 jdolecek .long .L016dj6
277 1.1.6.2 jdolecek .long .L015dj7
278 1.1.6.2 jdolecek .L_BF_cbc_encrypt_end:
279 1.1.6.2 jdolecek .size _C_LABEL(BF_cbc_encrypt),.L_BF_cbc_encrypt_end-_C_LABEL(BF_cbc_encrypt)
280