des_cbc.S revision 1.2 1 1.2 itohy /* $NetBSD: des_cbc.S,v 1.2 2002/11/12 03:03:11 itohy Exp $ */
2 1.1 tls
3 1.1 tls /* Copyright (C) 1995-1997 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.1 tls * Modified from the output of `perl des686.pl elf' by
62 1.1 tls * 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.1 tls
67 1.1 tls ENTRY(des_ncbc_encrypt)
68 1.1 tls
69 1.1 tls pushl %ebp
70 1.1 tls pushl %ebx
71 1.1 tls pushl %esi
72 1.1 tls pushl %edi
73 1.1 tls movl 28(%esp), %ebp
74 1.1 tls # getting iv ptr from parameter 4
75 1.1 tls movl 36(%esp), %ebx
76 1.1 tls movl (%ebx), %esi
77 1.1 tls movl 4(%ebx), %edi
78 1.1 tls pushl %edi
79 1.1 tls pushl %esi
80 1.1 tls pushl %edi
81 1.1 tls pushl %esi
82 1.1 tls movl %esp, %ebx
83 1.1 tls movl 36(%esp), %esi
84 1.1 tls movl 40(%esp), %edi
85 1.1 tls # getting encrypt flag from parameter 5
86 1.1 tls movl 56(%esp), %ecx
87 1.1 tls # get and push parameter 5
88 1.1 tls pushl %ecx
89 1.1 tls # get and push parameter 3
90 1.1 tls movl 52(%esp), %eax
91 1.1 tls pushl %eax
92 1.1 tls pushl %ebx
93 1.1 tls cmpl $0, %ecx
94 1.1 tls jz .L004decrypt
95 1.1 tls andl $4294967288, %ebp
96 1.1 tls movl 12(%esp), %eax
97 1.1 tls movl 16(%esp), %ebx
98 1.1 tls jz .L005encrypt_finish
99 1.1 tls .L006encrypt_loop:
100 1.1 tls movl (%esi), %ecx
101 1.1 tls movl 4(%esi), %edx
102 1.1 tls xorl %ecx, %eax
103 1.1 tls xorl %edx, %ebx
104 1.1 tls movl %eax, 12(%esp)
105 1.1 tls movl %ebx, 16(%esp)
106 1.1 tls call _C_LABEL(des_encrypt1)
107 1.1 tls movl 12(%esp), %eax
108 1.1 tls movl 16(%esp), %ebx
109 1.1 tls movl %eax, (%edi)
110 1.1 tls movl %ebx, 4(%edi)
111 1.1 tls addl $8, %esi
112 1.1 tls addl $8, %edi
113 1.1 tls subl $8, %ebp
114 1.1 tls jnz .L006encrypt_loop
115 1.1 tls .L005encrypt_finish:
116 1.1 tls movl 56(%esp), %ebp
117 1.1 tls andl $7, %ebp
118 1.1 tls jz .L007finish
119 1.1 tls xorl %ecx, %ecx
120 1.1 tls xorl %edx, %edx
121 1.1 tls movl .L008cbc_enc_jmp_table(,%ebp,4),%ebp
122 1.1 tls jmp *%ebp
123 1.1 tls .L009ej7:
124 1.1 tls movb 6(%esi), %dh
125 1.1 tls sall $8, %edx
126 1.1 tls .L010ej6:
127 1.1 tls movb 5(%esi), %dh
128 1.1 tls .L011ej5:
129 1.1 tls movb 4(%esi), %dl
130 1.1 tls .L012ej4:
131 1.1 tls movl (%esi), %ecx
132 1.1 tls jmp .L013ejend
133 1.1 tls .L014ej3:
134 1.1 tls movb 2(%esi), %ch
135 1.1 tls sall $8, %ecx
136 1.1 tls .L015ej2:
137 1.1 tls movb 1(%esi), %ch
138 1.1 tls .L016ej1:
139 1.1 tls movb (%esi), %cl
140 1.1 tls .L013ejend:
141 1.1 tls xorl %ecx, %eax
142 1.1 tls xorl %edx, %ebx
143 1.1 tls movl %eax, 12(%esp)
144 1.1 tls movl %ebx, 16(%esp)
145 1.1 tls call _C_LABEL(des_encrypt1)
146 1.1 tls movl 12(%esp), %eax
147 1.1 tls movl 16(%esp), %ebx
148 1.1 tls movl %eax, (%edi)
149 1.1 tls movl %ebx, 4(%edi)
150 1.1 tls jmp .L007finish
151 1.2 itohy #ifdef __ELF__
152 1.1 tls .align 16
153 1.2 itohy #else
154 1.2 itohy .align 4
155 1.2 itohy #endif
156 1.1 tls .L004decrypt:
157 1.1 tls andl $4294967288, %ebp
158 1.1 tls movl 20(%esp), %eax
159 1.1 tls movl 24(%esp), %ebx
160 1.1 tls jz .L017decrypt_finish
161 1.1 tls .L018decrypt_loop:
162 1.1 tls movl (%esi), %eax
163 1.1 tls movl 4(%esi), %ebx
164 1.1 tls movl %eax, 12(%esp)
165 1.1 tls movl %ebx, 16(%esp)
166 1.1 tls call _C_LABEL(des_encrypt1)
167 1.1 tls movl 12(%esp), %eax
168 1.1 tls movl 16(%esp), %ebx
169 1.1 tls movl 20(%esp), %ecx
170 1.1 tls movl 24(%esp), %edx
171 1.1 tls xorl %eax, %ecx
172 1.1 tls xorl %ebx, %edx
173 1.1 tls movl (%esi), %eax
174 1.1 tls movl 4(%esi), %ebx
175 1.1 tls movl %ecx, (%edi)
176 1.1 tls movl %edx, 4(%edi)
177 1.1 tls movl %eax, 20(%esp)
178 1.1 tls movl %ebx, 24(%esp)
179 1.1 tls addl $8, %esi
180 1.1 tls addl $8, %edi
181 1.1 tls subl $8, %ebp
182 1.1 tls jnz .L018decrypt_loop
183 1.1 tls .L017decrypt_finish:
184 1.1 tls movl 56(%esp), %ebp
185 1.1 tls andl $7, %ebp
186 1.1 tls jz .L007finish
187 1.1 tls movl (%esi), %eax
188 1.1 tls movl 4(%esi), %ebx
189 1.1 tls movl %eax, 12(%esp)
190 1.1 tls movl %ebx, 16(%esp)
191 1.1 tls call _C_LABEL(des_encrypt1)
192 1.1 tls movl 12(%esp), %eax
193 1.1 tls movl 16(%esp), %ebx
194 1.1 tls movl 20(%esp), %ecx
195 1.1 tls movl 24(%esp), %edx
196 1.1 tls xorl %eax, %ecx
197 1.1 tls xorl %ebx, %edx
198 1.1 tls movl (%esi), %eax
199 1.1 tls movl 4(%esi), %ebx
200 1.1 tls .L019dj7:
201 1.1 tls rorl $16, %edx
202 1.1 tls movb %dl, 6(%edi)
203 1.1 tls shrl $16, %edx
204 1.1 tls .L020dj6:
205 1.1 tls movb %dh, 5(%edi)
206 1.1 tls .L021dj5:
207 1.1 tls movb %dl, 4(%edi)
208 1.1 tls .L022dj4:
209 1.1 tls movl %ecx, (%edi)
210 1.1 tls jmp .L023djend
211 1.1 tls .L024dj3:
212 1.1 tls rorl $16, %ecx
213 1.1 tls movb %cl, 2(%edi)
214 1.1 tls sall $16, %ecx
215 1.1 tls .L025dj2:
216 1.1 tls movb %ch, 1(%esi)
217 1.1 tls .L026dj1:
218 1.1 tls movb %cl, (%esi)
219 1.1 tls .L023djend:
220 1.1 tls jmp .L007finish
221 1.2 itohy #ifdef __ELF__
222 1.1 tls .align 16
223 1.2 itohy #else
224 1.2 itohy .align 4
225 1.2 itohy #endif
226 1.1 tls .L007finish:
227 1.1 tls movl 64(%esp), %ecx
228 1.1 tls addl $28, %esp
229 1.1 tls movl %eax, (%ecx)
230 1.1 tls movl %ebx, 4(%ecx)
231 1.1 tls popl %edi
232 1.1 tls popl %esi
233 1.1 tls popl %ebx
234 1.1 tls popl %ebp
235 1.1 tls ret
236 1.2 itohy #ifdef __ELF__
237 1.1 tls .align 16
238 1.2 itohy #else
239 1.2 itohy .align 4
240 1.2 itohy #endif
241 1.1 tls .L008cbc_enc_jmp_table:
242 1.1 tls .long 0
243 1.1 tls .long .L016ej1
244 1.1 tls .long .L015ej2
245 1.1 tls .long .L014ej3
246 1.1 tls .long .L012ej4
247 1.1 tls .long .L011ej5
248 1.1 tls .long .L010ej6
249 1.1 tls .long .L009ej7
250 1.2 itohy #ifdef __ELF__
251 1.1 tls .align 16
252 1.2 itohy #else
253 1.2 itohy .align 4
254 1.2 itohy #endif
255 1.1 tls .L027cbc_dec_jmp_table:
256 1.1 tls .long 0
257 1.1 tls .long .L026dj1
258 1.1 tls .long .L025dj2
259 1.1 tls .long .L024dj3
260 1.1 tls .long .L022dj4
261 1.1 tls .long .L021dj5
262 1.1 tls .long .L020dj6
263 1.1 tls .long .L019dj7
264 1.1 tls .L_des_ncbc_encrypt_end:
265 1.1 tls .size _C_LABEL(des_ncbc_encrypt),.L_des_ncbc_encrypt_end-_C_LABEL(des_ncbc_encrypt)
266 1.1 tls
267 1.1 tls ENTRY(des_ede3_cbc_encrypt)
268 1.1 tls
269 1.1 tls pushl %ebp
270 1.1 tls pushl %ebx
271 1.1 tls pushl %esi
272 1.1 tls pushl %edi
273 1.1 tls movl 28(%esp), %ebp
274 1.1 tls # getting iv ptr from parameter 6
275 1.1 tls movl 44(%esp), %ebx
276 1.1 tls movl (%ebx), %esi
277 1.1 tls movl 4(%ebx), %edi
278 1.1 tls pushl %edi
279 1.1 tls pushl %esi
280 1.1 tls pushl %edi
281 1.1 tls pushl %esi
282 1.1 tls movl %esp, %ebx
283 1.1 tls movl 36(%esp), %esi
284 1.1 tls movl 40(%esp), %edi
285 1.1 tls # getting encrypt flag from parameter 7
286 1.1 tls movl 64(%esp), %ecx
287 1.1 tls # get and push parameter 5
288 1.1 tls movl 56(%esp), %eax
289 1.1 tls pushl %eax
290 1.1 tls # get and push parameter 4
291 1.1 tls movl 56(%esp), %eax
292 1.1 tls pushl %eax
293 1.1 tls # get and push parameter 3
294 1.1 tls movl 56(%esp), %eax
295 1.1 tls pushl %eax
296 1.1 tls pushl %ebx
297 1.1 tls cmpl $0, %ecx
298 1.1 tls jz .L028decrypt
299 1.1 tls andl $4294967288, %ebp
300 1.1 tls movl 16(%esp), %eax
301 1.1 tls movl 20(%esp), %ebx
302 1.1 tls jz .L029encrypt_finish
303 1.1 tls .L030encrypt_loop:
304 1.1 tls movl (%esi), %ecx
305 1.1 tls movl 4(%esi), %edx
306 1.1 tls xorl %ecx, %eax
307 1.1 tls xorl %edx, %ebx
308 1.1 tls movl %eax, 16(%esp)
309 1.1 tls movl %ebx, 20(%esp)
310 1.1 tls call _C_LABEL(des_encrypt3)
311 1.1 tls movl 16(%esp), %eax
312 1.1 tls movl 20(%esp), %ebx
313 1.1 tls movl %eax, (%edi)
314 1.1 tls movl %ebx, 4(%edi)
315 1.1 tls addl $8, %esi
316 1.1 tls addl $8, %edi
317 1.1 tls subl $8, %ebp
318 1.1 tls jnz .L030encrypt_loop
319 1.1 tls .L029encrypt_finish:
320 1.1 tls movl 60(%esp), %ebp
321 1.1 tls andl $7, %ebp
322 1.1 tls jz .L031finish
323 1.1 tls xorl %ecx, %ecx
324 1.1 tls xorl %edx, %edx
325 1.1 tls movl .L032cbc_enc_jmp_table(,%ebp,4),%ebp
326 1.1 tls jmp *%ebp
327 1.1 tls .L033ej7:
328 1.1 tls movb 6(%esi), %dh
329 1.1 tls sall $8, %edx
330 1.1 tls .L034ej6:
331 1.1 tls movb 5(%esi), %dh
332 1.1 tls .L035ej5:
333 1.1 tls movb 4(%esi), %dl
334 1.1 tls .L036ej4:
335 1.1 tls movl (%esi), %ecx
336 1.1 tls jmp .L037ejend
337 1.1 tls .L038ej3:
338 1.1 tls movb 2(%esi), %ch
339 1.1 tls sall $8, %ecx
340 1.1 tls .L039ej2:
341 1.1 tls movb 1(%esi), %ch
342 1.1 tls .L040ej1:
343 1.1 tls movb (%esi), %cl
344 1.1 tls .L037ejend:
345 1.1 tls xorl %ecx, %eax
346 1.1 tls xorl %edx, %ebx
347 1.1 tls movl %eax, 16(%esp)
348 1.1 tls movl %ebx, 20(%esp)
349 1.1 tls call _C_LABEL(des_encrypt3)
350 1.1 tls movl 16(%esp), %eax
351 1.1 tls movl 20(%esp), %ebx
352 1.1 tls movl %eax, (%edi)
353 1.1 tls movl %ebx, 4(%edi)
354 1.1 tls jmp .L031finish
355 1.2 itohy #ifdef __ELF__
356 1.1 tls .align 16
357 1.2 itohy #else
358 1.2 itohy .align 4
359 1.2 itohy #endif
360 1.1 tls .L028decrypt:
361 1.1 tls andl $4294967288, %ebp
362 1.1 tls movl 24(%esp), %eax
363 1.1 tls movl 28(%esp), %ebx
364 1.1 tls jz .L041decrypt_finish
365 1.1 tls .L042decrypt_loop:
366 1.1 tls movl (%esi), %eax
367 1.1 tls movl 4(%esi), %ebx
368 1.1 tls movl %eax, 16(%esp)
369 1.1 tls movl %ebx, 20(%esp)
370 1.1 tls call _C_LABEL(des_decrypt3)
371 1.1 tls movl 16(%esp), %eax
372 1.1 tls movl 20(%esp), %ebx
373 1.1 tls movl 24(%esp), %ecx
374 1.1 tls movl 28(%esp), %edx
375 1.1 tls xorl %eax, %ecx
376 1.1 tls xorl %ebx, %edx
377 1.1 tls movl (%esi), %eax
378 1.1 tls movl 4(%esi), %ebx
379 1.1 tls movl %ecx, (%edi)
380 1.1 tls movl %edx, 4(%edi)
381 1.1 tls movl %eax, 24(%esp)
382 1.1 tls movl %ebx, 28(%esp)
383 1.1 tls addl $8, %esi
384 1.1 tls addl $8, %edi
385 1.1 tls subl $8, %ebp
386 1.1 tls jnz .L042decrypt_loop
387 1.1 tls .L041decrypt_finish:
388 1.1 tls movl 60(%esp), %ebp
389 1.1 tls andl $7, %ebp
390 1.1 tls jz .L031finish
391 1.1 tls movl (%esi), %eax
392 1.1 tls movl 4(%esi), %ebx
393 1.1 tls movl %eax, 16(%esp)
394 1.1 tls movl %ebx, 20(%esp)
395 1.1 tls call _C_LABEL(des_decrypt3)
396 1.1 tls movl 16(%esp), %eax
397 1.1 tls movl 20(%esp), %ebx
398 1.1 tls movl 24(%esp), %ecx
399 1.1 tls movl 28(%esp), %edx
400 1.1 tls xorl %eax, %ecx
401 1.1 tls xorl %ebx, %edx
402 1.1 tls movl (%esi), %eax
403 1.1 tls movl 4(%esi), %ebx
404 1.1 tls .L043dj7:
405 1.1 tls rorl $16, %edx
406 1.1 tls movb %dl, 6(%edi)
407 1.1 tls shrl $16, %edx
408 1.1 tls .L044dj6:
409 1.1 tls movb %dh, 5(%edi)
410 1.1 tls .L045dj5:
411 1.1 tls movb %dl, 4(%edi)
412 1.1 tls .L046dj4:
413 1.1 tls movl %ecx, (%edi)
414 1.1 tls jmp .L047djend
415 1.1 tls .L048dj3:
416 1.1 tls rorl $16, %ecx
417 1.1 tls movb %cl, 2(%edi)
418 1.1 tls sall $16, %ecx
419 1.1 tls .L049dj2:
420 1.1 tls movb %ch, 1(%esi)
421 1.1 tls .L050dj1:
422 1.1 tls movb %cl, (%esi)
423 1.1 tls .L047djend:
424 1.1 tls jmp .L031finish
425 1.2 itohy #ifdef __ELF__
426 1.1 tls .align 16
427 1.2 itohy #else
428 1.2 itohy .align 4
429 1.2 itohy #endif
430 1.1 tls .L031finish:
431 1.1 tls movl 76(%esp), %ecx
432 1.1 tls addl $32, %esp
433 1.1 tls movl %eax, (%ecx)
434 1.1 tls movl %ebx, 4(%ecx)
435 1.1 tls popl %edi
436 1.1 tls popl %esi
437 1.1 tls popl %ebx
438 1.1 tls popl %ebp
439 1.1 tls ret
440 1.2 itohy #ifdef __ELF__
441 1.1 tls .align 16
442 1.2 itohy #else
443 1.2 itohy .align 4
444 1.2 itohy #endif
445 1.1 tls .L032cbc_enc_jmp_table:
446 1.1 tls .long 0
447 1.1 tls .long .L040ej1
448 1.1 tls .long .L039ej2
449 1.1 tls .long .L038ej3
450 1.1 tls .long .L036ej4
451 1.1 tls .long .L035ej5
452 1.1 tls .long .L034ej6
453 1.1 tls .long .L033ej7
454 1.2 itohy #ifdef __ELF__
455 1.1 tls .align 16
456 1.2 itohy #else
457 1.2 itohy .align 4
458 1.2 itohy #endif
459 1.1 tls .L051cbc_dec_jmp_table:
460 1.1 tls .long 0
461 1.1 tls .long .L050dj1
462 1.1 tls .long .L049dj2
463 1.1 tls .long .L048dj3
464 1.1 tls .long .L046dj4
465 1.1 tls .long .L045dj5
466 1.1 tls .long .L044dj6
467 1.1 tls .long .L043dj7
468 1.1 tls .L_des_ede3_cbc_encrypt_end:
469 1.1 tls .size _C_LABEL(des_ede3_cbc_encrypt),.L_des_ede3_cbc_encrypt_end-_C_LABEL(des_ede3_cbc_encrypt)
470