aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/cipher
diff options
context:
space:
mode:
authorcuiweixie <cuiweixie@gmail.com>2022-09-28 00:28:49 +0800
committerGopher Robot <gobot@golang.org>2022-09-28 03:55:33 +0000
commit56fb2cff9f127a2a7dad0b44bb5522785aa06ddf (patch)
tree944a9863756b24b5c10e7886d8fb9f1233d8222f /src/crypto/cipher
parentacc5e3a0c20432199181fef2bc6204fbd11d21d0 (diff)
downloadgo-56fb2cff9f127a2a7dad0b44bb5522785aa06ddf.tar.xz
crypto: use bytes.Clone
Change-Id: I92e110023739c6f8f7815c7e47ad7639c4e8812d Reviewed-on: https://go-review.googlesource.com/c/go/+/435279 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: xie cui <523516579@qq.com>
Diffstat (limited to 'src/crypto/cipher')
-rw-r--r--src/crypto/cipher/cbc.go3
-rw-r--r--src/crypto/cipher/cipher.go8
-rw-r--r--src/crypto/cipher/ctr.go3
3 files changed, 4 insertions, 10 deletions
diff --git a/src/crypto/cipher/cbc.go b/src/crypto/cipher/cbc.go
index fe774c116e..51a142071f 100644
--- a/src/crypto/cipher/cbc.go
+++ b/src/crypto/cipher/cbc.go
@@ -12,6 +12,7 @@
package cipher
import (
+ "bytes"
"crypto/internal/alias"
"crypto/subtle"
)
@@ -27,7 +28,7 @@ func newCBC(b Block, iv []byte) *cbc {
return &cbc{
b: b,
blockSize: b.BlockSize(),
- iv: dup(iv),
+ iv: bytes.Clone(iv),
tmp: make([]byte, b.BlockSize()),
}
}
diff --git a/src/crypto/cipher/cipher.go b/src/crypto/cipher/cipher.go
index 7e1a4de9a3..df6f596b4d 100644
--- a/src/crypto/cipher/cipher.go
+++ b/src/crypto/cipher/cipher.go
@@ -59,11 +59,3 @@ type BlockMode interface {
// maintains state and does not reset at each CryptBlocks call.
CryptBlocks(dst, src []byte)
}
-
-// Utility routines
-
-func dup(p []byte) []byte {
- q := make([]byte, len(p))
- copy(q, p)
- return q
-}
diff --git a/src/crypto/cipher/ctr.go b/src/crypto/cipher/ctr.go
index 2b434ef832..3ac0ff74d0 100644
--- a/src/crypto/cipher/ctr.go
+++ b/src/crypto/cipher/ctr.go
@@ -13,6 +13,7 @@
package cipher
import (
+ "bytes"
"crypto/internal/alias"
"crypto/subtle"
)
@@ -48,7 +49,7 @@ func NewCTR(block Block, iv []byte) Stream {
}
return &ctr{
b: block,
- ctr: dup(iv),
+ ctr: bytes.Clone(iv),
out: make([]byte, 0, bufSize),
outUsed: 0,
}