From 8a25134c8257859482a990b963e6f1b68d77944e Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Wed, 26 Feb 2025 10:24:46 +0800 Subject: [PATCH] sm4: fallback ctr change --- sm4/ctr_cipher_asm.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sm4/ctr_cipher_asm.go b/sm4/ctr_cipher_asm.go index 8920568..89ef8b9 100644 --- a/sm4/ctr_cipher_asm.go +++ b/sm4/ctr_cipher_asm.go @@ -34,17 +34,18 @@ func (c *sm4CipherAsm) NewCTR(iv []byte) cipher.Stream { } s := &ctr{ b: c, - ctr: bytes.Clone(iv), + ctr: make([]byte, c.blocksSize), out: make([]byte, 0, bufSize), outUsed: 0, } + copy(s.ctr, iv) for i := 1; i < c.batchBlocks; i++ { s.genCtr(i * BlockSize) } return s - } + func (x *ctr) genCtr(start int) { if start >= BlockSize { copy(x.ctr[start:], x.ctr[start-BlockSize:start])