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
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 \
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
+++ /dev/null
-#!/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;
+++ /dev/null
-license-gnutls.txt
\ No newline at end of file
+++ /dev/null
-#!/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;
-
+++ /dev/null
-license-gnutls.txt
\ No newline at end of file
@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
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)
+++ /dev/null
-#
-# 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
-
+++ /dev/null
-#
-# 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:
-
+++ /dev/null
-#
-# 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
+++ /dev/null
-#
-# 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
-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
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;
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)
{
HMAC_DIGEST(ctx, &x86_sha512, length, digest);
}
-#endif
static int
_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;
ctx->ctx_ptr = &ctx->ctx.sha512;
ctx->length = SHA512_DIGEST_SIZE;
break;
-#endif
default:
gnutls_assert();
return GNUTLS_E_INVALID_REQUEST;
+++ /dev/null
-#
-# 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
-
+++ /dev/null
-#
-# 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
-
-
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;
}
}
-#ifdef ENABLE_SHA512
void x86_sha512_update(struct sha512_ctx *ctx, size_t length,
const uint8_t * data)
{
sha512_update(ctx, res, data);
}
}
-#endif
static int _ctx_init(gnutls_digest_algorithm_t algo,
struct x86_hash_ctx *ctx)
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;
ctx->ctx_ptr = &ctx->ctx.sha512;
ctx->length = SHA512_DIGEST_SIZE;
break;
-#endif
default:
gnutls_assert();
return GNUTLS_E_INVALID_REQUEST;
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,
# 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.
#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
#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
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
}
if (capabilities & INTEL_SSSE3) {
- if (b & bit_SSSE3) {
+ if (a[1] & bit_SSSE3) {
_gnutls_x86_cpuid_s[1] |= bit_SSSE3;
} else {
_gnutls_debug_log
}
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
}
if (capabilities & INTEL_PCLMUL) {
- if (b & bit_PCLMUL) {
+ if (a[1] & bit_PCLMUL) {
_gnutls_x86_cpuid_s[1] |= bit_PCLMUL;
} else {
_gnutls_debug_log
}
}
+ 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");
+ }
+ }
}
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)
{
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;
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)) {
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 &&
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);
}
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,
if (ret < 0)
gnutls_assert();
-#ifdef ENABLE_SHA512
ret =
gnutls_crypto_single_digest_register(GNUTLS_DIG_SHA384,
80,
&_gnutls_hmac_sha_x86_ssse3, 0);
if (ret < 0)
gnutls_assert();
-#endif
}
if (check_optimized_aes()) {
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) \
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
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