mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-27 04:36:19 +08:00
sm4: fallback ctr change
This commit is contained in:
parent
27e7ceacbc
commit
8a25134c82
@ -34,17 +34,18 @@ func (c *sm4CipherAsm) NewCTR(iv []byte) cipher.Stream {
|
|||||||
}
|
}
|
||||||
s := &ctr{
|
s := &ctr{
|
||||||
b: c,
|
b: c,
|
||||||
ctr: bytes.Clone(iv),
|
ctr: make([]byte, c.blocksSize),
|
||||||
out: make([]byte, 0, bufSize),
|
out: make([]byte, 0, bufSize),
|
||||||
outUsed: 0,
|
outUsed: 0,
|
||||||
}
|
}
|
||||||
|
copy(s.ctr, iv)
|
||||||
for i := 1; i < c.batchBlocks; i++ {
|
for i := 1; i < c.batchBlocks; i++ {
|
||||||
s.genCtr(i * BlockSize)
|
s.genCtr(i * BlockSize)
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (x *ctr) genCtr(start int) {
|
func (x *ctr) genCtr(start int) {
|
||||||
if start >= BlockSize {
|
if start >= BlockSize {
|
||||||
copy(x.ctr[start:], x.ctr[start-BlockSize:start])
|
copy(x.ctr[start:], x.ctr[start-BlockSize:start])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user