Add asm versions of blowfish and des transforms for i386.

This also involved updating the in-kernel DES functions to correspond
to the versions in our in-tree OpenSSL, because the des_SPtrans table
has changed; the asm code will not work with the old permutation table!

C and i386 asm code for the DES, 3DES, and Blowfish CBC modes is also
included; it is not currently built as the ESP processing in esp_core.c
splits the CBC operation and the cipher transform apart.  Hopefully that
will be fixed as there is a substantial performance improvement to be had
from doing so.  It will remain necessary to use the C version of the
Blowfish CBC function on some i386 machines, however, as the asm version
uses bswapl, which ony 486 and later processors have.  The DES CBC code
doesn't have this problem.

Finally, change esp_core.c to use the ecb3_encrypt function instead of
calling ecb_encrypt three times; this improves performance a bit, in
particular in the asm case.
This commit is contained in:
tls 2001-09-09 11:00:59 +00:00
parent 9a621e89a7
commit 3d4146e21f
17 changed files with 5560 additions and 468 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: files.i386,v 1.191 2001/09/03 17:18:22 drochner Exp $
# $NetBSD: files.i386,v 1.192 2001/09/09 11:01:01 tls Exp $
#
# new style config file for i386 architecture
#
@ -84,6 +84,11 @@ file dev/cons.c
file arch/i386/i386/pmc.c perfctrs
file crypto/des/arch/i386/des_enc.S ipsec & ipsec_esp
#file crypto/des/arch/i386/des_cbc.S ipsec & ipsec_esp
file crypto/blowfish/arch/i386/bf_enc.S ipsec & ipsec_esp
#file crypto/blowfish/arch/i386/bf_cbc.S ipsec & ipsec_esp
#
# Machine-independent SCSI drivers
#

View File

@ -1,4 +1,4 @@
# $NetBSD: std.i386,v 1.20 2001/05/26 17:46:12 sommerfeld Exp $
# $NetBSD: std.i386,v 1.21 2001/09/09 11:01:01 tls Exp $
#
# standard, required NetBSD/i386 'options'
@ -8,4 +8,8 @@ options EXEC_AOUT # exec a.out binaries
options EXEC_ELF32 # exec ELF binaries
options EXEC_SCRIPT # exec #! scripts
options INET6_MD_CKSUM # machine-dependant code for in6_cksum
options INET6_MD_CKSUM # machine-dependant code for in6_cksum
options CRYPTO_MD_DES_ENC # machine-dependant code for DES
#options CRYPTO_MD_DES_CBC # machine-dependant DES CBC code
options CRYPTO_MD_BF_ENC # machine-dependant code for BF_encrypt
#options CRYPTO_MD_BF_CBC # careful: uses bswapl, requires 486

View File

@ -1,4 +1,4 @@
# $NetBSD: files,v 1.455 2001/09/01 23:50:43 thorpej Exp $
# $NetBSD: files,v 1.456 2001/09/09 11:01:00 tls Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
@ -722,7 +722,10 @@ file coda/coda_vnops.c coda
file crypto/arc4/arc4.c wlan
file crypto/des/des_ecb.c ipsec & ipsec_esp
file crypto/des/des_setkey.c ipsec & ipsec_esp
file crypto/blowfish/bf_enc.c ipsec & ipsec_esp
file crypto/des/des_enc.c ipsec & ipsec_esp & !crypto_md_des_enc
#file crypto/des/des_cbc.c ipsec & ipsec_esp & !crypto_md_des_cbc
file crypto/blowfish/bf_enc.c ipsec & ipsec_esp & !crypto_md_bf_enc
#file crypto/blowfish/bf_cbc.c ipsec & ipsec_esp & !crypto_md_bf_cbc
file crypto/blowfish/bf_skey.c ipsec & ipsec_esp
file crypto/cast128/cast128.c ipsec & ipsec_esp
file crypto/rijndael/rijndael-alg-fst.c ipsec & ipsec_esp

View File

@ -0,0 +1,279 @@
/* $NetBSD: bf_cbc.S,v 1.1 2001/09/09 11:01:01 tls Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
/*
* Modified from the output of `perl bf-686.pl elf' by
* Thor Lancelot Simon <tls@netbsd.org>
*/
#include <i386/include/asm.h>
ENTRY(BF_cbc_encrypt)
pushl %ebp
pushl %ebx
pushl %esi
pushl %edi
movl 28(%esp), %ebp
# getting iv ptr from parameter 4
movl 36(%esp), %ebx
movl (%ebx), %esi
movl 4(%ebx), %edi
pushl %edi
pushl %esi
pushl %edi
pushl %esi
movl %esp, %ebx
movl 36(%esp), %esi
movl 40(%esp), %edi
# getting encrypt flag from parameter 5
movl 56(%esp), %ecx
# get and push parameter 3
movl 48(%esp), %eax
pushl %eax
pushl %ebx
cmpl $0, %ecx
jz .L000decrypt
andl $4294967288, %ebp
movl 8(%esp), %eax
movl 12(%esp), %ebx
jz .L001encrypt_finish
.L002encrypt_loop:
movl (%esi), %ecx
movl 4(%esi), %edx
xorl %ecx, %eax
xorl %edx, %ebx
.byte 15
.byte 200 # bswapl %eax
.byte 15
.byte 203 # bswapl %ebx
movl %eax, 8(%esp)
movl %ebx, 12(%esp)
call _C_LABEL(BF_encrypt)
movl 8(%esp), %eax
movl 12(%esp), %ebx
.byte 15
.byte 200 # bswapl %eax
.byte 15
.byte 203 # bswapl %ebx
movl %eax, (%edi)
movl %ebx, 4(%edi)
addl $8, %esi
addl $8, %edi
subl $8, %ebp
jnz .L002encrypt_loop
.L001encrypt_finish:
movl 52(%esp), %ebp
andl $7, %ebp
jz .L003finish
xorl %ecx, %ecx
xorl %edx, %edx
movl .L004cbc_enc_jmp_table(,%ebp,4),%ebp
jmp *%ebp
.L005ej7:
movb 6(%esi), %dh
sall $8, %edx
.L006ej6:
movb 5(%esi), %dh
.L007ej5:
movb 4(%esi), %dl
.L008ej4:
movl (%esi), %ecx
jmp .L009ejend
.L010ej3:
movb 2(%esi), %ch
sall $8, %ecx
.L011ej2:
movb 1(%esi), %ch
.L012ej1:
movb (%esi), %cl
.L009ejend:
xorl %ecx, %eax
xorl %edx, %ebx
.byte 15
.byte 200 # bswapl %eax
.byte 15
.byte 203 # bswapl %ebx
movl %eax, 8(%esp)
movl %ebx, 12(%esp)
call _C_LABEL(BF_encrypt)
movl 8(%esp), %eax
movl 12(%esp), %ebx
.byte 15
.byte 200 # bswapl %eax
.byte 15
.byte 203 # bswapl %ebx
movl %eax, (%edi)
movl %ebx, 4(%edi)
jmp .L003finish
.align 16
.L000decrypt:
andl $4294967288, %ebp
movl 16(%esp), %eax
movl 20(%esp), %ebx
jz .L013decrypt_finish
.L014decrypt_loop:
movl (%esi), %eax
movl 4(%esi), %ebx
.byte 15
.byte 200 # bswapl %eax
.byte 15
.byte 203 # bswapl %ebx
movl %eax, 8(%esp)
movl %ebx, 12(%esp)
call _C_LABEL(BF_decrypt)
movl 8(%esp), %eax
movl 12(%esp), %ebx
.byte 15
.byte 200 # bswapl %eax
.byte 15
.byte 203 # bswapl %ebx
movl 16(%esp), %ecx
movl 20(%esp), %edx
xorl %eax, %ecx
xorl %ebx, %edx
movl (%esi), %eax
movl 4(%esi), %ebx
movl %ecx, (%edi)
movl %edx, 4(%edi)
movl %eax, 16(%esp)
movl %ebx, 20(%esp)
addl $8, %esi
addl $8, %edi
subl $8, %ebp
jnz .L014decrypt_loop
.L013decrypt_finish:
movl 52(%esp), %ebp
andl $7, %ebp
jz .L003finish
movl (%esi), %eax
movl 4(%esi), %ebx
.byte 15
.byte 200 # bswapl %eax
.byte 15
.byte 203 # bswapl %ebx
movl %eax, 8(%esp)
movl %ebx, 12(%esp)
call _C_LABEL(BF_decrypt)
movl 8(%esp), %eax
movl 12(%esp), %ebx
.byte 15
.byte 200 # bswapl %eax
.byte 15
.byte 203 # bswapl %ebx
movl 16(%esp), %ecx
movl 20(%esp), %edx
xorl %eax, %ecx
xorl %ebx, %edx
movl (%esi), %eax
movl 4(%esi), %ebx
.L015dj7:
rorl $16, %edx
movb %dl, 6(%edi)
shrl $16, %edx
.L016dj6:
movb %dh, 5(%edi)
.L017dj5:
movb %dl, 4(%edi)
.L018dj4:
movl %ecx, (%edi)
jmp .L019djend
.L020dj3:
rorl $16, %ecx
movb %cl, 2(%edi)
sall $16, %ecx
.L021dj2:
movb %ch, 1(%esi)
.L022dj1:
movb %cl, (%esi)
.L019djend:
jmp .L003finish
.align 16
.L003finish:
movl 60(%esp), %ecx
addl $24, %esp
movl %eax, (%ecx)
movl %ebx, 4(%ecx)
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
.align 16
.L004cbc_enc_jmp_table:
.long 0
.long .L012ej1
.long .L011ej2
.long .L010ej3
.long .L008ej4
.long .L007ej5
.long .L006ej6
.long .L005ej7
.align 16
.L023cbc_dec_jmp_table:
.long 0
.long .L022dj1
.long .L021dj2
.long .L020dj3
.long .L018dj4
.long .L017dj5
.long .L016dj6
.long .L015dj7
.L_BF_cbc_encrypt_end:
.size _C_LABEL(BF_cbc_encrypt),.L_BF_cbc_encrypt_end-_C_LABEL(BF_cbc_encrypt)

View File

