diff options
Diffstat (limited to 'golang-crypto.patch')
-rw-r--r-- | golang-crypto.patch | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/golang-crypto.patch b/golang-crypto.patch new file mode 100644 index 000000000000..89adda4d81b2 --- /dev/null +++ b/golang-crypto.patch @@ -0,0 +1,131 @@ +From ae8bce0030810cf999bb2b9868ae5c7c58e6343b Mon Sep 17 00:00:00 2001 +From: Andreas Auernhammer <aead@mail.de> +Date: Mon, 30 Apr 2018 19:54:52 +0200 +Subject: [PATCH] crypto/{blake2b,blake2s,argon2,chacha20poly1305}: replace CPU + feature detection + +This change removes package specific CPU-feature detection code and +replaces it with x/sys/cpu. + +Fixes golang/go#24843 + +Change-Id: I150dd7b3aeb8eef428c91f9b1df741ceb8a87a24 +Reviewed-on: https://go-review.googlesource.com/110355 +Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> +TryBot-Result: Gobot Gobot <gobot@golang.org> +Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> +--- + blake2b/blake2bAVX2_amd64.go | 26 ++++----- + blake2b/blake2bAVX2_amd64.s | 12 ----- + blake2b/blake2b_amd64.go | 7 ++- + blake2b/blake2b_amd64.s | 9 ---- + 11 files changed, 41 insertions(+), 182 deletions(-) + +diff --git a/blake2b/blake2bAVX2_amd64.go b/blake2b/blake2bAVX2_amd64.go +index 8c41cf6c7..4d31dd0fd 100644 +--- a/blake2b/blake2bAVX2_amd64.go ++++ b/blake2b/blake2bAVX2_amd64.go +@@ -6,21 +6,14 @@ + + package blake2b + ++import "golang.org/x/sys/cpu" ++ + func init() { +- useAVX2 = supportsAVX2() +- useAVX = supportsAVX() +- useSSE4 = supportsSSE4() ++ useAVX2 = cpu.X86.HasAVX2 ++ useAVX = cpu.X86.HasAVX ++ useSSE4 = cpu.X86.HasSSE41 + } + +-//go:noescape +-func supportsSSE4() bool +- +-//go:noescape +-func supportsAVX() bool +- +-//go:noescape +-func supportsAVX2() bool +- + //go:noescape + func hashBlocksAVX2(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) + +@@ -31,13 +24,14 @@ func hashBlocksAVX(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) + func hashBlocksSSE4(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) + + func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) { +- if useAVX2 { ++ switch { ++ case useAVX2: + hashBlocksAVX2(h, c, flag, blocks) +- } else if useAVX { ++ case useAVX: + hashBlocksAVX(h, c, flag, blocks) +- } else if useSSE4 { ++ case useSSE4: + hashBlocksSSE4(h, c, flag, blocks) +- } else { ++ default: + hashBlocksGeneric(h, c, flag, blocks) + } + } +diff --git a/blake2b/blake2bAVX2_amd64.s b/blake2b/blake2bAVX2_amd64.s +index 784bce6a9..5593b1b3d 100644 +--- a/blake2b/blake2bAVX2_amd64.s ++++ b/blake2b/blake2bAVX2_amd64.s +@@ -748,15 +748,3 @@ noinc: + + MOVQ BP, SP + RET +- +-// func supportsAVX2() bool +-TEXT ·supportsAVX2(SB), 4, $0-1 +- MOVQ runtime·support_avx2(SB), AX +- MOVB AX, ret+0(FP) +- RET +- +-// func supportsAVX() bool +-TEXT ·supportsAVX(SB), 4, $0-1 +- MOVQ runtime·support_avx(SB), AX +- MOVB AX, ret+0(FP) +- RET +diff --git a/blake2b/blake2b_amd64.go b/blake2b/blake2b_amd64.go +index 2ab7c30fc..30e2fcd58 100644 +--- a/blake2b/blake2b_amd64.go ++++ b/blake2b/blake2b_amd64.go +@@ -6,13 +6,12 @@ + + package blake2b + ++import "golang.org/x/sys/cpu" ++ + func init() { +- useSSE4 = supportsSSE4() ++ useSSE4 = cpu.X86.HasSSE41 + } + +-//go:noescape +-func supportsSSE4() bool +- + //go:noescape + func hashBlocksSSE4(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) + +diff --git a/blake2b/blake2b_amd64.s b/blake2b/blake2b_amd64.s +index 64530740b..578e947b3 100644 +--- a/blake2b/blake2b_amd64.s ++++ b/blake2b/blake2b_amd64.s +@@ -279,12 +279,3 @@ noinc: + + MOVQ BP, SP + RET +- +-// func supportsSSE4() bool +-TEXT ·supportsSSE4(SB), 4, $0-1 +- MOVL $1, AX +- CPUID +- SHRL $19, CX // Bit 19 indicates SSE4 support +- ANDL $1, CX // CX != 0 if support SSE4 +- MOVB CX, ret+0(FP) +- RET |