From 83849d33cf72c2384329bf4f760f02352aa8d4b3 Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Mon, 5 Jun 2023 14:46:59 +0800 Subject: [PATCH] sm4: fix bug --- sm4/block.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sm4/block.go b/sm4/block.go index 71fc5e6..c7134d8 100644 --- a/sm4/block.go +++ b/sm4/block.go @@ -70,7 +70,7 @@ func encryptBlockGo(xk []uint32, dst, src []byte) { // Key expansion algorithm. func expandKeyGo(key []byte, enc, dec []uint32) { // Encryption key setup. - enc = enc[:rounds-1] + enc = enc[:rounds] var i int var mk [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:]) k[3] = mk[3] ^ fk[3] - _ = enc[rounds-1] for i = 0; i < rounds; i++ { k[i+4] = k[i] ^ t2(k[i+1]^k[i+2]^k[i+3]^ck[i]) enc[i] = k[i+4] @@ -96,7 +95,7 @@ func expandKeyGo(key []byte, enc, dec []uint32) { return } - dec = dec[:rounds-1] + dec = dec[:rounds] for i = 0; i < rounds; i++ { dec[i] = enc[rounds-1-i] }