@@ -12,6 +12,8 @@ package sha3
12
12
13
13
import (
14
14
"hash"
15
+
16
+ "golang.org/x/sys/cpu"
15
17
)
16
18
17
19
// codes represent 7-bit KIMD/KLMD function codes as defined in
@@ -29,13 +31,6 @@ const (
29
31
nopad = 0x100
30
32
)
31
33
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
-
39
34
// kimd is a wrapper for the 'compute intermediate message digest' instruction.
40
35
// src must be a multiple of the rate for the given function code.
41
36
//go:noescape
@@ -237,7 +232,7 @@ func (s *asmState) Clone() ShakeHash {
237
232
// new224Asm returns an assembly implementation of SHA3-224 if available,
238
233
// otherwise it returns nil.
239
234
func new224Asm () hash.Hash {
240
- if hasAsm {
235
+ if cpu . S390X . HasSHA3 {
241
236
return newAsmState (sha3_224 )
242
237
}
243
238
return nil
@@ -246,7 +241,7 @@ func new224Asm() hash.Hash {
246
241
// new256Asm returns an assembly implementation of SHA3-256 if available,
247
242
// otherwise it returns nil.
248
243
func new256Asm () hash.Hash {
249
- if hasAsm {
244
+ if cpu . S390X . HasSHA3 {
250
245
return newAsmState (sha3_256 )
251
246
}
252
247
return nil
@@ -255,7 +250,7 @@ func new256Asm() hash.Hash {
255
250
// new384Asm returns an assembly implementation of SHA3-384 if available,
256
251
// otherwise it returns nil.
257
252
func new384Asm () hash.Hash {
258
- if hasAsm {
253
+ if cpu . S390X . HasSHA3 {
259
254
return newAsmState (sha3_384 )
260
255
}
261
256
return nil
@@ -264,7 +259,7 @@ func new384Asm() hash.Hash {
264
259
// new512Asm returns an assembly implementation of SHA3-512 if available,
265
260
// otherwise it returns nil.
266
261
func new512Asm () hash.Hash {
267
- if hasAsm {
262
+ if cpu . S390X . HasSHA3 {
268
263
return newAsmState (sha3_512 )
269
264
}
270
265
return nil
@@ -273,7 +268,7 @@ func new512Asm() hash.Hash {
273
268
// newShake128Asm returns an assembly implementation of SHAKE-128 if available,
274
269
// otherwise it returns nil.
275
270
func newShake128Asm () ShakeHash {
276
- if hasAsm {
271
+ if cpu . S390X . HasSHA3 {
277
272
return newAsmState (shake_128 )
278
273
}
279
274
return nil
@@ -282,7 +277,7 @@ func newShake128Asm() ShakeHash {
282
277
// newShake256Asm returns an assembly implementation of SHAKE-256 if available,
283
278
// otherwise it returns nil.
284
279
func newShake256Asm () ShakeHash {
285
- if hasAsm {
280
+ if cpu . S390X . HasSHA3 {
286
281
return newAsmState (shake_256 )
287
282
}
288
283
return nil
0 commit comments