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