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