tjfoc / gmsm

GM SM2/3/4 library based on Golang (基于Go语言的国密SM2/SM3/SM4算法库)
http://www.wutongchain.com
Apache License 2.0
1.78k stars 589 forks source link

sm4 算法多线程不安全,不符合 go 的常见 block cipher 的约束 #171

Closed wxiaoguang closed 1 year ago

wxiaoguang commented 2 years ago

可以改成这样:

type sm4CipherGo struct {
    subkeys [32]uint32
}

func (c *sm4CipherGo) Encrypt(dst, src []byte) {
    var block1 [4]uint32
    var block2 [16]byte
    sm4cryptBlock(c.subkeys[:], block1[:], block2[:], dst, src, false)
}

func (c *sm4CipherGo) Decrypt(dst, src []byte) {
    var block1 [4]uint32
    var block2 [16]byte
    sm4cryptBlock(c.subkeys[:], block1[:], block2[:], dst, src, true)
}