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