mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 04:06:18 +08:00
MAGIC - align with golang aes
This commit is contained in:
parent
78fd94a6aa
commit
a5f2479d38
@ -8,6 +8,9 @@ import (
|
|||||||
"golang.org/x/sys/cpu"
|
"golang.org/x/sys/cpu"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var supportsAES = cpu.X86.HasAES
|
||||||
|
var supportsGFMUL = cpu.X86.HasPCLMULQDQ
|
||||||
|
|
||||||
//go:noescape
|
//go:noescape
|
||||||
func encryptBlocksAsm(xk *uint32, dst, src *byte)
|
func encryptBlocksAsm(xk *uint32, dst, src *byte)
|
||||||
|
|
||||||
@ -21,9 +24,6 @@ type sm4CipherAsm struct {
|
|||||||
sm4Cipher
|
sm4Cipher
|
||||||
}
|
}
|
||||||
|
|
||||||
var supportsAES = cpu.X86.HasAES
|
|
||||||
var supportsGFMUL = cpu.X86.HasPCLMULQDQ
|
|
||||||
|
|
||||||
func newCipher(key []byte) (cipher.Block, error) {
|
func newCipher(key []byte) (cipher.Block, error) {
|
||||||
if !supportsAES {
|
if !supportsAES {
|
||||||
return newCipherGeneric(key)
|
return newCipherGeneric(key)
|
||||||
@ -65,3 +65,13 @@ func (c *sm4CipherAsm) Decrypt(dst, src []byte) {
|
|||||||
}
|
}
|
||||||
encryptBlockAsm(&c.dec[0], &dst[0], &src[0])
|
encryptBlockAsm(&c.dec[0], &dst[0], &src[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// expandKey is used by BenchmarkExpand to ensure that the asm implementation
|
||||||
|
// of key expansion is used for the benchmark when it is available.
|
||||||
|
func expandKey(key []byte, enc, dec []uint32) {
|
||||||
|
if supportsAES {
|
||||||
|
expandKeyAsm(&key[0], &ck[0], &enc[0], &dec[0])
|
||||||
|
} else {
|
||||||
|
expandKeyGo(key, enc, dec)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -12,3 +12,9 @@ import "crypto/cipher"
|
|||||||
func newCipher(key []byte) (cipher.Block, error) {
|
func newCipher(key []byte) (cipher.Block, error) {
|
||||||
return newCipherGeneric(key)
|
return newCipherGeneric(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// expandKey is used by BenchmarkExpand and should
|
||||||
|
// call an assembly implementation if one is available.
|
||||||
|
func expandKey(key []byte, enc, dec []uint32) {
|
||||||
|
expandKeyGo(key, enc, dec)
|
||||||
|
}
|
@ -89,6 +89,6 @@ func BenchmarkExpand(b *testing.B) {
|
|||||||
c := &sm4Cipher{make([]uint32, rounds), make([]uint32, rounds)}
|
c := &sm4Cipher{make([]uint32, rounds), make([]uint32, rounds)}
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
expandKeyGo(tt.key, c.enc, c.dec)
|
expandKey(tt.key, c.enc, c.dec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user