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