mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 12:16:20 +08:00
sm4: fix bug
This commit is contained in:
parent
57d800767b
commit
83849d33cf
@ -70,7 +70,7 @@ func encryptBlockGo(xk []uint32, dst, src []byte) {
|
|||||||
// Key expansion algorithm.
|
// Key expansion algorithm.
|
||||||
func expandKeyGo(key []byte, enc, dec []uint32) {
|
func expandKeyGo(key []byte, enc, dec []uint32) {
|
||||||
// Encryption key setup.
|
// Encryption key setup.
|
||||||
enc = enc[:rounds-1]
|
enc = enc[:rounds]
|
||||||
var i int
|
var i int
|
||||||
var mk [4]uint32
|
var mk [4]uint32
|
||||||
var k [rounds + 4]uint32
|
var k [rounds + 4]uint32
|
||||||
@ -85,7 +85,6 @@ func expandKeyGo(key []byte, enc, dec []uint32) {
|
|||||||
mk[3] = binary.BigEndian.Uint32(key[12:])
|
mk[3] = binary.BigEndian.Uint32(key[12:])
|
||||||
k[3] = mk[3] ^ fk[3]
|
k[3] = mk[3] ^ fk[3]
|
||||||
|
|
||||||
_ = enc[rounds-1]
|
|
||||||
for i = 0; i < rounds; i++ {
|
for i = 0; i < rounds; i++ {
|
||||||
k[i+4] = k[i] ^ t2(k[i+1]^k[i+2]^k[i+3]^ck[i])
|
k[i+4] = k[i] ^ t2(k[i+1]^k[i+2]^k[i+3]^ck[i])
|
||||||
enc[i] = k[i+4]
|
enc[i] = k[i+4]
|
||||||
@ -96,7 +95,7 @@ func expandKeyGo(key []byte, enc, dec []uint32) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dec = dec[:rounds-1]
|
dec = dec[:rounds]
|
||||||
for i = 0; i < rounds; i++ {
|
for i = 0; i < rounds; i++ {
|
||||||
dec[i] = enc[rounds-1-i]
|
dec[i] = enc[rounds-1-i]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user