@ -0,0 +1,16 @@
/* $NetBSD: bf_enc.S,v 1.1 2001/09/09 11:01:01 tls Exp $ */
/*
* Written by Jason R. Thorpe <thorpej@zembu.com> and Thor Lancelot Simon
* <tls@netbsd.org>. Public domain.
*/
/*
* XXX Should use CPP symbols defined as a result of
* XXX `cc -mcpu=pentiumpro'.
*/
#if defined(I386_CPU) || defined(I486_CPU) || defined(I586_CPU)
#include "bf_enc_586.S"
#else
#include "bf_enc_686.S"
#endif

View File

@ -0,0 +1,760 @@
/* $NetBSD: bf_enc_586.S,v 1.1 2001/09/09 11:01:01 tls Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
/*
* Modified from the output of `perl bf-586.pl elf' by
* Jason R. Thorpe <thorpej@zembu.com> and Thor Lancelot Simon
* <tls@netbsd.org>
*/
#include <i386/include/asm.h>
ENTRY(BF_encrypt)
pushl %ebp
pushl %ebx
movl 12(%esp), %ebx
movl 16(%esp), %ebp
pushl %esi
pushl %edi
/* Load the 2 words */
movl (%ebx), %edi
movl 4(%ebx), %esi
xorl %eax, %eax
movl (%ebp), %ebx
xorl %ecx, %ecx
xorl %ebx, %edi
/* Round 0 */
movl 4(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 1 */
movl 8(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %edi
/* Round 2 */
movl 12(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 3 */
movl 16(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %edi
/* Round 4 */
movl 20(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 5 */
movl 24(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %edi
/* Round 6 */
movl 28(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 7 */
movl 32(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %edi
/* Round 8 */
movl 36(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 9 */
movl 40(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %edi
/* Round 10 */
movl 44(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 11 */
movl 48(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %edi
/* Round 12 */
movl 52(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 13 */
movl 56(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %edi
/* Round 14 */
movl 60(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 15 */
movl 64(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
# Load parameter 0 (16) enc=1
movl 20(%esp), %eax
xorl %ebx, %edi
movl 68(%ebp), %edx
xorl %edx, %esi
movl %edi, 4(%eax)
movl %esi, (%eax)
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
.L_BF_encrypt_end:
.size _C_LABEL(BF_encrypt),.L_BF_encrypt_end-_C_LABEL(BF_encrypt)
ENTRY(BF_decrypt)
pushl %ebp
pushl %ebx
movl 12(%esp), %ebx
movl 16(%esp), %ebp
pushl %esi
pushl %edi
# Load the 2 words
movl (%ebx), %edi
movl 4(%ebx), %esi
xorl %eax, %eax
movl 68(%ebp), %ebx
xorl %ecx, %ecx
xorl %ebx, %edi
/* Round 16 */
movl 64(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 15 */
movl 60(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %edi
/* Round 14 */
movl 56(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 13 */
movl 52(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %edi
/* Round 12 */
movl 48(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 11 */
movl 44(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %edi
/* Round 10 */
movl 40(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 9 */
movl 36(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %edi
/* Round 8 */
movl 32(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 7 */
movl 28(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %edi
/* Round 6 */
movl 24(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 5 */
movl 20(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %edi
/* Round 4 */
movl 16(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 3 */
movl 12(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %edi
/* Round 2 */
movl 8(%ebp), %edx
movl %edi, %ebx
xorl %edx, %esi
shrl $16, %ebx
movl %edi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
xorl %eax, %eax
xorl %ebx, %esi
/* Round 1 */
movl 4(%ebp), %edx
movl %esi, %ebx
xorl %edx, %edi
shrl $16, %ebx
movl %esi, %edx
movb %bh, %al
andl $255, %ebx
movb %dh, %cl
andl $255, %edx
movl 72(%ebp,%eax,4),%eax
movl 1096(%ebp,%ebx,4),%ebx
addl %eax, %ebx
movl 2120(%ebp,%ecx,4),%eax
xorl %eax, %ebx
movl 3144(%ebp,%edx,4),%edx
addl %edx, %ebx
# Load parameter 0 (1) enc=0
movl 20(%esp), %eax
xorl %ebx, %edi
movl (%ebp), %edx
xorl %edx, %esi
movl %edi, 4(%eax)
movl %esi, (%eax)
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
.L_BF_decrypt_end:
.size _C_LABEL(BF_decrypt),.L_BF_decrypt_end-_C_LABEL(BF_decrypt)

View File

@ -0,0 +1,732 @@
/* $NetBSD: bf_enc_686.S,v 1.1 2001/09/09 11:01:02 tls Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
/*
* Modified from the output of `perl bf-686.pl elf' by
* Jason R. Thorpe <thorpej@zembu.com> and Thor Lancelot Simon
* <tls@netbsd.org>
*/
#include <i386/include/asm.h>
ENTRY(BF_encrypt)
pushl %ebp
pushl %ebx
pushl %esi
pushl %edi
/* Load the 2 words */
movl 20(%esp), %eax
movl (%eax), %ecx
movl 4(%eax), %edx
/* P pointer, s and enc flag */
movl 24(%esp), %edi
xorl %eax, %eax
xorl %ebx, %ebx
xorl (%edi), %ecx
/* Round 0 */
rorl $16, %ecx
movl 4(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 1 */
rorl $16, %edx
movl 8(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
/* Round 2 */
rorl $16, %ecx
movl 12(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 3 */
rorl $16, %edx
movl 16(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
/* Round 4 */
rorl $16, %ecx
movl 20(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 5 */
rorl $16, %edx
movl 24(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
/* Round 6 */
rorl $16, %ecx
movl 28(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 7 */
rorl $16, %edx
movl 32(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
/* Round 8 */
rorl $16, %ecx
movl 36(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 9 */
rorl $16, %edx
movl 40(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
/* Round 10 */
rorl $16, %ecx
movl 44(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 11 */
rorl $16, %edx
movl 48(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
/* Round 12 */
rorl $16, %ecx
movl 52(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 13 */
rorl $16, %edx
movl 56(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
/* Round 14 */
rorl $16, %ecx
movl 60(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 15 */
rorl $16, %edx
movl 64(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
xorl 68(%edi), %edx
movl 20(%esp), %eax
movl %edx, (%eax)
movl %ecx, 4(%eax)
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
.L_BF_encrypt_end:
.size _C_LABEL(BF_encrypt),.L_BF_encrypt_end-_C_LABEL(BF_encrypt)
ENTRY(BF_decrypt)
pushl %ebp
pushl %ebx
pushl %esi
pushl %edi
/* Load the 2 words */
movl 20(%esp), %eax
movl (%eax), %ecx
movl 4(%eax), %edx
/* P pointer, s and enc flag */
movl 24(%esp), %edi
xorl %eax, %eax
xorl %ebx, %ebx
xorl 68(%edi), %ecx
/* Round 16 */
rorl $16, %ecx
movl 64(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 15 */
rorl $16, %edx
movl 60(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
/* Round 14 */
rorl $16, %ecx
movl 56(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 13 */
rorl $16, %edx
movl 52(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
/* Round 12 */
rorl $16, %ecx
movl 48(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 11 */
rorl $16, %edx
movl 44(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
/* Round 10 */
rorl $16, %ecx
movl 40(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 9 */
rorl $16, %edx
movl 36(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
/* Round 8 */
rorl $16, %ecx
movl 32(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 7 */
rorl $16, %edx
movl 28(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
/* Round 6 */
rorl $16, %ecx
movl 24(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 5 */
rorl $16, %edx
movl 20(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
/* Round 4 */
rorl $16, %ecx
movl 16(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 3 */
rorl $16, %edx
movl 12(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
/* Round 2 */
rorl $16, %ecx
movl 8(%edi), %esi
movb %ch, %al
movb %cl, %bl
rorl $16, %ecx
xorl %esi, %edx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %ch, %al
movb %cl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %edx
/* Round 1 */
rorl $16, %edx
movl 4(%edi), %esi
movb %dh, %al
movb %dl, %bl
rorl $16, %edx
xorl %esi, %ecx
movl 72(%edi,%eax,4),%esi
movl 1096(%edi,%ebx,4),%ebp
movb %dh, %al
movb %dl, %bl
addl %ebp, %esi
movl 2120(%edi,%eax,4),%eax
xorl %eax, %esi
movl 3144(%edi,%ebx,4),%ebp
addl %ebp, %esi
xorl %eax, %eax
xorl %esi, %ecx
xorl (%edi), %edx
movl 20(%esp), %eax
movl %edx, (%eax)
movl %ecx, 4(%eax)
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
.L_BF_decrypt_end:
.size _C_LABEL(BF_decrypt),.L_BF_decrypt_end-_C_LABEL(BF_decrypt)

View File

@ -1,12 +1,9 @@
/* $NetBSD: bf_enc.c,v 1.3 2000/11/06 14:11:40 itojun Exp $ */
/* $KAME: bf_enc.c,v 1.5 2000/09/18 21:21:19 itojun Exp $ */
/* crypto/bf/bf_enc.c */
/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au)
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@mincom.oz.au).
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
@ -14,7 +11,7 @@
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@mincom.oz.au).
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
@ -34,12 +31,12 @@
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@mincom.oz.au)"
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@mincom.oz.au)"
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

View File

@ -1,4 +1,4 @@
/* $NetBSD: blowfish.h,v 1.3 2000/11/06 14:11:40 itojun Exp $ */
/* $NetBSD: blowfish.h,v 1.4 2001/09/09 11:01:01 tls Exp $ */
/* $KAME: blowfish.h,v 1.10 2000/09/18 21:21:20 itojun Exp $ */
/* crypto/bf/blowfish.h */
@ -82,6 +82,9 @@ typedef struct bf_key_st {
void BF_set_key __P((BF_KEY *, int, unsigned char *));
void BF_encrypt __P((BF_LONG *, BF_KEY *, int));
void BF_cbc_encrypt(const unsigned char *, unsigned char *, long,
const BF_KEY *, unsigned char *, int);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,437 @@
/* $NetBSD: des_cbc.S,v 1.1 2001/09/09 11:01:02 tls Exp $ */
/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
/*
* Modified from the output of `perl des686.pl elf' by
* Thor Lancelot Simon <tls@netbsd.org>
*/
#include <i386/include/asm.h>
ENTRY(des_ncbc_encrypt)
pushl %ebp
pushl %ebx
pushl %esi
pushl %edi
movl 28(%esp), %ebp
# getting iv ptr from parameter 4
movl 36(%esp), %ebx
movl (%ebx), %esi
movl 4(%ebx), %edi
pushl %edi
pushl %esi
pushl %edi
pushl %esi
movl %esp, %ebx
movl 36(%esp), %esi
movl 40(%esp), %edi
# getting encrypt flag from parameter 5
movl 56(%esp), %ecx
# get and push parameter 5
pushl %ecx
# get and push parameter 3
movl 52(%esp), %eax
pushl %eax
pushl %ebx
cmpl $0, %ecx
jz .L004decrypt
andl $4294967288, %ebp
movl 12(%esp), %eax
movl 16(%esp), %ebx
jz .L005encrypt_finish
.L006encrypt_loop:
movl (%esi), %ecx
movl 4(%esi), %edx
xorl %ecx, %eax
xorl %edx, %ebx
movl %eax, 12(%esp)
movl %ebx, 16(%esp)
call _C_LABEL(des_encrypt1)
movl 12(%esp), %eax
movl 16(%esp), %ebx
movl %eax, (%edi)
movl %ebx, 4(%edi)
addl $8, %esi
addl $8, %edi
subl $8, %ebp
jnz .L006encrypt_loop
.L005encrypt_finish:
movl 56(%esp), %ebp
andl $7, %ebp
jz .L007finish
xorl %ecx, %ecx
xorl %edx, %edx
movl .L008cbc_enc_jmp_table(,%ebp,4),%ebp
jmp *%ebp
.L009ej7:
movb 6(%esi), %dh
sall $8, %edx
.L010ej6:
movb 5(%esi), %dh
.L011ej5:
movb 4(%esi), %dl
.L012ej4:
movl (%esi), %ecx
jmp .L013ejend
.L014ej3:
movb 2(%esi), %ch
sall $8, %ecx
.L015ej2:
movb 1(%esi), %ch
.L016ej1:
movb (%esi), %cl
.L013ejend:
xorl %ecx, %eax
xorl %edx, %ebx
movl %eax, 12(%esp)
movl %ebx, 16(%esp)
call _C_LABEL(des_encrypt1)
movl 12(%esp), %eax
movl 16(%esp), %ebx
movl %eax, (%edi)
movl %ebx, 4(%edi)
jmp .L007finish
.align 16
.L004decrypt:
andl $4294967288, %ebp
movl 20(%esp), %eax
movl 24(%esp), %ebx
jz .L017decrypt_finish
.L018decrypt_loop:
movl (%esi), %eax
movl 4(%esi), %ebx
movl %eax, 12(%esp)
movl %ebx, 16(%esp)
call _C_LABEL(des_encrypt1)
movl 12(%esp), %eax
movl 16(%esp), %ebx
movl 20(%esp), %ecx
movl 24(%esp), %edx
xorl %eax, %ecx
xorl %ebx, %edx
movl (%esi), %eax
movl 4(%esi), %ebx
movl %ecx, (%edi)
movl %edx, 4(%edi)
movl %eax, 20(%esp)
movl %ebx, 24(%esp)
addl $8, %esi
addl $8, %edi
subl $8, %ebp
jnz .L018decrypt_loop
.L017decrypt_finish:
movl 56(%esp), %ebp
andl $7, %ebp
jz .L007finish
movl (%esi), %eax
movl 4(%esi), %ebx
movl %eax, 12(%esp)
movl %ebx, 16(%esp)
call _C_LABEL(des_encrypt1)
movl 12(%esp), %eax
movl 16(%esp), %ebx
movl 20(%esp), %ecx
movl 24(%esp), %edx
xorl %eax, %ecx
xorl %ebx, %edx
movl (%esi), %eax
movl 4(%esi), %ebx
.L019dj7:
rorl $16, %edx
movb %dl, 6(%edi)
shrl $16, %edx
.L020dj6:
movb %dh, 5(%edi)
.L021dj5:
movb %dl, 4(%edi)
.L022dj4:
movl %ecx, (%edi)
jmp .L023djend
.L024dj3:
rorl $16, %ecx
movb %cl, 2(%edi)
sall $16, %ecx
.L025dj2:
movb %ch, 1(%esi)
.L026dj1:
movb %cl, (%esi)
.L023djend:
jmp .L007finish
.align 16
.L007finish:
movl 64(%esp), %ecx
addl $28, %esp
movl %eax, (%ecx)
movl %ebx, 4(%ecx)
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
.align 16
.L008cbc_enc_jmp_table:
.long 0
.long .L016ej1
.long .L015ej2
.long .L014ej3
.long .L012ej4
.long .L011ej5
.long .L010ej6
.long .L009ej7
.align 16
.L027cbc_dec_jmp_table:
.long 0
.long .L026dj1
.long .L025dj2
.long .L024dj3
.long .L022dj4
.long .L021dj5
.long .L020dj6
.long .L019dj7
.L_des_ncbc_encrypt_end:
.size _C_LABEL(des_ncbc_encrypt),.L_des_ncbc_encrypt_end-_C_LABEL(des_ncbc_encrypt)
ENTRY(des_ede3_cbc_encrypt)
pushl %ebp
pushl %ebx
pushl %esi
pushl %edi
movl 28(%esp), %ebp
# getting iv ptr from parameter 6
movl 44(%esp), %ebx
movl (%ebx), %esi
movl 4(%ebx), %edi
pushl %edi
pushl %esi
pushl %edi
pushl %esi
movl %esp, %ebx
movl 36(%esp), %esi
movl 40(%esp), %edi
# getting encrypt flag from parameter 7
movl 64(%esp), %ecx
# get and push parameter 5
movl 56(%esp), %eax
pushl %eax
# get and push parameter 4
movl 56(%esp), %eax
pushl %eax
# get and push parameter 3
movl 56(%esp), %eax
pushl %eax
pushl %ebx
cmpl $0, %ecx
jz .L028decrypt
andl $4294967288, %ebp
movl 16(%esp), %eax
movl 20(%esp), %ebx
jz .L029encrypt_finish
.L030encrypt_loop:
movl (%esi), %ecx
movl 4(%esi), %edx
xorl %ecx, %eax
xorl %edx, %ebx
movl %eax, 16(%esp)
movl %ebx, 20(%esp)
call _C_LABEL(des_encrypt3)
movl 16(%esp), %eax
movl 20(%esp), %ebx
movl %eax, (%edi)
movl %ebx, 4(%edi)
addl $8, %esi
addl $8, %edi
subl $8, %ebp
jnz .L030encrypt_loop
.L029encrypt_finish:
movl 60(%esp), %ebp
andl $7, %ebp
jz .L031finish
xorl %ecx, %ecx
xorl %edx, %edx
movl .L032cbc_enc_jmp_table(,%ebp,4),%ebp
jmp *%ebp
.L033ej7:
movb 6(%esi), %dh
sall $8, %edx
.L034ej6:
movb 5(%esi), %dh
.L035ej5:
movb 4(%esi), %dl
.L036ej4:
movl (%esi), %ecx
jmp .L037ejend
.L038ej3:
movb 2(%esi), %ch
sall $8, %ecx
.L039ej2:
movb 1(%esi), %ch
.L040ej1:
movb (%esi), %cl
.L037ejend:
xorl %ecx, %eax
xorl %edx, %ebx
movl %eax, 16(%esp)
movl %ebx, 20(%esp)
call _C_LABEL(des_encrypt3)
movl 16(%esp), %eax
movl 20(%esp), %ebx
movl %eax, (%edi)
movl %ebx, 4(%edi)
jmp .L031finish
.align 16
.L028decrypt:
andl $4294967288, %ebp
movl 24(%esp), %eax
movl 28(%esp), %ebx
jz .L041decrypt_finish
.L042decrypt_loop:
movl (%esi), %eax
movl 4(%esi), %ebx
movl %eax, 16(%esp)
movl %ebx, 20(%esp)
call _C_LABEL(des_decrypt3)
movl 16(%esp), %eax
movl 20(%esp), %ebx
movl 24(%esp), %ecx
movl 28(%esp), %edx
xorl %eax, %ecx
xorl %ebx, %edx
movl (%esi), %eax
movl 4(%esi), %ebx
movl %ecx, (%edi)
movl %edx, 4(%edi)
movl %eax, 24(%esp)
movl %ebx, 28(%esp)
addl $8, %esi
addl $8, %edi
subl $8, %ebp
jnz .L042decrypt_loop
.L041decrypt_finish:
movl 60(%esp), %ebp
andl $7, %ebp
jz .L031finish
movl (%esi), %eax
movl 4(%esi), %ebx
movl %eax, 16(%esp)
movl %ebx, 20(%esp)
call _C_LABEL(des_decrypt3)
movl 16(%esp), %eax
movl 20(%esp), %ebx
movl 24(%esp), %ecx
movl 28(%esp), %edx
xorl %eax, %ecx
xorl %ebx, %edx
movl (%esi), %eax
movl 4(%esi), %ebx
.L043dj7:
rorl $16, %edx
movb %dl, 6(%edi)
shrl $16, %edx
.L044dj6:
movb %dh, 5(%edi)
.L045dj5:
movb %dl, 4(%edi)
.L046dj4:
movl %ecx, (%edi)
jmp .L047djend
.L048dj3:
rorl $16, %ecx
movb %cl, 2(%edi)
sall $16, %ecx
.L049dj2:
movb %ch, 1(%esi)
.L050dj1:
movb %cl, (%esi)
.L047djend:
jmp .L031finish
.align 16
.L031finish:
movl 76(%esp), %ecx
addl $32, %esp
movl %eax, (%ecx)
movl %ebx, 4(%ecx)
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
.align 16
.L032cbc_enc_jmp_table:
.long 0
.long .L040ej1
.long .L039ej2
.long .L038ej3
.long .L036ej4
.long .L035ej5
.long .L034ej6
.long .L033ej7
.align 16
.L051cbc_dec_jmp_table:
.long 0
.long .L050dj1
.long .L049dj2
.long .L048dj3
.long .L046dj4
.long .L045dj5
.long .L044dj6
.long .L043dj7
.L_des_ede3_cbc_encrypt_end:
.size _C_LABEL(des_ede3_cbc_encrypt),.L_des_ede3_cbc_encrypt_end-_C_LABEL(des_ede3_cbc_encrypt)

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: des.h,v 1.4 2000/11/06 14:11:41 itojun Exp $ */
/* $NetBSD: des.h,v 1.5 2001/09/09 11:01:02 tls Exp $ */
/* $KAME: des.h,v 1.7 2000/09/18 20:59:21 itojun Exp $ */
/* lib/des/des.h */
@ -61,15 +61,14 @@ extern "C" {
typedef unsigned char des_cblock[8];
typedef struct des_ks_struct
{
union {
des_cblock _;
/* make sure things are correct size on machines with
* 8 byte longs */
DES_LONG pad[2];
} ks;
#undef _
#define _ ks._
} des_key_schedule[16];
union {
des_cblock cblock;
/* make sure things are correct size on machines with
* 8 byte longs */
DES_LONG deslong[2];
} ks;
int weak_key;
} des_key_schedule[16];
#define DES_KEY_SZ (sizeof(des_cblock))
#define DES_SCHEDULE_SZ (sizeof(des_key_schedule))
@ -85,13 +84,32 @@ extern int des_check_key; /* defaults to false */
char *des_options __P((void));
void des_ecb_encrypt __P((des_cblock *, des_cblock *,
des_key_schedule, int));
void des_encrypt __P((DES_LONG *, des_key_schedule, int));
void des_encrypt1 __P((DES_LONG *, des_key_schedule, int));
void des_encrypt2 __P((DES_LONG *, des_key_schedule, int));
void des_encrypt3 __P((DES_LONG *, des_key_schedule, des_key_schedule,
des_key_schedule));
void des_decrypt3 __P((DES_LONG *, des_key_schedule, des_key_schedule,
des_key_schedule));
void des_ecb3_encrypt __P((des_cblock *, des_cblock *, des_key_schedule,
des_key_schedule, des_key_schedule, int));
void des_ncbc_encrypt __P((const unsigned char *, unsigned char *, long,
des_key_schedule, des_cblock *, int));
void des_ede3_cbc_encrypt(const unsigned char *, unsigned char *, long,
des_key_schedule, des_key_schedule,
des_key_schedule, des_cblock *, int);
void des_set_odd_parity __P((des_cblock *));
void des_fixup_key_parity __P((des_cblock *));
int des_is_weak_key __P((des_cblock *));
int des_set_key __P((des_cblock *, des_key_schedule));
int des_key_sched __P((des_cblock *, des_key_schedule));
int des_set_key_checked __P((des_cblock *, des_key_schedule));
void des_set_key_unchecked __P((des_cblock *, des_key_schedule));
int des_check_key_parity __P((des_cblock *));
#ifdef __cplusplus
}

View File

@ -1,8 +1,8 @@
/* $NetBSD: des_ecb.c,v 1.3 2000/11/06 14:11:41 itojun Exp $ */
/* $NetBSD: des_ecb.c,v 1.4 2001/09/09 11:01:02 tls Exp $ */
/* $KAME: des_ecb.c,v 1.5 2000/11/06 13:58:08 itojun Exp $ */
/* crypto/des/ecb_enc.c */
/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
/* Copyright (C) 1995-1998 Eric Young (eay@mincom.oz.au)
* All rights reserved.
*
* This file is part of an SSL implementation written
@ -57,182 +57,84 @@
#include <crypto/des/des_locl.h>
#include <crypto/des/spr.h>
char *libdes_version="libdes v 3.24 - 20-Apr-1996 - eay";
char *DES_version="DES part of SSLeay 0.6.4 30-Aug-1996";
/* char *libdes_version="libdes v 3.24 - 20-Apr-1996 - eay"; */ /* wrong */
/* char *DES_version="DES part of SSLeay 0.6.4 30-Aug-1996"; */
char *des_options(void)
{
static int init=1;
static char buf[32];
if (init)
{
const char *ptr,*unroll,*risc,*size;
char *des_options()
{
#ifdef DES_PTR
if (sizeof(DES_LONG) != sizeof(long))
return("des(ptr,int)");
else
return("des(ptr,long)");
ptr="ptr";
#else
if (sizeof(DES_LONG) != sizeof(long))
return("des(idx,int)");
else
return("des(idx,long)");
ptr="idx";
#endif
}
void des_ecb_encrypt(input, output, ks, encrypt)
des_cblock (*input);
des_cblock (*output);
des_key_schedule ks;
int encrypt;
{
#if defined(DES_RISC1) || defined(DES_RISC2)
#ifdef DES_RISC1
risc="risc1";
#endif
#ifdef DES_RISC2
risc="risc2";
#endif
#else
risc="cisc";
#endif
#ifdef DES_UNROLL
unroll="16";
#else
unroll="4";
#endif
if (sizeof(DES_LONG) != sizeof(long))
size="int";
else
size="long";
sprintf(buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,size);
init=0;
}
return(buf);
}
void des_ecb_encrypt(des_cblock *input, des_cblock *output,
des_key_schedule ks, int enc)
{
register DES_LONG l;
register unsigned char *in,*out;
DES_LONG ll[2];
const unsigned char *in=&(*input)[0];
unsigned char *out = &(*output)[0];
in=(unsigned char *)input;
out=(unsigned char *)output;
c2l(in,l); ll[0]=l;
c2l(in,l); ll[1]=l;
des_encrypt(ll,ks,encrypt);
des_encrypt1(ll,ks,enc);
l=ll[0]; l2c(l,out);
l=ll[1]; l2c(l,out);
l=ll[0]=ll[1]=0;
}
}
void des_encrypt(data, ks, encrypt)
DES_LONG *data;
des_key_schedule ks;
int encrypt;
{
register DES_LONG l,r,t,u;
#ifdef DES_PTR
register unsigned char *des_SP=(unsigned char *)des_SPtrans;
#endif
#ifdef undef
union fudge {
DES_LONG l;
unsigned short s[2];
unsigned char c[4];
} U,T;
#endif
register int i;
register DES_LONG *s;
void des_ecb3_encrypt(des_cblock *input, des_cblock *output,
des_key_schedule ks1, des_key_schedule ks2, des_key_schedule ks3,
int enc)
{
register DES_LONG l0,l1;
DES_LONG ll[2];
const unsigned char *in = &(*input)[0];
unsigned char *out = &(*output)[0];
c2l(in,l0);
c2l(in,l1);
ll[0]=l0;
ll[1]=l1;
u=data[0];
r=data[1];
IP(u,r);
/* Things have been modified so that the initial rotate is
* done outside the loop. This required the
* des_SPtrans values in sp.h to be rotated 1 bit to the right.
* One perl script later and things have a 5% speed up on a sparc2.
* Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
* for pointing this out. */
l=(r<<1)|(r>>31);
r=(u<<1)|(u>>31);
/* clear the top bits on machines with 8byte longs */
l&=0xffffffffL;
r&=0xffffffffL;
s=(DES_LONG *)ks;
/* I don't know if it is worth the effort of loop unrolling the
* inner loop
*/
if (encrypt)
{
for (i=0; i<32; i+=8)
{
D_ENCRYPT(l,r,i+0); /* 1 */
D_ENCRYPT(r,l,i+2); /* 2 */
D_ENCRYPT(l,r,i+4); /* 3 */
D_ENCRYPT(r,l,i+6); /* 4 */
}
}
if (enc)
des_encrypt3(ll,ks1,ks2,ks3);
else
{
for (i=30; i>0; i-=8)
{
D_ENCRYPT(l,r,i-0); /* 16 */
D_ENCRYPT(r,l,i-2); /* 15 */
D_ENCRYPT(l,r,i-4); /* 14 */
D_ENCRYPT(r,l,i-6); /* 13 */
}
}
l=(l>>1)|(l<<31);
r=(r>>1)|(r<<31);
/* clear the top bits on machines with 8byte longs */
l&=0xffffffffL;
r&=0xffffffffL;
des_decrypt3(ll,ks1,ks2,ks3);
FP(r,l);
data[0]=l;
data[1]=r;
l=r=t=u=0;
}
void des_encrypt2(data, ks, encrypt)
DES_LONG *data;
des_key_schedule ks;
int encrypt;
{
register DES_LONG l,r,t,u;
#ifdef DES_PTR
register unsigned char *des_SP=(unsigned char *)des_SPtrans;
#endif
#ifdef undef
union fudge {
DES_LONG l;
unsigned short s[2];
unsigned char c[4];
} U,T;
#endif
register int i;
register DES_LONG *s;
u=data[0];
r=data[1];
/* Things have been modified so that the initial rotate is
* done outside the loop. This required the
* des_SPtrans values in sp.h to be rotated 1 bit to the right.
* One perl script later and things have a 5% speed up on a sparc2.
* Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
* for pointing this out. */
l=(r<<1)|(r>>31);
r=(u<<1)|(u>>31);
/* clear the top bits on machines with 8byte longs */
l&=0xffffffffL;
r&=0xffffffffL;
s=(DES_LONG *)ks;
/* I don't know if it is worth the effort of loop unrolling the
* inner loop */
if (encrypt)
{
for (i=0; i<32; i+=8)
{
D_ENCRYPT(l,r,i+0); /* 1 */
D_ENCRYPT(r,l,i+2); /* 2 */
D_ENCRYPT(l,r,i+4); /* 3 */
D_ENCRYPT(r,l,i+6); /* 4 */
}
}
else
{
for (i=30; i>0; i-=8)
{
D_ENCRYPT(l,r,i-0); /* 16 */
D_ENCRYPT(r,l,i-2); /* 15 */
D_ENCRYPT(l,r,i-4); /* 14 */
D_ENCRYPT(r,l,i-6); /* 13 */
}
}
l=(l>>1)|(l<<31);
r=(r>>1)|(r<<31);
/* clear the top bits on machines with 8byte longs */
l&=0xffffffffL;
r&=0xffffffffL;
data[0]=l;
data[1]=r;
l=r=t=u=0;
}
l0=ll[0];
l1=ll[1];
l2c(l0,out);
l2c(l1,out);
}

View File

@ -1,8 +1,8 @@
/* $NetBSD: des_locl.h,v 1.3 2000/11/06 14:11:41 itojun Exp $ */
/* $NetBSD: des_locl.h,v 1.4 2001/09/09 11:01:02 tls Exp $ */
/* $KAME: des_locl.h,v 1.6 2000/11/06 13:58:09 itojun Exp $ */
/* lib/des/des_locl.h */
/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
/* crypto/des/des_locl.h */
/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au)
* All rights reserved.
*
* This file is part of an SSL implementation written
@ -47,13 +47,6 @@
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
* Always modify des_locl.org since des_locl.h is automatically generated from
* it during SSLeay configuration.
*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*/
#ifndef HEADER_DES_LOCL_H
#define HEADER_DES_LOCL_H
@ -130,6 +123,11 @@
#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n))))
#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g)
#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
u=R^s[S ]; \
t=R^s[S+1]
/* The changes to this macro may help or hinder, depending on the
* compiler and the achitecture. gcc2 always seems to do well :-).
* Inspired by Dana How <how@isl.stanford.edu>
@ -138,49 +136,170 @@
* bytes, probably an issue of accessing non-word aligned objects :-( */
#ifdef DES_PTR
#define D_ENCRYPT(L,R,S) { \
u=((R^s[S ])<<2); \
t= R^s[S+1]; \
t=ROTATE(t,2); \
L^= (\
*(DES_LONG *)((unsigned char *)des_SP+0x100+((t )&0xfc))+ \
*(DES_LONG *)((unsigned char *)des_SP+0x300+((t>> 8)&0xfc))+ \
*(DES_LONG *)((unsigned char *)des_SP+0x500+((t>>16)&0xfc))+ \
*(DES_LONG *)((unsigned char *)des_SP+0x700+((t>>24)&0xfc))+ \
*(DES_LONG *)((unsigned char *)des_SP +((u )&0xfc))+ \
*(DES_LONG *)((unsigned char *)des_SP+0x200+((u>> 8)&0xfc))+ \
*(DES_LONG *)((unsigned char *)des_SP+0x400+((u>>16)&0xfc))+ \
*(DES_LONG *)((unsigned char *)des_SP+0x600+((u>>24)&0xfc))); }
#else /* original version */
#ifdef undef
#define D_ENCRYPT(L,R,S) \
U.l=R^s[S+1]; \
T.s[0]=((U.s[0]>>4)|(U.s[1]<<12))&0x3f3f; \
T.s[1]=((U.s[1]>>4)|(U.s[0]<<12))&0x3f3f; \
U.l=(R^s[S ])&0x3f3f3f3fL; \
L^= des_SPtrans[1][(T.c[0])]| \
des_SPtrans[3][(T.c[1])]| \
des_SPtrans[5][(T.c[2])]| \
des_SPtrans[7][(T.c[3])]| \
des_SPtrans[0][(U.c[0])]| \
des_SPtrans[2][(U.c[1])]| \
des_SPtrans[4][(U.c[2])]| \
des_SPtrans[6][(U.c[3])];
#else
#define D_ENCRYPT(Q,R,S) {\
u=(R^s[S ]); \
t=R^s[S+1]; \
/* It recently occurred to me that 0^0^0^0^0^0^0 == 0, so there
* is no reason to not xor all the sub items together. This potentially
* saves a register since things can be xored directly into L */
#if defined(DES_RISC1) || defined(DES_RISC2)
#ifdef DES_RISC1
#define D_ENCRYPT(LL,R,S) { \
unsigned int u1,u2,u3; \
LOAD_DATA(R,S,u,t,E0,E1,u1); \
u2=(int)u>>8L; \
u1=(int)u&0xfc; \
u2&=0xfc; \
t=ROTATE(t,4); \
u>>=16L; \
LL^= *(const DES_LONG *)(des_SP +u1); \
LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
u3=(int)(u>>8L); \
u1=(int)u&0xfc; \
u3&=0xfc; \
LL^= *(const DES_LONG *)(des_SP+0x400+u1); \
LL^= *(const DES_LONG *)(des_SP+0x600+u3); \
u2=(int)t>>8L; \
u1=(int)t&0xfc; \
u2&=0xfc; \
t>>=16L; \
LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
u3=(int)t>>8L; \
u1=(int)t&0xfc; \
u3&=0xfc; \
LL^= *(const DES_LONG *)(des_SP+0x500+u1); \
LL^= *(const DES_LONG *)(des_SP+0x700+u3); }
#endif /* DES_RISC1 */
#ifdef DES_RISC2
#define D_ENCRYPT(LL,R,S) { \
unsigned int u1,u2,s1,s2; \
LOAD_DATA(R,S,u,t,E0,E1,u1); \
u2=(int)u>>8L; \
u1=(int)u&0xfc; \
u2&=0xfc; \
t=ROTATE(t,4); \
LL^= *(const DES_LONG *)(des_SP +u1); \
LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
s1=(int)(u>>16L); \
s2=(int)(u>>24L); \
s1&=0xfc; \
s2&=0xfc; \
LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
u2=(int)t>>8L; \
u1=(int)t&0xfc; \
u2&=0xfc; \
LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
s1=(int)(t>>16L); \
s2=(int)(t>>24L); \
s1&=0xfc; \
s2&=0xfc; \
LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
u2=(int)t>>8L; \
u1=(int)t&0xfc; \
u2&=0xfc; \
LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
s1=(int)(t>>16L); \
s2=(int)(t>>24L); \
s1&=0xfc; \
s2&=0xfc; \
LL^= *(const DES_LONG *)(des_SP+0x500+s1); \
LL^= *(const DES_LONG *)(des_SP+0x700+s2); }
#endif /* DES_RISC2 */
#else /* DES_RISC1 || DES_RISC2 */
#define D_ENCRYPT(LL,R,S) { \
LOAD_DATA_tmp(R,S,u,t,E0,E1); \
t=ROTATE(t,4); \
Q^= des_SPtrans[1][(t )&0x3f]| \
des_SPtrans[3][(t>> 8L)&0x3f]| \
des_SPtrans[5][(t>>16L)&0x3f]| \
des_SPtrans[7][(t>>24L)&0x3f]| \
des_SPtrans[0][(u )&0x3f]| \
des_SPtrans[2][(u>> 8L)&0x3f]| \
des_SPtrans[4][(u>>16L)&0x3f]| \
des_SPtrans[6][(u>>24L)&0x3f]; }
#endif
#endif
LL^= \
*(const DES_LONG *)(des_SP +((u )&0xfc))^ \
*(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \
*(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \
*(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \
*(const DES_LONG *)(des_SP+0x100+((t )&0xfc))^ \
*(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \
*(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \
*(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); }
#endif /* DES_RISC1 || DES_RISC2 */
#else /* original version */
#if defined(DES_RISC1) || defined(DES_RISC2)
#ifdef DES_RISC1
#define D_ENCRYPT(LL,R,S) {\
unsigned int u1,u2,u3; \
LOAD_DATA(R,S,u,t,E0,E1,u1); \
u>>=2L; \
t=ROTATE(t,6); \
u2=(int)u>>8L; \
u1=(int)u&0x3f; \
u2&=0x3f; \
u>>=16L; \
LL^=des_SPtrans[0][u1]; \
LL^=des_SPtrans[2][u2]; \
u3=(int)u>>8L; \
u1=(int)u&0x3f; \
u3&=0x3f; \
LL^=des_SPtrans[4][u1]; \
LL^=des_SPtrans[6][u3]; \
u2=(int)t>>8L; \
u1=(int)t&0x3f; \
u2&=0x3f; \
t>>=16L; \
LL^=des_SPtrans[1][u1]; \
LL^=des_SPtrans[3][u2]; \
u3=(int)t>>8L; \
u1=(int)t&0x3f; \
u3&=0x3f; \
LL^=des_SPtrans[5][u1]; \
LL^=des_SPtrans[7][u3]; }
#endif /* DES_RISC1 */
#ifdef DES_RISC2
#define D_ENCRYPT(LL,R,S) {\
unsigned int u1,u2,s1,s2; \
LOAD_DATA(R,S,u,t,E0,E1,u1); \
u>>=2L; \
t=ROTATE(t,6); \
u2=(int)u>>8L; \
u1=(int)u&0x3f; \
u2&=0x3f; \
LL^=des_SPtrans[0][u1]; \
LL^=des_SPtrans[2][u2]; \
s1=(int)u>>16L; \
s2=(int)u>>24L; \
s1&=0x3f; \
s2&=0x3f; \
LL^=des_SPtrans[4][s1]; \
LL^=des_SPtrans[6][s2]; \
u2=(int)t>>8L; \
u1=(int)t&0x3f; \
u2&=0x3f; \
LL^=des_SPtrans[1][u1]; \
LL^=des_SPtrans[3][u2]; \
s1=(int)t>>16; \
s2=(int)t>>24L; \
s1&=0x3f; \
s2&=0x3f; \
LL^=des_SPtrans[5][s1]; \
LL^=des_SPtrans[7][s2]; }
#endif /* DES_RISC2 */
#else /* DES_RISC1 || DES_RISC2 */
#define D_ENCRYPT(LL,R,S) {\
LOAD_DATA_tmp(R,S,u,t,E0,E1); \
t=ROTATE(t,4); \
LL^=\
des_SPtrans[0][(u>> 2L)&0x3f]^ \
des_SPtrans[2][(u>>10L)&0x3f]^ \
des_SPtrans[4][(u>>18L)&0x3f]^ \
des_SPtrans[6][(u>>26L)&0x3f]^ \
des_SPtrans[1][(t>> 2L)&0x3f]^ \
des_SPtrans[3][(t>>10L)&0x3f]^ \
des_SPtrans[5][(t>>18L)&0x3f]^ \
des_SPtrans[7][(t>>26L)&0x3f]; }
#endif /* DES_RISC1 || DES_RISC2 */
#endif /* DES_PTR */
/* IP and FP
* The problem is more of a geometric problem that random bit fiddling.

View File

@ -1,4 +1,4 @@
/* $NetBSD: des_setkey.c,v 1.5 2001/07/03 14:29:45 itojun Exp $ */
/* $NetBSD: des_setkey.c,v 1.6 2001/09/09 11:01:02 tls Exp $ */
/* $KAME: des_setkey.c,v 1.6 2001/07/03 14:27:53 itojun Exp $ */
/* crypto/des/set_key.c */
@ -65,22 +65,18 @@
#include <crypto/des/podd.h>
#include <crypto/des/sk.h>
static int check_parity __P((des_cblock (*)));
int des_check_key=0;
void des_set_odd_parity(key)
des_cblock (*key);
{
void des_set_odd_parity(des_cblock *key)
{
int i;
for (i=0; i<DES_KEY_SZ; i++)
(*key)[i]=odd_parity[(*key)[i]];
}
}
static int check_parity(key)
des_cblock (*key);
{
int des_check_key_parity(des_cblock *key)
{
int i;
for (i=0; i<DES_KEY_SZ; i++)
@ -89,7 +85,7 @@ des_cblock (*key);
return(0);
}
return(1);
}
}
/* Weak and semi week keys as take from
* %A D.W. Davies
@ -101,12 +97,12 @@ des_cblock (*key);
* (and actual cblock values).
*/
#define NUM_WEAK_KEY 16
static const des_cblock weak_keys[NUM_WEAK_KEY]={
static des_cblock weak_keys[NUM_WEAK_KEY]={
/* weak keys */
{0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
{0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
{0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F},
{0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0},
{0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
{0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1},
/* semi-weak keys */
{0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE},
{0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01},
@ -121,22 +117,23 @@ static const des_cblock weak_keys[NUM_WEAK_KEY]={
{0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
{0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
int des_is_weak_key(key)
des_cblock (*key);
{
int des_is_weak_key(des_cblock *key)
{
int i;
for (i=0; i<NUM_WEAK_KEY; i++)
/* Added == 0 to comparision, I obviously don't run
/* Added == 0 to comparison, I obviously don't run
* this section very often :-(, thanks to
* engineering@MorningStar.Com for the fix
* eay 93/06/29 */
if (bcmp(weak_keys[i],key,sizeof(*key)) == 0) return(1);
* eay 93/06/29
* Another problem, I was comparing only the first 4
* bytes, 97/03/18 */
if (memcmp(weak_keys[i],key,sizeof(des_cblock)) == 0) return(1);
return(0);
}
}
/* NOW DEFINED IN des_local.h
* See ecb_encrypt.c for a pseudo description of these macros.
* See ecb_encrypt.c for a pseudo description of these macros.
* #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
* (b)^=(t),\
* (a)=((a)^((t)<<(n))))
@ -145,49 +142,48 @@ des_cblock (*key);
#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
(a)=(a)^(t)^(t>>(16-(n))))
int des_set_key(des_cblock *key, des_key_schedule schedule)
{
if (des_check_key)
{
return des_set_key_checked(key, schedule);
}
else
{
des_set_key_unchecked(key, schedule);
return 0;
}
}
/* return 0 if key parity is odd (correct),
* return -1 if key parity error,
* return -2 if illegal weak key.
*/
int des_set_key(key, schedule)
des_cblock (*key);
des_key_schedule schedule;
{
static const int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
register DES_LONG c,d,t,s;
register unsigned char *in;
int des_set_key_checked(des_cblock *key, des_key_schedule schedule)
{
if (!des_check_key_parity(key))
return(-1);
if (des_is_weak_key(key))
return(-2);
des_set_key_unchecked(key, schedule);
return 0;
}
void des_set_key_unchecked(des_cblock *key, des_key_schedule schedule)
{
static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
register DES_LONG c,d,t,s,t2;
register const unsigned char *in;
register DES_LONG *k;
register int i;
if (des_check_key)
{
if (!check_parity(key))
return(-1);
if (des_is_weak_key(key))
return(-2);
}
k=(DES_LONG *)schedule;
in=(unsigned char *)key;
k = &schedule->ks.deslong[0];
in = &(*key)[0];
c2l(in,c);
c2l(in,d);
/* do PC1 in 60 simple operations */
/* PERM_OP(d,c,t,4,0x0f0f0f0fL);
HPERM_OP(c,t,-2, 0xcccc0000L);
HPERM_OP(c,t,-1, 0xaaaa0000L);
HPERM_OP(c,t, 8, 0x00ff0000L);
HPERM_OP(c,t,-1, 0xaaaa0000L);
HPERM_OP(d,t,-8, 0xff000000L);
HPERM_OP(d,t, 8, 0x00ff0000L);
HPERM_OP(d,t, 2, 0x33330000L);
d=((d&0x00aa00aaL)<<7L)|((d&0x55005500L)>>7L)|(d&0xaa55aa55L);
d=(d>>8)|((c&0xf0000000L)>>4);
c&=0x0fffffffL; */
/* I now do it in 47 simple operations :-)
/* do PC1 in 47 simple operations :-)
* Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
* for the inspiration. :-) */
PERM_OP (d,c,t,4,0x0f0f0f0fL);
@ -201,7 +197,7 @@ des_key_schedule schedule;
c&=0x0fffffffL;
for (i=0; i<ITERATIONS; i++)
{
{
if (shifts2[i])
{ c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); }
else
@ -209,30 +205,32 @@ des_key_schedule schedule;
c&=0x0fffffffL;
d&=0x0fffffffL;
/* could be a few less shifts but I am to lazy at this
* point in time to investigate */
* point in time to investigate */
s= des_skb[0][ (c )&0x3f ]|
des_skb[1][((c>> 6)&0x03)|((c>> 7L)&0x3c)]|
des_skb[2][((c>>13)&0x0f)|((c>>14L)&0x30)]|
des_skb[3][((c>>20)&0x01)|((c>>21L)&0x06) |
((c>>22L)&0x38)];
des_skb[1][((c>> 6L)&0x03)|((c>> 7L)&0x3c)]|
des_skb[2][((c>>13L)&0x0f)|((c>>14L)&0x30)]|
des_skb[3][((c>>20L)&0x01)|((c>>21L)&0x06) |
((c>>22L)&0x38)];
t= des_skb[4][ (d )&0x3f ]|
des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]|
des_skb[6][ (d>>15L)&0x3f ]|
des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)];
/* table contained 0213 4657 */
*(k++)=((t<<16L)|(s&0x0000ffffL))&0xffffffffL;
s= ((s>>16L)|(t&0xffff0000L));
s=(s<<4L)|(s>>28L);
*(k++)=s&0xffffffffL;
}
return(0);
}
t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL;
*(k++)=ROTATE(t2,30)&0xffffffffL;
int des_key_sched(key, schedule)
des_cblock (*key);
des_key_schedule schedule;
{
return(des_set_key(key,schedule));
t2=((s>>16L)|(t&0xffff0000L));
*(k++)=ROTATE(t2,26)&0xffffffffL;
}
}
int des_key_sched(des_cblock *key, des_key_schedule schedule)
{
return(des_set_key(key,schedule));
}
void des_fixup_key_parity(des_cblock *key)
{
des_set_odd_parity(key);
}

View File

@ -1,23 +1,25 @@
/* $NetBSD: spr.h,v 1.1.1.1 2000/06/14 19:45:36 thorpej Exp $ */
/* $KAME: spr.h,v 1.3 2000/03/27 04:36:35 sumikawa Exp $ */
/* crypto/des/spr.h */
/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This file is part of an SSL implementation written
* by Eric Young (eay@mincom.oz.au).
* The implementation was written so as to conform with Netscapes SSL
* specification. This library and applications are
* FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
* as long as the following conditions are aheared to.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed. If this code is used in a product,
* Eric Young should be given attribution as the author of the parts used.
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@ -28,8 +30,14 @@
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Eric Young (eay@mincom.oz.au)
*
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@ -41,156 +49,156 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
static const DES_LONG des_SPtrans[8][64]={
const DES_LONG des_SPtrans[8][64]={
{
/* nibble 0 */
0x00820200L, 0x00020000L, 0x80800000L, 0x80820200L,
0x00800000L, 0x80020200L, 0x80020000L, 0x80800000L,
0x80020200L, 0x00820200L, 0x00820000L, 0x80000200L,
0x80800200L, 0x00800000L, 0x00000000L, 0x80020000L,
0x00020000L, 0x80000000L, 0x00800200L, 0x00020200L,
0x80820200L, 0x00820000L, 0x80000200L, 0x00800200L,
0x80000000L, 0x00000200L, 0x00020200L, 0x80820000L,
0x00000200L, 0x80800200L, 0x80820000L, 0x00000000L,
0x00000000L, 0x80820200L, 0x00800200L, 0x80020000L,
0x00820200L, 0x00020000L, 0x80000200L, 0x00800200L,
0x80820000L, 0x00000200L, 0x00020200L, 0x80800000L,
0x80020200L, 0x80000000L, 0x80800000L, 0x00820000L,
0x80820200L, 0x00020200L, 0x00820000L, 0x80800200L,
0x00800000L, 0x80000200L, 0x80020000L, 0x00000000L,
0x00020000L, 0x00800000L, 0x80800200L, 0x00820200L,
0x80000000L, 0x80820000L, 0x00000200L, 0x80020200L,
0x02080800L, 0x00080000L, 0x02000002L, 0x02080802L,
0x02000000L, 0x00080802L, 0x00080002L, 0x02000002L,
0x00080802L, 0x02080800L, 0x02080000L, 0x00000802L,
0x02000802L, 0x02000000L, 0x00000000L, 0x00080002L,
0x00080000L, 0x00000002L, 0x02000800L, 0x00080800L,
0x02080802L, 0x02080000L, 0x00000802L, 0x02000800L,
0x00000002L, 0x00000800L, 0x00080800L, 0x02080002L,
0x00000800L, 0x02000802L, 0x02080002L, 0x00000000L,
0x00000000L, 0x02080802L, 0x02000800L, 0x00080002L,
0x02080800L, 0x00080000L, 0x00000802L, 0x02000800L,
0x02080002L, 0x00000800L, 0x00080800L, 0x02000002L,
0x00080802L, 0x00000002L, 0x02000002L, 0x02080000L,
0x02080802L, 0x00080800L, 0x02080000L, 0x02000802L,
0x02000000L, 0x00000802L, 0x00080002L, 0x00000000L,
0x00080000L, 0x02000000L, 0x02000802L, 0x02080800L,
0x00000002L, 0x02080002L, 0x00000800L, 0x00080802L,
},{
/* nibble 1 */
0x10042004L, 0x00000000L, 0x00042000L, 0x10040000L,
0x10000004L, 0x00002004L, 0x10002000L, 0x00042000L,
0x00002000L, 0x10040004L, 0x00000004L, 0x10002000L,
0x00040004L, 0x10042000L, 0x10040000L, 0x00000004L,
0x00040000L, 0x10002004L, 0x10040004L, 0x00002000L,
0x00042004L, 0x10000000L, 0x00000000L, 0x00040004L,
0x10002004L, 0x00042004L, 0x10042000L, 0x10000004L,
0x10000000L, 0x00040000L, 0x00002004L, 0x10042004L,
0x00040004L, 0x10042000L, 0x10002000L, 0x00042004L,
0x10042004L, 0x00040004L, 0x10000004L, 0x00000000L,
0x10000000L, 0x00002004L, 0x00040000L, 0x10040004L,
0x00002000L, 0x10000000L, 0x00042004L, 0x10002004L,
0x10042000L, 0x00002000L, 0x00000000L, 0x10000004L,
0x00000004L, 0x10042004L, 0x00042000L, 0x10040000L,
0x10040004L, 0x00040000L, 0x00002004L, 0x10002000L,
0x10002004L, 0x00000004L, 0x10040000L, 0x00042000L,
0x40108010L, 0x00000000L, 0x00108000L, 0x40100000L,
0x40000010L, 0x00008010L, 0x40008000L, 0x00108000L,
0x00008000L, 0x40100010L, 0x00000010L, 0x40008000L,
0x00100010L, 0x40108000L, 0x40100000L, 0x00000010L,
0x00100000L, 0x40008010L, 0x40100010L, 0x00008000L,
0x00108010L, 0x40000000L, 0x00000000L, 0x00100010L,
0x40008010L, 0x00108010L, 0x40108000L, 0x40000010L,
0x40000000L, 0x00100000L, 0x00008010L, 0x40108010L,
0x00100010L, 0x40108000L, 0x40008000L, 0x00108010L,
0x40108010L, 0x00100010L, 0x40000010L, 0x00000000L,
0x40000000L, 0x00008010L, 0x00100000L, 0x40100010L,
0x00008000L, 0x40000000L, 0x00108010L, 0x40008010L,
0x40108000L, 0x00008000L, 0x00000000L, 0x40000010L,
0x00000010L, 0x40108010L, 0x00108000L, 0x40100000L,
0x40100010L, 0x00100000L, 0x00008010L, 0x40008000L,
0x40008010L, 0x00000010L, 0x40100000L, 0x00108000L,
},{
/* nibble 2 */
0x41000000L, 0x01010040L, 0x00000040L, 0x41000040L,
0x40010000L, 0x01000000L, 0x41000040L, 0x00010040L,
0x01000040L, 0x00010000L, 0x01010000L, 0x40000000L,
0x41010040L, 0x40000040L, 0x40000000L, 0x41010000L,
0x00000000L, 0x40010000L, 0x01010040L, 0x00000040L,
0x40000040L, 0x41010040L, 0x00010000L, 0x41000000L,
0x41010000L, 0x01000040L, 0x40010040L, 0x01010000L,
0x00010040L, 0x00000000L, 0x01000000L, 0x40010040L,
0x01010040L, 0x00000040L, 0x40000000L, 0x00010000L,
0x40000040L, 0x40010000L, 0x01010000L, 0x41000040L,
0x00000000L, 0x01010040L, 0x00010040L, 0x41010000L,
0x40010000L, 0x01000000L, 0x41010040L, 0x40000000L,
0x40010040L, 0x41000000L, 0x01000000L, 0x41010040L,
0x00010000L, 0x01000040L, 0x41000040L, 0x00010040L,
0x01000040L, 0x00000000L, 0x41010000L, 0x40000040L,
0x41000000L, 0x40010040L, 0x00000040L, 0x01010000L,
0x04000001L, 0x04040100L, 0x00000100L, 0x04000101L,
0x00040001L, 0x04000000L, 0x04000101L, 0x00040100L,
0x04000100L, 0x00040000L, 0x04040000L, 0x00000001L,
0x04040101L, 0x00000101L, 0x00000001L, 0x04040001L,
0x00000000L, 0x00040001L, 0x04040100L, 0x00000100L,
0x00000101L, 0x04040101L, 0x00040000L, 0x04000001L,
0x04040001L, 0x04000100L, 0x00040101L, 0x04040000L,
0x00040100L, 0x00000000L, 0x04000000L, 0x00040101L,
0x04040100L, 0x00000100L, 0x00000001L, 0x00040000L,
0x00000101L, 0x00040001L, 0x04040000L, 0x04000101L,
0x00000000L, 0x04040100L, 0x00040100L, 0x04040001L,
0x00040001L, 0x04000000L, 0x04040101L, 0x00000001L,
0x00040101L, 0x04000001L, 0x04000000L, 0x04040101L,
0x00040000L, 0x04000100L, 0x04000101L, 0x00040100L,
0x04000100L, 0x00000000L, 0x04040001L, 0x00000101L,
0x04000001L, 0x00040101L, 0x00000100L, 0x04040000L,
},{
/* nibble 3 */
0x00100402L, 0x04000400L, 0x00000002L, 0x04100402L,
0x00000000L, 0x04100000L, 0x04000402L, 0x00100002L,
0x04100400L, 0x04000002L, 0x04000000L, 0x00000402L,
0x04000002L, 0x00100402L, 0x00100000L, 0x04000000L,
0x04100002L, 0x00100400L, 0x00000400L, 0x00000002L,
0x00100400L, 0x04000402L, 0x04100000L, 0x00000400L,
0x00000402L, 0x00000000L, 0x00100002L, 0x04100400L,
0x04000400L, 0x04100002L, 0x04100402L, 0x00100000L,
0x04100002L, 0x00000402L, 0x00100000L, 0x04000002L,
0x00100400L, 0x04000400L, 0x00000002L, 0x04100000L,
0x04000402L, 0x00000000L, 0x00000400L, 0x00100002L,
0x00000000L, 0x04100002L, 0x04100400L, 0x00000400L,
0x04000000L, 0x04100402L, 0x00100402L, 0x00100000L,
0x04100402L, 0x00000002L, 0x04000400L, 0x00100402L,
0x00100002L, 0x00100400L, 0x04100000L, 0x04000402L,
0x00000402L, 0x04000000L, 0x04000002L, 0x04100400L,
0x00401008L, 0x10001000L, 0x00000008L, 0x10401008L,
0x00000000L, 0x10400000L, 0x10001008L, 0x00400008L,
0x10401000L, 0x10000008L, 0x10000000L, 0x00001008L,
0x10000008L, 0x00401008L, 0x00400000L, 0x10000000L,
0x10400008L, 0x00401000L, 0x00001000L, 0x00000008L,
0x00401000L, 0x10001008L, 0x10400000L, 0x00001000L,
0x00001008L, 0x00000000L, 0x00400008L, 0x10401000L,
0x10001000L, 0x10400008L, 0x10401008L, 0x00400000L,
0x10400008L, 0x00001008L, 0x00400000L, 0x10000008L,
0x00401000L, 0x10001000L, 0x00000008L, 0x10400000L,
0x10001008L, 0x00000000L, 0x00001000L, 0x00400008L,
0x00000000L, 0x10400008L, 0x10401000L, 0x00001000L,
0x10000000L, 0x10401008L, 0x00401008L, 0x00400000L,
0x10401008L, 0x00000008L, 0x10001000L, 0x00401008L,
0x00400008L, 0x00401000L, 0x10400000L, 0x10001008L,
0x00001008L, 0x10000000L, 0x10000008L, 0x10401000L,
},{
/* nibble 4 */
0x02000000L, 0x00004000L, 0x00000100L, 0x02004108L,
0x02004008L, 0x02000100L, 0x00004108L, 0x02004000L,
0x00004000L, 0x00000008L, 0x02000008L, 0x00004100L,
0x02000108L, 0x02004008L, 0x02004100L, 0x00000000L,
0x00004100L, 0x02000000L, 0x00004008L, 0x00000108L,
0x02000100L, 0x00004108L, 0x00000000L, 0x02000008L,
0x00000008L, 0x02000108L, 0x02004108L, 0x00004008L,
0x02004000L, 0x00000100L, 0x00000108L, 0x02004100L,
0x02004100L, 0x02000108L, 0x00004008L, 0x02004000L,
0x00004000L, 0x00000008L, 0x02000008L, 0x02000100L,
0x02000000L, 0x00004100L, 0x02004108L, 0x00000000L,
0x00004108L, 0x02000000L, 0x00000100L, 0x00004008L,
0x02000108L, 0x00000100L, 0x00000000L, 0x02004108L,
0x02004008L, 0x02004100L, 0x00000108L, 0x00004000L,
0x00004100L, 0x02004008L, 0x02000100L, 0x00000108L,
0x00000008L, 0x00004108L, 0x02004000L, 0x02000008L,
0x08000000L, 0x00010000L, 0x00000400L, 0x08010420L,
0x08010020L, 0x08000400L, 0x00010420L, 0x08010000L,
0x00010000L, 0x00000020L, 0x08000020L, 0x00010400L,
0x08000420L, 0x08010020L, 0x08010400L, 0x00000000L,
0x00010400L, 0x08000000L, 0x00010020L, 0x00000420L,
0x08000400L, 0x00010420L, 0x00000000L, 0x08000020L,
0x00000020L, 0x08000420L, 0x08010420L, 0x00010020L,
0x08010000L, 0x00000400L, 0x00000420L, 0x08010400L,
0x08010400L, 0x08000420L, 0x00010020L, 0x08010000L,
0x00010000L, 0x00000020L, 0x08000020L, 0x08000400L,
0x08000000L, 0x00010400L, 0x08010420L, 0x00000000L,
0x00010420L, 0x08000000L, 0x00000400L, 0x00010020L,
0x08000420L, 0x00000400L, 0x00000000L, 0x08010420L,
0x08010020L, 0x08010400L, 0x00000420L, 0x00010000L,
0x00010400L, 0x08010020L, 0x08000400L, 0x00000420L,
0x00000020L, 0x00010420L, 0x08010000L, 0x08000020L,
},{
/* nibble 5 */
0x20000010L, 0x00080010L, 0x00000000L, 0x20080800L,
0x00080010L, 0x00000800L, 0x20000810L, 0x00080000L,
0x00000810L, 0x20080810L, 0x00080800L, 0x20000000L,
0x20000800L, 0x20000010L, 0x20080000L, 0x00080810L,
0x00080000L, 0x20000810L, 0x20080010L, 0x00000000L,
0x00000800L, 0x00000010L, 0x20080800L, 0x20080010L,
0x20080810L, 0x20080000L, 0x20000000L, 0x00000810L,
0x00000010L, 0x00080800L, 0x00080810L, 0x20000800L,
0x00000810L, 0x20000000L, 0x20000800L, 0x00080810L,
0x20080800L, 0x00080010L, 0x00000000L, 0x20000800L,
0x20000000L, 0x00000800L, 0x20080010L, 0x00080000L,
0x00080010L, 0x20080810L, 0x00080800L, 0x00000010L,
0x20080810L, 0x00080800L, 0x00080000L, 0x20000810L,
0x20000010L, 0x20080000L, 0x00080810L, 0x00000000L,
0x00000800L, 0x20000010L, 0x20000810L, 0x20080800L,
0x20080000L, 0x00000810L, 0x00000010L, 0x20080010L,
0x80000040L, 0x00200040L, 0x00000000L, 0x80202000L,
0x00200040L, 0x00002000L, 0x80002040L, 0x00200000L,
0x00002040L, 0x80202040L, 0x00202000L, 0x80000000L,
0x80002000L, 0x80000040L, 0x80200000L, 0x00202040L,
0x00200000L, 0x80002040L, 0x80200040L, 0x00000000L,
0x00002000L, 0x00000040L, 0x80202000L, 0x80200040L,
0x80202040L, 0x80200000L, 0x80000000L, 0x00002040L,
0x00000040L, 0x00202000L, 0x00202040L, 0x80002000L,
0x00002040L, 0x80000000L, 0x80002000L, 0x00202040L,
0x80202000L, 0x00200040L, 0x00000000L, 0x80002000L,
0x80000000L, 0x00002000L, 0x80200040L, 0x00200000L,
0x00200040L, 0x80202040L, 0x00202000L, 0x00000040L,
0x80202040L, 0x00202000L, 0x00200000L, 0x80002040L,
0x80000040L, 0x80200000L, 0x00202040L, 0x00000000L,
0x00002000L, 0x80000040L, 0x80002040L, 0x80202000L,
0x80200000L, 0x00002040L, 0x00000040L, 0x80200040L,
},{
/* nibble 6 */
0x00001000L, 0x00000080L, 0x00400080L, 0x00400001L,
0x00401081L, 0x00001001L, 0x00001080L, 0x00000000L,
0x00400000L, 0x00400081L, 0x00000081L, 0x00401000L,
0x00000001L, 0x00401080L, 0x00401000L, 0x00000081L,
0x00400081L, 0x00001000L, 0x00001001L, 0x00401081L,
0x00000000L, 0x00400080L, 0x00400001L, 0x00001080L,
0x00401001L, 0x00001081L, 0x00401080L, 0x00000001L,
0x00001081L, 0x00401001L, 0x00000080L, 0x00400000L,
0x00001081L, 0x00401000L, 0x00401001L, 0x00000081L,
0x00001000L, 0x00000080L, 0x00400000L, 0x00401001L,
0x00400081L, 0x00001081L, 0x00001080L, 0x00000000L,
0x00000080L, 0x00400001L, 0x00000001L, 0x00400080L,
0x00000000L, 0x00400081L, 0x00400080L, 0x00001080L,
0x00000081L, 0x00001000L, 0x00401081L, 0x00400000L,
0x00401080L, 0x00000001L, 0x00001001L, 0x00401081L,
0x00400001L, 0x00401080L, 0x00401000L, 0x00001001L,
0x00004000L, 0x00000200L, 0x01000200L, 0x01000004L,
0x01004204L, 0x00004004L, 0x00004200L, 0x00000000L,
0x01000000L, 0x01000204L, 0x00000204L, 0x01004000L,
0x00000004L, 0x01004200L, 0x01004000L, 0x00000204L,
0x01000204L, 0x00004000L, 0x00004004L, 0x01004204L,
0x00000000L, 0x01000200L, 0x01000004L, 0x00004200L,
0x01004004L, 0x00004204L, 0x01004200L, 0x00000004L,
0x00004204L, 0x01004004L, 0x00000200L, 0x01000000L,
0x00004204L, 0x01004000L, 0x01004004L, 0x00000204L,
0x00004000L, 0x00000200L, 0x01000000L, 0x01004004L,
0x01000204L, 0x00004204L, 0x00004200L, 0x00000000L,
0x00000200L, 0x01000004L, 0x00000004L, 0x01000200L,
0x00000000L, 0x01000204L, 0x01000200L, 0x00004200L,
0x00000204L, 0x00004000L, 0x01004204L, 0x01000000L,
0x01004200L, 0x00000004L, 0x00004004L, 0x01004204L,
0x01000004L, 0x01004200L, 0x01004000L, 0x00004004L,
},{
/* nibble 7 */
0x08200020L, 0x08208000L, 0x00008020L, 0x00000000L,
0x08008000L, 0x00200020L, 0x08200000L, 0x08208020L,
0x00000020L, 0x08000000L, 0x00208000L, 0x00008020L,
0x00208020L, 0x08008020L, 0x08000020L, 0x08200000L,
0x00008000L, 0x00208020L, 0x00200020L, 0x08008000L,
0x08208020L, 0x08000020L, 0x00000000L, 0x00208000L,
0x08000000L, 0x00200000L, 0x08008020L, 0x08200020L,
0x00200000L, 0x00008000L, 0x08208000L, 0x00000020L,
0x00200000L, 0x00008000L, 0x08000020L, 0x08208020L,
0x00008020L, 0x08000000L, 0x00000000L, 0x00208000L,
0x08200020L, 0x08008020L, 0x08008000L, 0x00200020L,
0x08208000L, 0x00000020L, 0x00200020L, 0x08008000L,
0x08208020L, 0x00200000L, 0x08200000L, 0x08000020L,
0x00208000L, 0x00008020L, 0x08008020L, 0x08200000L,
0x00000020L, 0x08208000L, 0x00208020L, 0x00000000L,
0x08000000L, 0x08200020L, 0x00008000L, 0x00208020L,
0x20800080L, 0x20820000L, 0x00020080L, 0x00000000L,
0x20020000L, 0x00800080L, 0x20800000L, 0x20820080L,
0x00000080L, 0x20000000L, 0x00820000L, 0x00020080L,
0x00820080L, 0x20020080L, 0x20000080L, 0x20800000L,
0x00020000L, 0x00820080L, 0x00800080L, 0x20020000L,
0x20820080L, 0x20000080L, 0x00000000L, 0x00820000L,
0x20000000L, 0x00800000L, 0x20020080L, 0x20800080L,
0x00800000L, 0x00020000L, 0x20820000L, 0x00000080L,
0x00800000L, 0x00020000L, 0x20000080L, 0x20820080L,
0x00020080L, 0x20000000L, 0x00000000L, 0x00820000L,
0x20800080L, 0x20020080L, 0x20020000L, 0x00800080L,
0x20820000L, 0x00000080L, 0x00800080L, 0x20020000L,
0x20820080L, 0x00800000L, 0x20800000L, 0x20000080L,
0x00820000L, 0x00020080L, 0x20020080L, 0x20800000L,
0x00000080L, 0x20820000L, 0x00820080L, 0x00000000L,
0x20000000L, 0x20800080L, 0x00020000L, 0x00820080L,
}};

View File

@ -1,4 +1,4 @@
/* $NetBSD: esp_core.c,v 1.14 2000/11/02 12:28:45 itojun Exp $ */
/* $NetBSD: esp_core.c,v 1.15 2001/09/09 11:00:59 tls Exp $ */
/* $KAME: esp_core.c,v 1.50 2000/11/02 12:27:38 itojun Exp $ */
/*
@ -586,9 +586,8 @@ esp_3des_blockdecrypt(algo, sav, s, d)
/* assumption: d has a good alignment */
p = (des_key_schedule *)sav->sched;
bcopy(s, d, sizeof(DES_LONG) * 2);
des_ecb_encrypt((des_cblock *)d, (des_cblock *)d, p[2], DES_DECRYPT);
des_ecb_encrypt((des_cblock *)d, (des_cblock *)d, p[1], DES_ENCRYPT);
des_ecb_encrypt((des_cblock *)d, (des_cblock *)d, p[0], DES_DECRYPT);
des_ecb3_encrypt((des_cblock *)d, (des_cblock *)d,
p[0], p[1], p[2], DES_DECRYPT);
return 0;
}
@ -604,9 +603,8 @@ esp_3des_blockencrypt(algo, sav, s, d)
/* assumption: d has a good alignment */
p = (des_key_schedule *)sav->sched;
bcopy(s, d, sizeof(DES_LONG) * 2);
des_ecb_encrypt((des_cblock *)d, (des_cblock *)d, p[0], DES_ENCRYPT);
des_ecb_encrypt((des_cblock *)d, (des_cblock *)d, p[1], DES_DECRYPT);
des_ecb_encrypt((des_cblock *)d, (des_cblock *)d, p[2], DES_ENCRYPT);
des_ecb3_encrypt((des_cblock *)d, (des_cblock *)d,
p[0],p[1],p[2], DES_ENCRYPT);
return 0;
}