mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 20:26:19 +08:00
cipher: use new functions
This commit is contained in:
parent
a98b806453
commit
0bb54adc1e
@ -3,6 +3,7 @@
|
|||||||
package cipher
|
package cipher
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
_cipher "crypto/cipher"
|
_cipher "crypto/cipher"
|
||||||
|
|
||||||
"github.com/emmansun/gmsm/internal/subtle"
|
"github.com/emmansun/gmsm/internal/subtle"
|
||||||
@ -15,13 +16,11 @@ type bc struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newBC(b _cipher.Block, iv []byte) *bc {
|
func newBC(b _cipher.Block, iv []byte) *bc {
|
||||||
c := &bc{
|
return &bc{
|
||||||
b: b,
|
b: b,
|
||||||
blockSize: b.BlockSize(),
|
blockSize: b.BlockSize(),
|
||||||
iv: make([]byte, b.BlockSize()),
|
iv: bytes.Clone(iv),
|
||||||
}
|
}
|
||||||
copy(c.iv, iv)
|
|
||||||
return c
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type bcEncrypter bc
|
type bcEncrypter bc
|
||||||
|
@ -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
|
// so overwrites dst in the event of a tag mismatch. That
|
||||||
// behavior is mimicked here in order to be consistent across
|
// behavior is mimicked here in order to be consistent across
|
||||||
// platforms.
|
// platforms.
|
||||||
for i := range out {
|
clear(out)
|
||||||
out[i] = 0
|
|
||||||
}
|
|
||||||
return nil, errOpen
|
return nil, errOpen
|
||||||
}
|
}
|
||||||
return ret, nil
|
return ret, nil
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
package cipher
|
package cipher
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
_cipher "crypto/cipher"
|
_cipher "crypto/cipher"
|
||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
@ -28,8 +29,8 @@ func newOFBNLF(cipherFunc CipherCreator, key, iv []byte) (*ofbnlf, error) {
|
|||||||
if len(iv) != c.blockSize {
|
if len(iv) != c.blockSize {
|
||||||
return nil, errors.New("cipher: IV length must equal block size")
|
return nil, errors.New("cipher: IV length must equal block size")
|
||||||
}
|
}
|
||||||
c.iv = make([]byte, c.blockSize)
|
c.iv = bytes.Clone(iv)
|
||||||
copy(c.iv, iv)
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ func mul2(tweak *[blockSize]byte, isGB bool) {
|
|||||||
|
|
||||||
func doubleTweaks(tweak *[blockSize]byte, tweaks []byte, isGB bool) {
|
func doubleTweaks(tweak *[blockSize]byte, tweaks []byte, isGB bool) {
|
||||||
count := len(tweaks) >> 4
|
count := len(tweaks) >> 4
|
||||||
for i := 0; i < count; i++ {
|
for i := range count {
|
||||||
copy(tweaks[blockSize*i:], tweak[:])
|
copy(tweaks[blockSize*i:], tweak[:])
|
||||||
mul2(tweak, isGB)
|
mul2(tweak, isGB)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user