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