@@ -12,6 +12,8 @@ package sha3
1212
1313import (
1414 "hash"
15+
16+ "golang.org/x/sys/cpu"
1517)
1618
1719// codes represent 7-bit KIMD/KLMD function codes as defined in
@@ -29,13 +31,6 @@ const (
2931 nopad = 0x100
3032)
3133
32- // hasMSA6 reports whether the machine supports the SHA-3 and SHAKE function
33- // codes, as defined in message-security-assist extension 6.
34- func hasMSA6 () bool
35-
36- // hasAsm caches the result of hasMSA6 (which might be expensive to call).
37- var hasAsm = hasMSA6 ()
38-
3934// kimd is a wrapper for the 'compute intermediate message digest' instruction.
4035// src must be a multiple of the rate for the given function code.
4136//go:noescape
@@ -237,7 +232,7 @@ func (s *asmState) Clone() ShakeHash {
237232// new224Asm returns an assembly implementation of SHA3-224 if available,
238233// otherwise it returns nil.
239234func new224Asm () hash.Hash {
240- if hasAsm {
235+ if cpu . S390X . HasSHA3 {
241236 return newAsmState (sha3_224 )
242237 }
243238 return nil
@@ -246,7 +241,7 @@ func new224Asm() hash.Hash {
246241// new256Asm returns an assembly implementation of SHA3-256 if available,
247242// otherwise it returns nil.
248243func new256Asm () hash.Hash {
249- if hasAsm {
244+ if cpu . S390X . HasSHA3 {
250245 return newAsmState (sha3_256 )
251246 }
252247 return nil
@@ -255,7 +250,7 @@ func new256Asm() hash.Hash {
255250// new384Asm returns an assembly implementation of SHA3-384 if available,
256251// otherwise it returns nil.
257252func new384Asm () hash.Hash {
258- if hasAsm {
253+ if cpu . S390X . HasSHA3 {
259254 return newAsmState (sha3_384 )
260255 }
261256 return nil
@@ -264,7 +259,7 @@ func new384Asm() hash.Hash {
264259// new512Asm returns an assembly implementation of SHA3-512 if available,
265260// otherwise it returns nil.
266261func new512Asm () hash.Hash {
267- if hasAsm {
262+ if cpu . S390X . HasSHA3 {
268263 return newAsmState (sha3_512 )
269264 }
270265 return nil
@@ -273,7 +268,7 @@ func new512Asm() hash.Hash {
273268// newShake128Asm returns an assembly implementation of SHAKE-128 if available,
274269// otherwise it returns nil.
275270func newShake128Asm () ShakeHash {
276- if hasAsm {
271+ if cpu . S390X . HasSHA3 {
277272 return newAsmState (shake_128 )
278273 }
279274 return nil
@@ -282,7 +277,7 @@ func newShake128Asm() ShakeHash {
282277// newShake256Asm returns an assembly implementation of SHAKE-256 if available,
283278// otherwise it returns nil.
284279func newShake256Asm () ShakeHash {
285- if hasAsm {
280+ if cpu . S390X . HasSHA3 {
286281 return newAsmState (shake_256 )
287282 }
288283 return nil
0 commit comments