Source-Changes-HG archive

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

[src/trunk]: src/sys Add asm versions of blowfish and des transforms for i386.



details:   https://anonhg.NetBSD.org/src/rev/6af2f1cd81a0
branches:  trunk
changeset: 514714:6af2f1cd81a0
user:      tls <tls%NetBSD.org@localhost>
date:      Sun Sep 09 11:00:59 2001 +0000

description:
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.

diffstat:

 sys/arch/i386/conf/files.i386              |     7 +-
 sys/arch/i386/conf/std.i386                |     8 +-
 sys/conf/files                             |     7 +-
 sys/crypto/blowfish/arch/i386/bf_cbc.S     |   279 ++
 sys/crypto/blowfish/arch/i386/bf_enc.S     |    16 +
 sys/crypto/blowfish/arch/i386/bf_enc_586.S |   760 +++++++
 sys/crypto/blowfish/arch/i386/bf_enc_686.S |   732 +++++++
 sys/crypto/blowfish/bf_enc.c               |    13 +-
 sys/crypto/blowfish/blowfish.h             |     5 +-
 sys/crypto/des/arch/i386/des_cbc.S         |   437 ++++
 sys/crypto/des/arch/i386/des_enc.S         |  2813 ++++++++++++++++++++++++++++
 sys/crypto/des/des.h                       |    40 +-
 sys/crypto/des/des_ecb.c                   |   236 +-
 sys/crypto/des/des_locl.h                  |   221 +-
 sys/crypto/des/des_setkey.c                |   142 +-
 sys/crypto/des/spr.h                       |   300 +-
 sys/netinet6/esp_core.c                    |    12 +-
 17 files changed, 5560 insertions(+), 468 deletions(-)

diffs (truncated from 6381 to 300 lines):

diff -r fa986bf75497 -r 6af2f1cd81a0 sys/arch/i386/conf/files.i386
--- a/sys/arch/i386/conf/files.i386     Sun Sep 09 10:48:34 2001 +0000
+++ b/sys/arch/i386/conf/files.i386     Sun Sep 09 11:00:59 2001 +0000
@@ -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   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
 #
diff -r fa986bf75497 -r 6af2f1cd81a0 sys/arch/i386/conf/std.i386
--- a/sys/arch/i386/conf/std.i386       Sun Sep 09 10:48:34 2001 +0000
+++ b/sys/arch/i386/conf/std.i386       Sun Sep 09 11:00:59 2001 +0000
@@ -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_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
diff -r fa986bf75497 -r 6af2f1cd81a0 sys/conf/files
--- a/sys/conf/files    Sun Sep 09 10:48:34 2001 +0000
+++ b/sys/conf/files    Sun Sep 09 11:00:59 2001 +0000
@@ -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   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
diff -r fa986bf75497 -r 6af2f1cd81a0 sys/crypto/blowfish/arch/i386/bf_cbc.S
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/crypto/blowfish/arch/i386/bf_cbc.S    Sun Sep 09 11:00:59 2001 +0000
@@ -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@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 bf-686.pl elf' by 
+ * Thor Lancelot Simon <tls%netbsd.org@localhost>
+ */
+
+#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)



Home | Main Index | Thread Index | Old Index