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