sm4: fallback ctr change

This commit is contained in:
Sun Yimin 2025-02-26 10:24:46 +08:00 committed by GitHub
parent 27e7ceacbc
commit 8a25134c82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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])