Skip to content

Commit 614d502

Browse files
committed
chacha20poly1305: use x/sys/cpu feature variables directly
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent aabede6 commit 614d502

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

chacha20poly1305/chacha20poly1305_amd64.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ func chacha20Poly1305Open(dst []byte, key []uint32, src, ad []byte) bool
2020
func chacha20Poly1305Seal(dst []byte, key []uint32, src, ad []byte)
2121

2222
var (
23-
useASM = cpu.X86.HasSSSE3
2423
useAVX2 = cpu.X86.HasAVX2 && cpu.X86.HasBMI2
2524
)
2625

@@ -48,7 +47,7 @@ func setupState(state *[16]uint32, key *[8]uint32, nonce []byte) {
4847
}
4948

5049
func (c *chacha20poly1305) seal(dst, nonce, plaintext, additionalData []byte) []byte {
51-
if !useASM {
50+
if !cpu.X86.HasSSSE3 {
5251
return c.sealGeneric(dst, nonce, plaintext, additionalData)
5352
}
5453

@@ -64,7 +63,7 @@ func (c *chacha20poly1305) seal(dst, nonce, plaintext, additionalData []byte) []
6463
}
6564

6665
func (c *chacha20poly1305) open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) {
67-
if !useASM {
66+
if !cpu.X86.HasSSSE3 {
6867
return c.openGeneric(dst, nonce, ciphertext, additionalData)
6968
}
7069

0 commit comments

Comments
 (0)