]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Align _gnutls_x86_cpuid_s as OPENSSL_ia32cap_P would be
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Mon, 29 Apr 2019 13:28:28 +0000 (15:28 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 27 Jun 2019 04:45:36 +0000 (06:45 +0200)
We were not setting the third array member correctly, though
this didn't have any impact to previous implementations as they
did not rely on it. This also moves away from the custom implementation
of cpuid (which was limited), and we now rely on the compiler's
version.

This effectively enables support for SHA_NI.

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
21 files changed:
NEWS
cfg.mk
devel/perlasm/cpuid-x86.pl [deleted file]
devel/perlasm/cpuid-x86.pl.license [deleted symlink]
devel/perlasm/cpuid-x86_64.pl [deleted file]
devel/perlasm/cpuid-x86_64.pl.license [deleted symlink]
doc/cha-gtls-app.texi
lib/accelerated/accelerated.c
lib/accelerated/x86/coff/cpuid-x86.s [deleted file]
lib/accelerated/x86/coff/cpuid-x86_64.s [deleted file]
lib/accelerated/x86/elf/cpuid-x86.s [deleted file]
lib/accelerated/x86/elf/cpuid-x86_64.s [deleted file]
lib/accelerated/x86/files.mk
lib/accelerated/x86/hmac-x86-ssse3.c
lib/accelerated/x86/macosx/cpuid-x86.s [deleted file]
lib/accelerated/x86/macosx/cpuid-x86_64.s [deleted file]
lib/accelerated/x86/sha-x86-ssse3.c
lib/accelerated/x86/x86-common.c
lib/accelerated/x86/x86-common.h
tests/slow/test-ciphers-common.sh
tests/slow/test-hash-large.sh

diff --git a/NEWS b/NEWS
index cf5b1277600c8c8844f8a6fd58b148e6de9391ce..0be861954065de70cb87ab1b777bafc1be378b23 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -38,6 +38,9 @@ See the end for copying conditions.
    of digest or MAC context. Copying contexts for externally-registered digest and MAC
    contexts is unupported.
 
+** libgnutls: Added new flag for GNUTLS_CPUID_OVERRIDE
+  0x20: Enable SHA_NI instruction set
+
 ** API and ABI modifications:
 gnutls_get_system_config_file: Added
 gnutls_crypto_register_cipher: Deprecated
diff --git a/cfg.mk b/cfg.mk
index f7ae6408fd42d58499e41f110a68fc839b29d568..ff79dbf2ed2f91e839f3919b1ca297e5a7ac7c89 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -130,8 +130,6 @@ ASM_SOURCES_XXX := \
        lib/accelerated/aarch64/XXX/sha1-armv8.s \
        lib/accelerated/aarch64/XXX/sha256-armv8.s \
        lib/accelerated/aarch64/XXX/sha512-armv8.s \
-       lib/accelerated/x86/XXX/cpuid-x86_64.s \
-       lib/accelerated/x86/XXX/cpuid-x86.s \
        lib/accelerated/x86/XXX/ghash-x86_64.s \
        lib/accelerated/x86/XXX/aesni-x86_64.s \
        lib/accelerated/x86/XXX/aesni-x86.s \
@@ -154,10 +152,10 @@ asm-sources: $(ASM_SOURCES_ELF) $(ASM_SOURCES_COFF) $(ASM_SOURCES_MACOSX) lib/ac
 asm-sources-clean:
        rm -f $(ASM_SOURCES_ELF) $(ASM_SOURCES_COFF) $(ASM_SOURCES_MACOSX) lib/accelerated/x86/files.mk
 
-X86_FILES=XXX/aesni-x86.s XXX/cpuid-x86.s XXX/sha1-ssse3-x86.s \
+X86_FILES=XXX/aesni-x86.s XXX/sha1-ssse3-x86.s \
        XXX/sha256-ssse3-x86.s XXX/sha512-ssse3-x86.s XXX/aes-ssse3-x86.s
 
-X86_64_FILES=XXX/aesni-x86_64.s XXX/cpuid-x86_64.s XXX/ghash-x86_64.s \
+X86_64_FILES=XXX/aesni-x86_64.s XXX/ghash-x86_64.s \
        XXX/sha1-ssse3-x86_64.s XXX/sha512-ssse3-x86_64.s XXX/aes-ssse3-x86_64.s \
        XXX/aesni-gcm-x86_64.s XXX/sha256-ssse3-x86_64.s
 
diff --git a/devel/perlasm/cpuid-x86.pl b/devel/perlasm/cpuid-x86.pl
deleted file mode 100644 (file)
index a5541d4..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/perl
-#
-# ====================================================================
-# Written by Nikos Mavrogiannopoulos
-# Placed under the LGPL
-# ====================================================================
-#
-
-$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
-push(@INC,"${dir}","${dir}../../crypto/perlasm");
-require "x86asm.pl";
-
-$output=pop;
-open STDOUT,">$output";
-
-&asm_init($ARGV[0],$0);
-
-&function_begin_B("gnutls_cpuid");
-       &push   ("ebp");
-       &mov    ("ebp", "esp");
-       &sub    ("esp", 12);
-       &mov    (&DWP(0,"esp"), "ebx");
-       &mov    ("eax",&DWP(8,"ebp"));
-       &mov    (&DWP(4,"esp"), "esi");
-       &mov    (&DWP(8,"esp"), "edi");
-       &push   ("ebx");
-       &cpuid  ();
-       &mov    ("edi", "ebx");
-       &pop    ("ebx");
-       &mov    ("esi","edx");
-       &mov    ("edx",&DWP(12,"ebp"));
-       &mov    (&DWP(0,"edx"), "eax");
-       &mov    ("eax",&DWP(16,"ebp"));
-       &mov    (&DWP(0,"eax"), "edi");
-       &mov    ("eax",&DWP(20,"ebp"));
-       &mov    (&DWP(0,"eax"), "ecx");
-       &mov    ("eax",&DWP(24,"ebp"));
-       &mov    (&DWP(0,"eax"), "esi");
-       &mov    ("ebx",&DWP(0,"esp"));
-       &mov    ("esi",&DWP(4,"esp"));
-       &mov    ("edi",&DWP(8,"esp"));
-       &mov    ("esp","ebp");
-       &pop    ("ebp");
-       &ret    ();
-&function_end_B("gnutls_cpuid");
-
-&function_begin_B("gnutls_have_cpuid");
-       &pushf  ();
-       &pop    ("eax");
-       &or     ("eax",0x200000);
-       &push   ("eax");
-       &popf   ();
-       &pushf  ();
-       &pop    ("eax");
-       &and     ("eax",0x200000);
-       &ret    ();
-&function_end_B("gnutls_have_cpuid");
-
-&asciz("CPUID for x86");
-&asm_finish();
-
-close STDOUT;
diff --git a/devel/perlasm/cpuid-x86.pl.license b/devel/perlasm/cpuid-x86.pl.license
deleted file mode 120000 (symlink)
index 6879a72..0000000
+++ /dev/null
@@ -1 +0,0 @@
-license-gnutls.txt
\ No newline at end of file
diff --git a/devel/perlasm/cpuid-x86_64.pl b/devel/perlasm/cpuid-x86_64.pl
deleted file mode 100644 (file)
index a6bb30e..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/usr/bin/env perl
-#
-# ====================================================================
-# Written by Nikos Mavrogiannopoulos
-# Based on e_padlock-x86_64
-# ====================================================================
-#
-
-$flavour = shift;
-$output  = shift;
-if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
-
-$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
-
-$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
-( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
-( $xlate="${dir}../../crypto/perlasm/x86_64-xlate.pl" and -f $xlate) or
-die "can't locate x86_64-xlate.pl";
-
-open STDOUT,"| $^X $xlate $flavour $output";
-
-$code=".text\n";
-
-($arg1,$arg2,$arg3,$arg4)=$win64?("%rcx","%rdx","%r8", "%r9") : # Win64 order
-                                 ("%rdi","%rsi","%rdx","%rcx"); # Unix order
-
-
-$code.=<<___;
-.globl gnutls_cpuid
-.type gnutls_cpuid,\@function
-.align 16
-gnutls_cpuid:
-       pushq   %rbp
-       movq    %rsp, %rbp
-       pushq   %rbx
-       movl    %edi, -12(%rbp)
-       movq    %rsi, -24(%rbp)
-       movq    %rdx, -32(%rbp)
-       movq    %rcx, -40(%rbp)
-       movq    %r8, -48(%rbp)
-       movl    -12(%rbp), %eax
-       movl    %eax, -60(%rbp)
-       movl    -60(%rbp), %eax
-       cpuid
-       movl    %edx, -56(%rbp)
-       movl    %ecx, %esi
-       movl    %eax, -52(%rbp)
-       movq    -24(%rbp), %rax
-       movl    -52(%rbp), %edx
-       movl    %edx, (%rax)
-       movq    -32(%rbp), %rax
-       movl    %ebx, (%rax)
-       movq    -40(%rbp), %rax
-       movl    %esi, (%rax)
-       movq    -48(%rbp), %rax
-       movl    -56(%rbp), %ecx
-       movl    %ecx, (%rax)
-       popq    %rbx
-       leave
-       ret
-.size gnutls_cpuid,.-gnutls_cpuid
-___
-
-$code =~ s/\`([^\`]*)\`/eval($1)/gem;
-
-print $code;
-
-close STDOUT;
-
diff --git a/devel/perlasm/cpuid-x86_64.pl.license b/devel/perlasm/cpuid-x86_64.pl.license
deleted file mode 120000 (symlink)
index 6879a72..0000000
+++ /dev/null
@@ -1 +0,0 @@
-license-gnutls.txt
\ No newline at end of file
index 66875af222aa676e9a56c9cb8a115d5027e312d1..4a6a53811b4ee19f8f8c230a42a26bb36715a22e 100644 (file)
@@ -199,6 +199,7 @@ CPU. The currently available options are:
 @item 0x4: Enable SSSE3
 @item 0x8: Enable PCLMUL
 @item 0x10: Enable AVX
+@item 0x20: Enable SHA_NI
 @item 0x100000: Enable VIA padlock
 @item 0x200000: Enable VIA PHE
 @item 0x400000: Enable VIA PHE SHA512
index 2d8f546b2336a58f04ae384e23e0da47b9f39d58..8fb0b11f6572edc0d7fdbfe6afffa0cd173c6e00 100644 (file)
@@ -32,9 +32,7 @@
 void _gnutls_register_accel_crypto(void)
 {
 #if defined(ASM_X86)
-       if (gnutls_have_cpuid() != 0) {
-               register_x86_crypto();
-       }
+       register_x86_crypto();
 #endif
 
 #if defined(ASM_AARCH64)
diff --git a/lib/accelerated/x86/coff/cpuid-x86.s b/lib/accelerated/x86/coff/cpuid-x86.s
deleted file mode 100644 (file)
index 610e961..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-#
-# Copyright (C) 2011-2013 Free Software Foundation, Inc.
-# Copyright (C) 2013 Nikos Mavrogiannopoulos
-#
-# Author: Nikos Mavrogiannopoulos
-#
-# This file is part of GnuTLS.
-#
-# The GnuTLS is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public License
-# as published by the Free Software Foundation; either version 2.1 of
-# the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-#
-# *** This file is auto-generated ***
-#
-.text
-.globl _gnutls_cpuid
-.def   _gnutls_cpuid;  .scl    2;      .type   32;     .endef
-.align 16
-_gnutls_cpuid:
-.L_gnutls_cpuid_begin:
-       pushl   %ebp
-       movl    %esp,%ebp
-       subl    $12,%esp
-       movl    %ebx,(%esp)
-       movl    8(%ebp),%eax
-       movl    %esi,4(%esp)
-       movl    %edi,8(%esp)
-       pushl   %ebx
-       .byte   0x0f,0xa2
-       movl    %ebx,%edi
-       popl    %ebx
-       movl    %edx,%esi
-       movl    12(%ebp),%edx
-       movl    %eax,(%edx)
-       movl    16(%ebp),%eax
-       movl    %edi,(%eax)
-       movl    20(%ebp),%eax
-       movl    %ecx,(%eax)
-       movl    24(%ebp),%eax
-       movl    %esi,(%eax)
-       movl    (%esp),%ebx
-       movl    4(%esp),%esi
-       movl    8(%esp),%edi
-       movl    %ebp,%esp
-       popl    %ebp
-       ret
-.globl _gnutls_have_cpuid
-.def   _gnutls_have_cpuid;     .scl    2;      .type   32;     .endef
-.align 16
-_gnutls_have_cpuid:
-.L_gnutls_have_cpuid_begin:
-       pushfl
-       popl    %eax
-       orl     $2097152,%eax
-       pushl   %eax
-       popfl
-       pushfl
-       popl    %eax
-       andl    $2097152,%eax
-       ret
-.byte  67,80,85,73,68,32,102,111,114,32,120,56,54,0
-
diff --git a/lib/accelerated/x86/coff/cpuid-x86_64.s b/lib/accelerated/x86/coff/cpuid-x86_64.s
deleted file mode 100644 (file)
index cd28c7b..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-#
-# Copyright (C) 2011-2013 Free Software Foundation, Inc.
-# Copyright (C) 2013 Nikos Mavrogiannopoulos
-#
-# Author: Nikos Mavrogiannopoulos
-#
-# This file is part of GnuTLS.
-#
-# The GnuTLS is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public License
-# as published by the Free Software Foundation; either version 2.1 of
-# the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-#
-# *** This file is auto-generated ***
-#
-.text  
-.globl gnutls_cpuid
-.def   gnutls_cpuid;   .scl 2; .type 32;       .endef
-.p2align       4
-gnutls_cpuid:
-       movq    %rdi,8(%rsp)
-       movq    %rsi,16(%rsp)
-       movq    %rsp,%rax
-.LSEH_begin_gnutls_cpuid:
-       movq    %rcx,%rdi
-       movq    %rdx,%rsi
-       movq    %r8,%rdx
-       movq    %r9,%rcx
-       movq    40(%rsp),%r8
-       movq    48(%rsp),%r9
-
-       pushq   %rbp
-       movq    %rsp,%rbp
-       pushq   %rbx
-       movl    %edi,-12(%rbp)
-       movq    %rsi,-24(%rbp)
-       movq    %rdx,-32(%rbp)
-       movq    %rcx,-40(%rbp)
-       movq    %r8,-48(%rbp)
-       movl    -12(%rbp),%eax
-       movl    %eax,-60(%rbp)
-       movl    -60(%rbp),%eax
-       cpuid
-       movl    %edx,-56(%rbp)
-       movl    %ecx,%esi
-       movl    %eax,-52(%rbp)
-       movq    -24(%rbp),%rax
-       movl    -52(%rbp),%edx
-       movl    %edx,(%rax)
-       movq    -32(%rbp),%rax
-       movl    %ebx,(%rax)
-       movq    -40(%rbp),%rax
-       movl    %esi,(%rax)
-       movq    -48(%rbp),%rax
-       movl    -56(%rbp),%ecx
-       movl    %ecx,(%rax)
-       popq    %rbx
-       leave
-       movq    8(%rsp),%rdi
-       movq    16(%rsp),%rsi
-       .byte   0xf3,0xc3
-.LSEH_end_gnutls_cpuid:
-
diff --git a/lib/accelerated/x86/elf/cpuid-x86.s b/lib/accelerated/x86/elf/cpuid-x86.s
deleted file mode 100644 (file)
index 4427b6b..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#
-# Copyright (C) 2011-2013 Free Software Foundation, Inc.
-# Copyright (C) 2013 Nikos Mavrogiannopoulos
-#
-# Author: Nikos Mavrogiannopoulos
-#
-# This file is part of GnuTLS.
-#
-# The GnuTLS is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public License
-# as published by the Free Software Foundation; either version 2.1 of
-# the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-#
-# *** This file is auto-generated ***
-#
-.text
-.globl gnutls_cpuid
-.type  gnutls_cpuid,@function
-.align 16
-gnutls_cpuid:
-.L_gnutls_cpuid_begin:
-       pushl   %ebp
-       movl    %esp,%ebp
-       subl    $12,%esp
-       movl    %ebx,(%esp)
-       movl    8(%ebp),%eax
-       movl    %esi,4(%esp)
-       movl    %edi,8(%esp)
-       pushl   %ebx
-       .byte   0x0f,0xa2
-       movl    %ebx,%edi
-       popl    %ebx
-       movl    %edx,%esi
-       movl    12(%ebp),%edx
-       movl    %eax,(%edx)
-       movl    16(%ebp),%eax
-       movl    %edi,(%eax)
-       movl    20(%ebp),%eax
-       movl    %ecx,(%eax)
-       movl    24(%ebp),%eax
-       movl    %esi,(%eax)
-       movl    (%esp),%ebx
-       movl    4(%esp),%esi
-       movl    8(%esp),%edi
-       movl    %ebp,%esp
-       popl    %ebp
-       ret
-.size  gnutls_cpuid,.-.L_gnutls_cpuid_begin
-.globl gnutls_have_cpuid
-.type  gnutls_have_cpuid,@function
-.align 16
-gnutls_have_cpuid:
-.L_gnutls_have_cpuid_begin:
-       pushfl
-       popl    %eax
-       orl     $2097152,%eax
-       pushl   %eax
-       popfl
-       pushfl
-       popl    %eax
-       andl    $2097152,%eax
-       ret
-.size  gnutls_have_cpuid,.-.L_gnutls_have_cpuid_begin
-.byte  67,80,85,73,68,32,102,111,114,32,120,56,54,0
-
-.section .note.GNU-stack,"",%progbits
diff --git a/lib/accelerated/x86/elf/cpuid-x86_64.s b/lib/accelerated/x86/elf/cpuid-x86_64.s
deleted file mode 100644 (file)
index 0740edc..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#
-# Copyright (C) 2011-2013 Free Software Foundation, Inc.
-# Copyright (C) 2013 Nikos Mavrogiannopoulos
-#
-# Author: Nikos Mavrogiannopoulos
-#
-# This file is part of GnuTLS.
-#
-# The GnuTLS is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public License
-# as published by the Free Software Foundation; either version 2.1 of
-# the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-#
-# *** This file is auto-generated ***
-#
-.text  
-.globl gnutls_cpuid
-.type  gnutls_cpuid,@function
-.align 16
-gnutls_cpuid:
-       pushq   %rbp
-       movq    %rsp,%rbp
-       pushq   %rbx
-       movl    %edi,-12(%rbp)
-       movq    %rsi,-24(%rbp)
-       movq    %rdx,-32(%rbp)
-       movq    %rcx,-40(%rbp)
-       movq    %r8,-48(%rbp)
-       movl    -12(%rbp),%eax
-       movl    %eax,-60(%rbp)
-       movl    -60(%rbp),%eax
-       cpuid
-       movl    %edx,-56(%rbp)
-       movl    %ecx,%esi
-       movl    %eax,-52(%rbp)
-       movq    -24(%rbp),%rax
-       movl    -52(%rbp),%edx
-       movl    %edx,(%rax)
-       movq    -32(%rbp),%rax
-       movl    %ebx,(%rax)
-       movq    -40(%rbp),%rax
-       movl    %esi,(%rax)
-       movq    -48(%rbp),%rax
-       movl    -56(%rbp),%ecx
-       movl    %ecx,(%rax)
-       popq    %rbx
-       leave
-       .byte   0xf3,0xc3
-.size  gnutls_cpuid,.-gnutls_cpuid
-
-.section .note.GNU-stack,"",%progbits
index cf688b3883f0136cde173fc656b67a56e6273214..ac1f2b05bd646a3d4c207e9b93a2df6eb9c885d4 100644 (file)
@@ -1,9 +1,9 @@
-X86_FILES_ELF=elf/aesni-x86.s elf/cpuid-x86.s elf/sha1-ssse3-x86.s elf/sha256-ssse3-x86.s elf/sha512-ssse3-x86.s elf/aes-ssse3-x86.s
-X86_FILES_COFF=coff/aesni-x86.s coff/cpuid-x86.s coff/sha1-ssse3-x86.s coff/sha256-ssse3-x86.s coff/sha512-ssse3-x86.s coff/aes-ssse3-x86.s
-X86_FILES_MACOSX=macosx/aesni-x86.s macosx/cpuid-x86.s macosx/sha1-ssse3-x86.s macosx/sha256-ssse3-x86.s macosx/sha512-ssse3-x86.s macosx/aes-ssse3-x86.s
-X86_64_FILES_ELF=elf/aesni-x86_64.s elf/cpuid-x86_64.s elf/ghash-x86_64.s elf/sha1-ssse3-x86_64.s elf/sha512-ssse3-x86_64.s elf/aes-ssse3-x86_64.s elf/aesni-gcm-x86_64.s elf/sha256-ssse3-x86_64.s
-X86_64_FILES_COFF=coff/aesni-x86_64.s coff/cpuid-x86_64.s coff/ghash-x86_64.s coff/sha1-ssse3-x86_64.s coff/sha512-ssse3-x86_64.s coff/aes-ssse3-x86_64.s coff/aesni-gcm-x86_64.s coff/sha256-ssse3-x86_64.s
-X86_64_FILES_MACOSX=macosx/aesni-x86_64.s macosx/cpuid-x86_64.s macosx/ghash-x86_64.s macosx/sha1-ssse3-x86_64.s macosx/sha512-ssse3-x86_64.s macosx/aes-ssse3-x86_64.s macosx/aesni-gcm-x86_64.s macosx/sha256-ssse3-x86_64.s
+X86_FILES_ELF=elf/aesni-x86.s elf/sha1-ssse3-x86.s elf/sha256-ssse3-x86.s elf/sha512-ssse3-x86.s elf/aes-ssse3-x86.s
+X86_FILES_COFF=coff/aesni-x86.s coff/sha1-ssse3-x86.s coff/sha256-ssse3-x86.s coff/sha512-ssse3-x86.s coff/aes-ssse3-x86.s
+X86_FILES_MACOSX=macosx/aesni-x86.s macosx/sha1-ssse3-x86.s macosx/sha256-ssse3-x86.s macosx/sha512-ssse3-x86.s macosx/aes-ssse3-x86.s
+X86_64_FILES_ELF=elf/aesni-x86_64.s elf/ghash-x86_64.s elf/sha1-ssse3-x86_64.s elf/sha512-ssse3-x86_64.s elf/aes-ssse3-x86_64.s elf/aesni-gcm-x86_64.s elf/sha256-ssse3-x86_64.s
+X86_64_FILES_COFF=coff/aesni-x86_64.s coff/ghash-x86_64.s coff/sha1-ssse3-x86_64.s coff/sha512-ssse3-x86_64.s coff/aes-ssse3-x86_64.s coff/aesni-gcm-x86_64.s coff/sha256-ssse3-x86_64.s
+X86_64_FILES_MACOSX=macosx/aesni-x86_64.s macosx/ghash-x86_64.s macosx/sha1-ssse3-x86_64.s macosx/sha512-ssse3-x86_64.s macosx/aes-ssse3-x86_64.s macosx/aesni-gcm-x86_64.s macosx/sha256-ssse3-x86_64.s
 X86_PADLOCK_FILES_ELF=elf/e_padlock-x86.s
 X86_PADLOCK_FILES_COFF=coff/e_padlock-x86.s
 X86_PADLOCK_FILES_MACOSX=macosx/e_padlock-x86.s
index 5a4677b405c1e2469c0738a4bc270f8179d8c2b7..f4ead02c473c499b89d3951cc3148761ef82b439 100644 (file)
@@ -45,10 +45,8 @@ struct x86_hmac_ctx {
                struct hmac_sha1_ctx sha1;
                struct hmac_sha224_ctx sha224;
                struct hmac_sha256_ctx sha256;
-#ifdef ENABLE_SHA512
                struct hmac_sha384_ctx sha384;
                struct hmac_sha512_ctx sha512;
-#endif
        } ctx;
 
        void *ctx_ptr;
@@ -115,7 +113,6 @@ x86_hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
        HMAC_DIGEST(ctx, &x86_sha224, length, digest);
 }
 
-#ifdef ENABLE_SHA512
 static void
 x86_hmac_sha384_set_key(struct hmac_sha384_ctx *ctx,
                            size_t key_length, const uint8_t * key)
@@ -150,7 +147,6 @@ x86_hmac_sha512_digest(struct hmac_sha512_ctx *ctx,
 {
        HMAC_DIGEST(ctx, &x86_sha512, length, digest);
 }
-#endif
 
 static int
 _hmac_ctx_init(gnutls_mac_algorithm_t algo, struct x86_hmac_ctx *ctx)
@@ -177,7 +173,6 @@ _hmac_ctx_init(gnutls_mac_algorithm_t algo, struct x86_hmac_ctx *ctx)
                ctx->ctx_ptr = &ctx->ctx.sha256;
                ctx->length = SHA256_DIGEST_SIZE;
                break;
-#ifdef ENABLE_SHA512
        case GNUTLS_MAC_SHA384:
                ctx->update = (update_func) x86_hmac_sha512_update;
                ctx->digest = (digest_func) x86_hmac_sha384_digest;
@@ -192,7 +187,6 @@ _hmac_ctx_init(gnutls_mac_algorithm_t algo, struct x86_hmac_ctx *ctx)
                ctx->ctx_ptr = &ctx->ctx.sha512;
                ctx->length = SHA512_DIGEST_SIZE;
                break;
-#endif
        default:
                gnutls_assert();
                return GNUTLS_E_INVALID_REQUEST;
diff --git a/lib/accelerated/x86/macosx/cpuid-x86.s b/lib/accelerated/x86/macosx/cpuid-x86.s
deleted file mode 100644 (file)
index bd8e443..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-#
-# Copyright (C) 2011-2013 Free Software Foundation, Inc.
-# Copyright (C) 2013 Nikos Mavrogiannopoulos
-#
-# Author: Nikos Mavrogiannopoulos
-#
-# This file is part of GnuTLS.
-#
-# The GnuTLS is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public License
-# as published by the Free Software Foundation; either version 2.1 of
-# the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-#
-# *** This file is auto-generated ***
-#
-.text
-.globl _gnutls_cpuid
-.align 4
-_gnutls_cpuid:
-L_gnutls_cpuid_begin:
-       pushl   %ebp
-       movl    %esp,%ebp
-       subl    $12,%esp
-       movl    %ebx,(%esp)
-       movl    8(%ebp),%eax
-       movl    %esi,4(%esp)
-       movl    %edi,8(%esp)
-       pushl   %ebx
-       .byte   0x0f,0xa2
-       movl    %ebx,%edi
-       popl    %ebx
-       movl    %edx,%esi
-       movl    12(%ebp),%edx
-       movl    %eax,(%edx)
-       movl    16(%ebp),%eax
-       movl    %edi,(%eax)
-       movl    20(%ebp),%eax
-       movl    %ecx,(%eax)
-       movl    24(%ebp),%eax
-       movl    %esi,(%eax)
-       movl    (%esp),%ebx
-       movl    4(%esp),%esi
-       movl    8(%esp),%edi
-       movl    %ebp,%esp
-       popl    %ebp
-       ret
-.globl _gnutls_have_cpuid
-.align 4
-_gnutls_have_cpuid:
-L_gnutls_have_cpuid_begin:
-       pushfl
-       popl    %eax
-       orl     $2097152,%eax
-       pushl   %eax
-       popfl
-       pushfl
-       popl    %eax
-       andl    $2097152,%eax
-       ret
-.byte  67,80,85,73,68,32,102,111,114,32,120,56,54,0
-
diff --git a/lib/accelerated/x86/macosx/cpuid-x86_64.s b/lib/accelerated/x86/macosx/cpuid-x86_64.s
deleted file mode 100644 (file)
index 05dc5c8..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-#
-# Copyright (C) 2011-2013 Free Software Foundation, Inc.
-# Copyright (C) 2013 Nikos Mavrogiannopoulos
-#
-# Author: Nikos Mavrogiannopoulos
-#
-# This file is part of GnuTLS.
-#
-# The GnuTLS is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public License
-# as published by the Free Software Foundation; either version 2.1 of
-# the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-#
-# *** This file is auto-generated ***
-#
-.text  
-.globl _gnutls_cpuid
-
-.p2align       4
-_gnutls_cpuid:
-       pushq   %rbp
-       movq    %rsp,%rbp
-       pushq   %rbx
-       movl    %edi,-12(%rbp)
-       movq    %rsi,-24(%rbp)
-       movq    %rdx,-32(%rbp)
-       movq    %rcx,-40(%rbp)
-       movq    %r8,-48(%rbp)
-       movl    -12(%rbp),%eax
-       movl    %eax,-60(%rbp)
-       movl    -60(%rbp),%eax
-       cpuid
-       movl    %edx,-56(%rbp)
-       movl    %ecx,%esi
-       movl    %eax,-52(%rbp)
-       movq    -24(%rbp),%rax
-       movl    -52(%rbp),%edx
-       movl    %edx,(%rax)
-       movq    -32(%rbp),%rax
-       movl    %ebx,(%rax)
-       movq    -40(%rbp),%rax
-       movl    %esi,(%rax)
-       movq    -48(%rbp),%rax
-       movl    -56(%rbp),%ecx
-       movl    %ecx,(%rax)
-       popq    %rbx
-       leave
-       .byte   0xf3,0xc3
-
-
index b6393488cf3822274e7bec150133fd9010e8993c..8ea4e54aee7634362b7385379a93352c33776f77 100644 (file)
@@ -45,10 +45,8 @@ struct x86_hash_ctx {
                struct sha1_ctx sha1;
                struct sha224_ctx sha224;
                struct sha256_ctx sha256;
-#ifdef ENABLE_SHA512
                struct sha384_ctx sha384;
                struct sha512_ctx sha512;
-#endif
        } ctx;
        void *ctx_ptr;
        gnutls_digest_algorithm_t algo;
@@ -180,7 +178,6 @@ void x86_sha256_update(struct sha256_ctx *ctx, size_t length,
        }
 }
 
-#ifdef ENABLE_SHA512
 void x86_sha512_update(struct sha512_ctx *ctx, size_t length,
                     const uint8_t * data)
 {
@@ -231,7 +228,6 @@ void x86_sha512_update(struct sha512_ctx *ctx, size_t length,
                sha512_update(ctx, res, data);
        }
 }
-#endif
 
 static int _ctx_init(gnutls_digest_algorithm_t algo,
                     struct x86_hash_ctx *ctx)
@@ -261,7 +257,6 @@ static int _ctx_init(gnutls_digest_algorithm_t algo,
                ctx->ctx_ptr = &ctx->ctx.sha256;
                ctx->length = SHA256_DIGEST_SIZE;
                break;
-#ifdef ENABLE_SHA512
        case GNUTLS_DIG_SHA384:
                sha384_init(&ctx->ctx.sha384);
                ctx->update = (update_func) x86_sha512_update;
@@ -278,7 +273,6 @@ static int _ctx_init(gnutls_digest_algorithm_t algo,
                ctx->ctx_ptr = &ctx->ctx.sha512;
                ctx->length = SHA512_DIGEST_SIZE;
                break;
-#endif
        default:
                gnutls_assert();
                return GNUTLS_E_INVALID_REQUEST;
@@ -368,12 +362,10 @@ NN_HASH(sha224, x86_sha256_update, sha224_digest, SHA224);
 const struct nettle_hash x86_sha256 =
 NN_HASH(sha256, x86_sha256_update, sha256_digest, SHA256);
 
-#ifdef ENABLE_SHA512
 const struct nettle_hash x86_sha384 =
 NN_HASH(sha384, x86_sha512_update, sha384_digest, SHA384);
 const struct nettle_hash x86_sha512 =
 NN_HASH(sha512, x86_sha512_update, sha512_digest, SHA512);
-#endif
 
 const gnutls_crypto_digest_st _gnutls_sha_x86_ssse3 = {
        .init = wrap_x86_hash_init,
index acd4586e4e67139dc681b78b104b9192c5562d6f..fb3ff90919f2f2de63f383bce9b48719f79a741e 100644 (file)
 # include <sha-padlock.h>
 #endif
 #include <aes-padlock.h>
+#ifdef HAVE_CPUID_H
+# include <cpuid.h>
+#else
+# define __get_cpuid(...) 0
+# define __get_cpuid_count(...) 0
+#endif
 
 /* ebx, ecx, edx 
  * This is a format compatible with openssl's CPUID detection.
@@ -49,11 +55,21 @@ __hidden
 #endif
 unsigned int _gnutls_x86_cpuid_s[4];
 
+#ifndef bit_SHA
+# define bit_SHA (1<<29)
+#endif
+
+/* ecx */
+#ifndef bit_AVX512BITALG
+# define bit_AVX512BITALG 0x4000
+#endif
+
 #ifndef bit_PCLMUL
 # define bit_PCLMUL 0x2
 #endif
 
 #ifndef bit_SSSE3
+/* ecx */
 # define bit_SSSE3 0x0000200
 #endif
 
@@ -85,10 +101,26 @@ unsigned int _gnutls_x86_cpuid_s[4];
 #define INTEL_SSSE3 (1<<2)
 #define INTEL_PCLMUL (1<<3)
 #define INTEL_AVX (1<<4)
+#define INTEL_SHA (1<<5)
 #define VIA_PADLOCK (1<<20)
 #define VIA_PADLOCK_PHE (1<<21)
 #define VIA_PADLOCK_PHE_SHA512 (1<<22)
 
+static unsigned read_cpuid_vals(unsigned int vals[4])
+{
+       unsigned t1, t2, t3;
+       if (!__get_cpuid(1, &t1, &vals[0],
+                        &vals[1], &t2))
+               return 0;
+       /* suppress AVX512; it works conditionally on certain CPUs on the original code */
+       vals[1] &= 0xfffff7ff;
+
+       if (!__get_cpuid_count(7, 0, &t1, &vals[2], &t2, &t3))
+               return 0;
+
+       return 1;
+}
+
 /* Based on the example in "How to detect New Instruction support in
  * the 4th generation Intel Core processor family.
  * https://software.intel.com/en-us/articles/how-to-detect-new-instruction-support-in-the-4th-generation-intel-core-processor-family
@@ -111,18 +143,17 @@ static unsigned check_4th_gen_intel_features(unsigned ecx)
 
 static void capabilities_to_intel_cpuid(unsigned capabilities)
 {
-       unsigned a,b,c,t;
-
-       memset(_gnutls_x86_cpuid_s, 0, sizeof(_gnutls_x86_cpuid_s));
+       unsigned a[4];
 
        if (capabilities & EMPTY_SET) {
                return;
        }
 
-       gnutls_cpuid(1, &t, &a, &b, &c);
+       if (!read_cpuid_vals(a))
+               return;
 
        if (capabilities & INTEL_AES_NI) {
-               if (b & bit_AES) {
+               if (a[1] & bit_AES) {
                        _gnutls_x86_cpuid_s[1] |= bit_AES;
                } else {
                        _gnutls_debug_log
@@ -131,7 +162,7 @@ static void capabilities_to_intel_cpuid(unsigned capabilities)
        }
 
        if (capabilities & INTEL_SSSE3) {
-               if (b & bit_SSSE3) {
+               if (a[1] & bit_SSSE3) {
                        _gnutls_x86_cpuid_s[1] |= bit_SSSE3;
                } else {
                        _gnutls_debug_log
@@ -140,7 +171,7 @@ static void capabilities_to_intel_cpuid(unsigned capabilities)
        }
 
        if (capabilities & INTEL_AVX) {
-               if ((b & bit_AVX) && check_4th_gen_intel_features(b)) {
+               if ((a[1] & bit_AVX) && check_4th_gen_intel_features(a[1])) {
                        _gnutls_x86_cpuid_s[1] |= bit_AVX|bit_MOVBE;
                } else {
                        _gnutls_debug_log
@@ -149,7 +180,7 @@ static void capabilities_to_intel_cpuid(unsigned capabilities)
        }
 
        if (capabilities & INTEL_PCLMUL) {
-               if (b & bit_PCLMUL) {
+               if (a[1] & bit_PCLMUL) {
                        _gnutls_x86_cpuid_s[1] |= bit_PCLMUL;
                } else {
                        _gnutls_debug_log
@@ -157,6 +188,14 @@ static void capabilities_to_intel_cpuid(unsigned capabilities)
                }
        }
 
+       if (capabilities & INTEL_SHA) {
+               if (a[2] & bit_SHA) {
+                       _gnutls_x86_cpuid_s[2] |= bit_SHA;
+               } else {
+                       _gnutls_debug_log
+                           ("SHA acceleration requested but not available\n");
+               }
+       }
 }
 
 
@@ -170,6 +209,11 @@ static unsigned check_ssse3(void)
        return (_gnutls_x86_cpuid_s[1] & bit_SSSE3);
 }
 
+static unsigned check_sha(void)
+{
+       return (_gnutls_x86_cpuid_s[2] & bit_SHA);
+}
+
 #ifdef ASM_X86_64
 static unsigned check_avx_movbe(void)
 {
@@ -196,8 +240,8 @@ static unsigned capabilities_to_via_edx(unsigned capabilities)
                return 0;
        }
 
-       gnutls_cpuid(1, &t, &a, &b, &c);
-
+       if (!__get_cpuid(1, &t, &a, &b, &c))
+               return 0;
        if (capabilities & VIA_PADLOCK) {
                if (c & via_bit_PADLOCK) {
                        _gnutls_x86_cpuid_s[2] |= via_bit_PADLOCK;
@@ -265,7 +309,9 @@ static int check_phe_partial(void)
 static unsigned check_via(void)
 {
        unsigned int a, b, c, d;
-       gnutls_cpuid(0, &a, &b, &c, &d);
+
+       if (!__get_cpuid(0, &a, &b, &c, &d))
+               return 0;
 
        if ((memcmp(&b, "Cent", 4) == 0 &&
             memcmp(&d, "aurH", 4) == 0 && memcmp(&c, "auls", 4) == 0)) {
@@ -455,7 +501,9 @@ void register_x86_padlock_crypto(unsigned capabilities)
 static unsigned check_intel_or_amd(void)
 {
        unsigned int a, b, c, d;
-       gnutls_cpuid(0, &a, &b, &c, &d);
+
+       if (!__get_cpuid(0, &a, &b, &c, &d))
+               return 0;
 
        if ((memcmp(&b, "Genu", 4) == 0 &&
             memcmp(&d, "ineI", 4) == 0 &&
@@ -472,14 +520,15 @@ static
 void register_x86_intel_crypto(unsigned capabilities)
 {
        int ret;
-       unsigned t;
+
+       memset(_gnutls_x86_cpuid_s, 0, sizeof(_gnutls_x86_cpuid_s));
 
        if (check_intel_or_amd() == 0)
                return;
 
        if (capabilities == 0) {
-               gnutls_cpuid(1, &t, &_gnutls_x86_cpuid_s[0], 
-                       &_gnutls_x86_cpuid_s[1], &_gnutls_x86_cpuid_s[2]);
+               if (!read_cpuid_vals(_gnutls_x86_cpuid_s))
+                       return;
        } else {
                capabilities_to_intel_cpuid(capabilities);
        }
@@ -523,6 +572,11 @@ void register_x86_intel_crypto(unsigned capabilities)
                if (ret < 0) {
                        gnutls_assert();
                }
+       }
+
+       if (check_sha() || check_ssse3()) {
+               if (check_sha())
+                       _gnutls_debug_log("Intel SHA was detected\n");
 
                ret =
                    gnutls_crypto_single_digest_register(GNUTLS_DIG_SHA1,
@@ -570,7 +624,6 @@ void register_x86_intel_crypto(unsigned capabilities)
                if (ret < 0)
                        gnutls_assert();
 
-#ifdef ENABLE_SHA512
                ret =
                    gnutls_crypto_single_digest_register(GNUTLS_DIG_SHA384,
                                                         80,
@@ -597,7 +650,6 @@ void register_x86_intel_crypto(unsigned capabilities)
                                                         &_gnutls_hmac_sha_x86_ssse3, 0);
                if (ret < 0)
                        gnutls_assert();
-#endif
        }
 
        if (check_optimized_aes()) {
index 0e2d86d51087f1b937285c801b07c03110e562d5..d15786f378c5080133d4d316e47d26a2e0e78eac 100644 (file)
 void gnutls_cpuid(unsigned int func, unsigned int *ax, unsigned int *bx,
                  unsigned int *cx, unsigned int *dx);
 
-# ifdef ASM_X86_32
-unsigned int gnutls_have_cpuid(void);
-# else
-#  define gnutls_have_cpuid() 1
-# endif                                /* ASM_X86_32 */
-
 #endif
 
 #define CHECK_AES_KEYSIZE(s) \
index 52d9d50ea9cab75d8195428d6ca697c53dce90ef..1a76b48ce0eff02c720d10f989200e495650f0cc 100644 (file)
@@ -73,6 +73,17 @@ if test $ret != 0; then
        exit $ret
 fi
 
+#SHANI
+$(which lscpu)|grep Flags|grep sha_ni >/dev/null
+if test $? = 0;then
+       GNUTLS_CPUID_OVERRIDE=0x20 ${PROG}
+       ret=$?
+       if test $ret != 0; then
+               echo "SHANI cipher tests failed"
+               exit $ret
+       fi
+fi
+
 GNUTLS_CPUID_OVERRIDE=0x100000 ${PROG}
 ret=$?
 if test $ret != 0; then
index 944eaa5d8dd18fb70a8798c471e111295ba3186d..754232ec2c5741d234ab9a4f4557ab55f95f4e76 100755 (executable)
@@ -39,21 +39,28 @@ run_test() {
        fi
 }
 
+#0x20: SHA_NI
 #0x4: SSSE3
 #0x1: no optimizations
 #"": default optimizations
 
 SSSE3FLAG=""
+SHANIFLAG=""
 which lscpu >/dev/null 2>&1
 if test $? = 0;then
         $(which lscpu)|grep Architecture|grep x86 >/dev/null
         if test $? = 0;then
                 SSSE3FLAG="0x4"
         fi
+
+        $(which lscpu)|grep Flags|grep sha_ni >/dev/null
+        if test $? = 0;then
+                SHANIFLAG="0x20"
+        fi
 fi
 
 WAITPID=""
-for flags in "" "0x1" ${SSSE3FLAG};do
+for flags in "" "0x1" ${SSSE3FLAG} ${SHANIFLAG};do
        run_test ${flags} &
        WAITPID="${WAITPID} $!"
 done