From 614d502a4dac94afa3a6ce146bd1736da82514c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Sat, 28 Jul 2018 10:01:47 +0200 Subject: [PATCH] chacha20poly1305: use x/sys/cpu feature variables directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid using package specific variables when there is a one to one correspondance to cpu feature support exported by internal/cpu. This makes it clearer which cpu feature is referenced. Another advantage is that internal/cpu variables are padded to avoid false sharing and memory and cache usage is shared by multiple packages. Change-Id: Ieadfc2f2f65f83f947aa8a5efc869aa85d89615d Reviewed-on: https://go-review.googlesource.com/126597 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- chacha20poly1305/chacha20poly1305_amd64.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/chacha20poly1305/chacha20poly1305_amd64.go b/chacha20poly1305/chacha20poly1305_amd64.go index ec13d13..2aa4fd8 100644 --- a/chacha20poly1305/chacha20poly1305_amd64.go +++ b/chacha20poly1305/chacha20poly1305_amd64.go @@ -20,7 +20,6 @@ func chacha20Poly1305Open(dst []byte, key []uint32, src, ad []byte) bool func chacha20Poly1305Seal(dst []byte, key []uint32, src, ad []byte) var ( - useASM = cpu.X86.HasSSSE3 useAVX2 = cpu.X86.HasAVX2 && cpu.X86.HasBMI2 ) @@ -48,7 +47,7 @@ func setupState(state *[16]uint32, key *[8]uint32, nonce []byte) { } func (c *chacha20poly1305) seal(dst, nonce, plaintext, additionalData []byte) []byte { - if !useASM { + if !cpu.X86.HasSSSE3 { return c.sealGeneric(dst, nonce, plaintext, additionalData) } @@ -64,7 +63,7 @@ func (c *chacha20poly1305) seal(dst, nonce, plaintext, additionalData []byte) [] } func (c *chacha20poly1305) open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) { - if !useASM { + if !cpu.X86.HasSSSE3 { return c.openGeneric(dst, nonce, ciphertext, additionalData) }