Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libcrypto/arch/i386 Add assembly versions of DES transfo...



details:   https://anonhg.NetBSD.org/src/rev/b9b7efedd671
branches:  trunk
changeset: 514711:b9b7efedd671
user:      tls <tls%NetBSD.org@localhost>
date:      Sun Sep 09 10:44:24 2001 +0000

description:
Add assembly versions of DES transforms for x86; a performance improvement
of about 3.5X on my 1333MHz Athlon (about 37MB/sec!) compared to the old
C versions.

We could boost the speed of the C versions on most other architectures with
des.inc files that set the compile-time flags (DES_PTR, DES_RISC1, DES_RISC2)
correctly; at the moment they aren't set at all.

diffstat:

 lib/libcrypto/arch/i386/des.inc    |    19 +
 lib/libcrypto/arch/i386/des_enc.S  |  2575 ++++++++++++++++++++++++++++++++++++
 lib/libcrypto/arch/i386/des_enc3.c |   222 +++
 3 files changed, 2816 insertions(+), 0 deletions(-)

diffs (truncated from 2828 to 300 lines):

diff -r ed108e19f7bd -r b9b7efedd671 lib/libcrypto/arch/i386/des.inc
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libcrypto/arch/i386/des.inc   Sun Sep 09 10:44:24 2001 +0000
@@ -0,0 +1,19 @@
+#      $NetBSD: des.inc,v 1.1 2001/09/09 10:44:24 tls Exp $
+#
+#      @(#) Copyright (c) 1995 Simon J. Gerraty
+#
+#
+
+.PATH: ${OPENSSLSRC}/crypto/des
+.PATH: ${.CURDIR}/arch/i386
+
+CPPFLAGS+=     -I${OPENSSLSRC}/crypto/des
+CPPFLAGS+=     -I${.CURDIR}/arch/i386
+
+SRCS+= cbc_cksm.c cbc_enc.c  cfb64enc.c cfb_enc.c  \
+       ecb3_enc.c ecb_enc.c  enc_read.c enc_writ.c \
+       fcrypt.c ofb64enc.c ofb_enc.c  pcbc_enc.c \
+       qud_cksm.c rand_key.c read_pwd.c rpc_enc.c  set_key.c  \
+       des_enc.S des_enc3.c fcrypt_b.c read2pwd.c \
+       xcbc_enc.c \
+       str2key.c  cfb64ede.c ofb64ede.c ede_cbcm_enc.c
diff -r ed108e19f7bd -r b9b7efedd671 lib/libcrypto/arch/i386/des_enc.S
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libcrypto/arch/i386/des_enc.S Sun Sep 09 10:44:24 2001 +0000
@@ -0,0 +1,2575 @@
+/* $NetBSD: des_enc.S,v 1.1 2001/09/09 10:44:24 tls Exp $ */
+
+/* Copyright (C) 1995-1997 Eric Young (eay%cryptsoft.com@localhost)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay%cryptsoft.com@localhost).
+ * 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@localhost).
+ *
+ * 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@localhost)"
+ *    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@localhost)"
+ *
+ * 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@localhost>
+ */
+
+#include <machine/asm.h>
+
+ENTRY(des_encrypt1)
+       pushl   %esi
+       pushl   %edi
+
+       # Load the 2 words 
+       movl    12(%esp),       %esi
+       xorl    %ecx,           %ecx
+       pushl   %ebx
+       pushl   %ebp
+       movl    (%esi),         %eax
+       movl    28(%esp),       %ebx
+       movl    4(%esi),        %edi
+
+       # IP 
+       roll    $4,             %eax
+       movl    %eax,           %esi
+       xorl    %edi,           %eax
+       andl    $0xf0f0f0f0,    %eax
+       xorl    %eax,           %esi
+       xorl    %eax,           %edi
+
+       roll    $20,            %edi
+       movl    %edi,           %eax
+       xorl    %esi,           %edi
+       andl    $0xfff0000f,    %edi
+       xorl    %edi,           %eax
+       xorl    %edi,           %esi
+
+       roll    $14,            %eax
+       movl    %eax,           %edi
+       xorl    %esi,           %eax
+       andl    $0x33333333,    %eax
+       xorl    %eax,           %edi
+       xorl    %eax,           %esi
+
+       roll    $22,            %esi
+       movl    %esi,           %eax
+       xorl    %edi,           %esi
+       andl    $0x03fc03fc,    %esi
+       xorl    %esi,           %eax
+       xorl    %esi,           %edi
+
+       roll    $9,             %eax
+       movl    %eax,           %esi
+       xorl    %edi,           %eax
+       andl    $0xaaaaaaaa,    %eax
+       xorl    %eax,           %esi
+       xorl    %eax,           %edi
+
+.byte 209
+.byte 199              # roll $1 %edi 
+       movl    24(%esp),       %ebp
+       cmpl    $0,             %ebx
+       je      .L000start_decrypt
+
+       # Round 0 
+       movl    (%ebp),         %eax
+       xorl    %ebx,           %ebx
+       movl    4(%ebp),        %edx
+       xorl    %esi,           %eax
+       xorl    %esi,           %edx
+       andl    $0xfcfcfcfc,    %eax
+       andl    $0xcfcfcfcf,    %edx
+       movb    %al,            %bl
+       movb    %ah,            %cl
+       rorl    $4,             %edx
+       movl          _C_LABEL(des_SPtrans)(%ebx),%ebp
+       movb    %dl,            %bl
+       xorl    %ebp,           %edi
+       movl    0x200+_C_LABEL(des_SPtrans)(%ecx),%ebp
+       xorl    %ebp,           %edi
+       movb    %dh,            %cl
+       shrl    $16,            %eax
+       movl    0x100+_C_LABEL(des_SPtrans)(%ebx),%ebp
+       xorl    %ebp,           %edi
+       movb    %ah,            %bl
+       shrl    $16,            %edx
+       movl    0x300+_C_LABEL(des_SPtrans)(%ecx),%ebp
+       xorl    %ebp,           %edi
+       movl    24(%esp),       %ebp
+       movb    %dh,            %cl
+       andl    $0xff,          %eax
+       andl    $0xff,          %edx
+       movl    0x600+_C_LABEL(des_SPtrans)(%ebx),%ebx
+       xorl    %ebx,           %edi
+       movl    0x700+_C_LABEL(des_SPtrans)(%ecx),%ebx
+       xorl    %ebx,           %edi
+       movl    0x400+_C_LABEL(des_SPtrans)(%eax),%ebx
+       xorl    %ebx,           %edi
+       movl    0x500+_C_LABEL(des_SPtrans)(%edx),%ebx
+       xorl    %ebx,           %edi
+
+       # Round 1 
+       movl    8(%ebp),        %eax
+       xorl    %ebx,           %ebx
+       movl    12(%ebp),       %edx
+       xorl    %edi,           %eax
+       xorl    %edi,           %edx
+       andl    $0xfcfcfcfc,    %eax
+       andl    $0xcfcfcfcf,    %edx
+       movb    %al,            %bl
+       movb    %ah,            %cl
+       rorl    $4,             %edx
+       movl          _C_LABEL(des_SPtrans)(%ebx),%ebp
+       movb    %dl,            %bl
+       xorl    %ebp,           %esi
+       movl    0x200+_C_LABEL(des_SPtrans)(%ecx),%ebp
+       xorl    %ebp,           %esi
+       movb    %dh,            %cl
+       shrl    $16,            %eax
+       movl    0x100+_C_LABEL(des_SPtrans)(%ebx),%ebp
+       xorl    %ebp,           %esi
+       movb    %ah,            %bl
+       shrl    $16,            %edx
+       movl    0x300+_C_LABEL(des_SPtrans)(%ecx),%ebp
+       xorl    %ebp,           %esi
+       movl    24(%esp),       %ebp
+       movb    %dh,            %cl
+       andl    $0xff,          %eax
+       andl    $0xff,          %edx
+       movl    0x600+_C_LABEL(des_SPtrans)(%ebx),%ebx
+       xorl    %ebx,           %esi
+       movl    0x700+_C_LABEL(des_SPtrans)(%ecx),%ebx
+       xorl    %ebx,           %esi
+       movl    0x400+_C_LABEL(des_SPtrans)(%eax),%ebx
+       xorl    %ebx,           %esi
+       movl    0x500+_C_LABEL(des_SPtrans)(%edx),%ebx
+       xorl    %ebx,           %esi
+
+       # Round 2 
+       movl    16(%ebp),       %eax
+       xorl    %ebx,           %ebx
+       movl    20(%ebp),       %edx
+       xorl    %esi,           %eax
+       xorl    %esi,           %edx
+       andl    $0xfcfcfcfc,    %eax
+       andl    $0xcfcfcfcf,    %edx
+       movb    %al,            %bl
+       movb    %ah,            %cl
+       rorl    $4,             %edx
+       movl          _C_LABEL(des_SPtrans)(%ebx),%ebp
+       movb    %dl,            %bl
+       xorl    %ebp,           %edi
+       movl    0x200+_C_LABEL(des_SPtrans)(%ecx),%ebp
+       xorl    %ebp,           %edi
+       movb    %dh,            %cl
+       shrl    $16,            %eax
+       movl    0x100+_C_LABEL(des_SPtrans)(%ebx),%ebp
+       xorl    %ebp,           %edi
+       movb    %ah,            %bl
+       shrl    $16,            %edx
+       movl    0x300+_C_LABEL(des_SPtrans)(%ecx),%ebp
+       xorl    %ebp,           %edi
+       movl    24(%esp),       %ebp
+       movb    %dh,            %cl
+       andl    $0xff,          %eax
+       andl    $0xff,          %edx
+       movl    0x600+_C_LABEL(des_SPtrans)(%ebx),%ebx
+       xorl    %ebx,           %edi
+       movl    0x700+_C_LABEL(des_SPtrans)(%ecx),%ebx
+       xorl    %ebx,           %edi
+       movl    0x400+_C_LABEL(des_SPtrans)(%eax),%ebx
+       xorl    %ebx,           %edi
+       movl    0x500+_C_LABEL(des_SPtrans)(%edx),%ebx
+       xorl    %ebx,           %edi
+
+       # Round 3 
+       movl    24(%ebp),       %eax
+       xorl    %ebx,           %ebx
+       movl    28(%ebp),       %edx
+       xorl    %edi,           %eax
+       xorl    %edi,           %edx
+       andl    $0xfcfcfcfc,    %eax
+       andl    $0xcfcfcfcf,    %edx
+       movb    %al,            %bl
+       movb    %ah,            %cl
+       rorl    $4,             %edx
+       movl          _C_LABEL(des_SPtrans)(%ebx),%ebp
+       movb    %dl,            %bl
+       xorl    %ebp,           %esi
+       movl    0x200+_C_LABEL(des_SPtrans)(%ecx),%ebp
+       xorl    %ebp,           %esi
+       movb    %dh,            %cl
+       shrl    $16,            %eax
+       movl    0x100+_C_LABEL(des_SPtrans)(%ebx),%ebp
+       xorl    %ebp,           %esi
+       movb    %ah,            %bl
+       shrl    $16,            %edx
+       movl    0x300+_C_LABEL(des_SPtrans)(%ecx),%ebp
+       xorl    %ebp,           %esi
+       movl    24(%esp),       %ebp
+       movb    %dh,            %cl
+       andl    $0xff,          %eax
+       andl    $0xff,          %edx
+       movl    0x600+_C_LABEL(des_SPtrans)(%ebx),%ebx
+       xorl    %ebx,           %esi
+       movl    0x700+_C_LABEL(des_SPtrans)(%ecx),%ebx
+       xorl    %ebx,           %esi
+       movl    0x400+_C_LABEL(des_SPtrans)(%eax),%ebx
+       xorl    %ebx,           %esi
+       movl    0x500+_C_LABEL(des_SPtrans)(%edx),%ebx
+       xorl    %ebx,           %esi
+
+       # Round 4 
+       movl    32(%ebp),       %eax
+       xorl    %ebx,           %ebx
+       movl    36(%ebp),       %edx



Home | Main Index | Thread Index | Old Index