Home | History | Annotate | Line # | Download | only in i386
bf_cbc.S revision 1.1
      1 /* $NetBSD: bf_cbc.S,v 1.1 2001/09/09 11:01:01 tls Exp $ */
      2 
      3 /* Copyright (C) 1995-1998 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 bf-686.pl elf' by
     62  * Thor Lancelot Simon <tls (at) netbsd.org>
     63  */
     64 
     65 #include <i386/include/asm.h>
     66 
     67 ENTRY(BF_cbc_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 3
     88 	movl	48(%esp),	%eax
     89 	pushl	%eax
     90 	pushl	%ebx
     91 	cmpl	$0,		%ecx
     92 	jz	.L000decrypt
     93 	andl	$4294967288,	%ebp
     94 	movl	8(%esp),	%eax
     95 	movl	12(%esp),	%ebx
     96 	jz	.L001encrypt_finish
     97 .L002encrypt_loop:
     98 	movl	(%esi),		%ecx
     99 	movl	4(%esi),	%edx
    100 	xorl	%ecx,		%eax
    101 	xorl	%edx,		%ebx
    102 .byte 15
    103 .byte 200		# bswapl  %eax
    104 .byte 15
    105 .byte 203		# bswapl  %ebx
    106 	movl	%eax,		8(%esp)
    107 	movl	%ebx,		12(%esp)
    108 	call	_C_LABEL(BF_encrypt)
    109 	movl	8(%esp),	%eax
    110 	movl	12(%esp),	%ebx
    111 .byte 15
    112 .byte 200		# bswapl  %eax
    113 .byte 15
    114 .byte 203		# bswapl  %ebx
    115 	movl	%eax,		(%edi)
    116 	movl	%ebx,		4(%edi)
    117 	addl	$8,		%esi
    118 	addl	$8,		%edi
    119 	subl	$8,		%ebp
    120 	jnz	.L002encrypt_loop
    121 .L001encrypt_finish:
    122 	movl	52(%esp),	%ebp
    123 	andl	$7,		%ebp
    124 	jz	.L003finish
    125 	xorl	%ecx,		%ecx
    126 	xorl	%edx,		%edx
    127 	movl	.L004cbc_enc_jmp_table(,%ebp,4),%ebp
    128 	jmp	*%ebp
    129 .L005ej7:
    130 	movb	6(%esi),	%dh
    131 	sall	$8,		%edx
    132 .L006ej6:
    133 	movb	5(%esi),	%dh
    134 .L007ej5:
    135 	movb	4(%esi),	%dl
    136 .L008ej4:
    137 	movl	(%esi),		%ecx
    138 	jmp	.L009ejend
    139 .L010ej3:
    140 	movb	2(%esi),	%ch
    141 	sall	$8,		%ecx
    142 .L011ej2:
    143 	movb	1(%esi),	%ch
    144 .L012ej1:
    145 	movb	(%esi),		%cl
    146 .L009ejend:
    147 	xorl	%ecx,		%eax
    148 	xorl	%edx,		%ebx
    149 .byte 15
    150 .byte 200		# bswapl  %eax
    151 .byte 15
    152 .byte 203		# bswapl  %ebx
    153 	movl	%eax,		8(%esp)
    154 	movl	%ebx,		12(%esp)
    155 	call	_C_LABEL(BF_encrypt)
    156 	movl	8(%esp),	%eax
    157 	movl	12(%esp),	%ebx
    158 .byte 15
    159 .byte 200		# bswapl  %eax
    160 .byte 15
    161 .byte 203		# bswapl  %ebx
    162 	movl	%eax,		(%edi)
    163 	movl	%ebx,		4(%edi)
    164 	jmp	.L003finish
    165 .align 16
    166 .L000decrypt:
    167 	andl	$4294967288,	%ebp
    168 	movl	16(%esp),	%eax
    169 	movl	20(%esp),	%ebx
    170 	jz	.L013decrypt_finish
    171 .L014decrypt_loop:
    172 	movl	(%esi),		%eax
    173 	movl	4(%esi),	%ebx
    174 .byte 15
    175 .byte 200		# bswapl  %eax
    176 .byte 15
    177 .byte 203		# bswapl  %ebx
    178 	movl	%eax,		8(%esp)
    179 	movl	%ebx,		12(%esp)
    180 	call	_C_LABEL(BF_decrypt)
    181 	movl	8(%esp),	%eax
    182 	movl	12(%esp),	%ebx
    183 .byte 15
    184 .byte 200		# bswapl  %eax
    185 .byte 15
    186 .byte 203		# bswapl  %ebx
    187 	movl	16(%esp),	%ecx
    188 	movl	20(%esp),	%edx
    189 	xorl	%eax,		%ecx
    190 	xorl	%ebx,		%edx
    191 	movl	(%esi),		%eax
    192 	movl	4(%esi),	%ebx
    193 	movl	%ecx,		(%edi)
    194 	movl	%edx,		4(%edi)
    195 	movl	%eax,		16(%esp)
    196 	movl	%ebx,		20(%esp)
    197 	addl	$8,		%esi
    198 	addl	$8,		%edi
    199 	subl	$8,		%ebp
    200 	jnz	.L014decrypt_loop
    201 .L013decrypt_finish:
    202 	movl	52(%esp),	%ebp
    203 	andl	$7,		%ebp
    204 	jz	.L003finish
    205 	movl	(%esi),		%eax
    206 	movl	4(%esi),	%ebx
    207 .byte 15
    208 .byte 200		# bswapl  %eax
    209 .byte 15
    210 .byte 203		# bswapl  %ebx
    211 	movl	%eax,		8(%esp)
    212 	movl	%ebx,		12(%esp)
    213 	call	_C_LABEL(BF_decrypt)
    214 	movl	8(%esp),	%eax
    215 	movl	12(%esp),	%ebx
    216 .byte 15
    217 .byte 200		# bswapl  %eax
    218 .byte 15
    219 .byte 203		# bswapl  %ebx
    220 	movl	16(%esp),	%ecx
    221 	movl	20(%esp),	%edx
    222 	xorl	%eax,		%ecx
    223 	xorl	%ebx,		%edx
    224 	movl	(%esi),		%eax
    225 	movl	4(%esi),	%ebx
    226 .L015dj7:
    227 	rorl	$16,		%edx
    228 	movb	%dl,		6(%edi)
    229 	shrl	$16,		%edx
    230 .L016dj6:
    231 	movb	%dh,		5(%edi)
    232 .L017dj5:
    233 	movb	%dl,		4(%edi)
    234 .L018dj4:
    235 	movl	%ecx,		(%edi)
    236 	jmp	.L019djend
    237 .L020dj3:
    238 	rorl	$16,		%ecx
    239 	movb	%cl,		2(%edi)
    240 	sall	$16,		%ecx
    241 .L021dj2:
    242 	movb	%ch,		1(%esi)
    243 .L022dj1:
    244 	movb	%cl,		(%esi)
    245 .L019djend:
    246 	jmp	.L003finish
    247 .align 16
    248 .L003finish:
    249 	movl	60(%esp),	%ecx
    250 	addl	$24,		%esp
    251 	movl	%eax,		(%ecx)
    252 	movl	%ebx,		4(%ecx)
    253 	popl	%edi
    254 	popl	%esi
    255 	popl	%ebx
    256 	popl	%ebp
    257 	ret
    258 .align 16
    259 .L004cbc_enc_jmp_table:
    260 	.long 0
    261 	.long .L012ej1
    262 	.long .L011ej2
    263 	.long .L010ej3
    264 	.long .L008ej4
    265 	.long .L007ej5
    266 	.long .L006ej6
    267 	.long .L005ej7
    268 .align 16
    269 .L023cbc_dec_jmp_table:
    270 	.long 0
    271 	.long .L022dj1
    272 	.long .L021dj2
    273 	.long .L020dj3
    274 	.long .L018dj4
    275 	.long .L017dj5
    276 	.long .L016dj6
    277 	.long .L015dj7
    278 .L_BF_cbc_encrypt_end:
    279 	.size	_C_LABEL(BF_cbc_encrypt),.L_BF_cbc_encrypt_end-_C_LABEL(BF_cbc_encrypt)
    280