cipher: use new functions

This commit is contained in:
Sun Yimin 2025-02-26 11:46:48 +08:00 committed by GitHub
parent a98b806453
commit 0bb54adc1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 10 deletions

View File

@ -3,6 +3,7 @@
package cipher
import (
"bytes"
_cipher "crypto/cipher"
"github.com/emmansun/gmsm/internal/subtle"
@ -15,13 +16,11 @@ type bc struct {
}
func newBC(b _cipher.Block, iv []byte) *bc {
c := &bc{
return &bc{
b: b,
blockSize: b.BlockSize(),
iv: make([]byte, b.BlockSize()),
iv: bytes.Clone(iv),
}
copy(c.iv, iv)
return c
}
type bcEncrypter bc

View File

@ -239,9 +239,7 @@ func (c *ccm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
// so overwrites dst in the event of a tag mismatch. That
// behavior is mimicked here in order to be consistent across
// platforms.
for i := range out {
out[i] = 0
}
clear(out)
return nil, errOpen
}
return ret, nil

View File

@ -4,6 +4,7 @@
package cipher
import (
"bytes"
_cipher "crypto/cipher"
"errors"
)
@ -28,8 +29,8 @@ func newOFBNLF(cipherFunc CipherCreator, key, iv []byte) (*ofbnlf, error) {
if len(iv) != c.blockSize {
return nil, errors.New("cipher: IV length must equal block size")
}
c.iv = make([]byte, c.blockSize)
copy(c.iv, iv)
c.iv = bytes.Clone(iv)
return c, nil
}

View File

@ -8,7 +8,7 @@ func mul2(tweak *[blockSize]byte, isGB bool) {
func doubleTweaks(tweak *[blockSize]byte, tweaks []byte, isGB bool) {
count := len(tweaks) >> 4
for i := 0; i < count; i++ {
for i := range count {
copy(tweaks[blockSize*i:], tweak[:])
mul2(tweak, isGB)
}