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>
package cipher
import (
+ "bytes"
"crypto/internal/alias"
"crypto/subtle"
)
return &cbc{
b: b,
blockSize: b.BlockSize(),
- iv: dup(iv),
+ iv: bytes.Clone(iv),
tmp: make([]byte, b.BlockSize()),
}
}
// 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
-}
package cipher
import (
+ "bytes"
"crypto/internal/alias"
"crypto/subtle"
)
}
return &ctr{
b: block,
- ctr: dup(iv),
+ ctr: bytes.Clone(iv),
out: make([]byte, 0, bufSize),
outUsed: 0,
}
// interoperability with RFC 8032. RFC 8032's private keys correspond to seeds
// in this package.
func (priv PrivateKey) Seed() []byte {
- seed := make([]byte, SeedSize)
- copy(seed, priv[:32])
- return seed
+ return bytes.Clone(priv[:SeedSize])
}
// Sign signs the given message with priv.
*/
import "C"
import (
+ "bytes"
"crypto/cipher"
"errors"
"runtime"
var _ extraModes = (*aesCipher)(nil)
func NewAESCipher(key []byte) (cipher.Block, error) {
- c := &aesCipher{key: make([]byte, len(key))}
- copy(c.key, key)
+ c := &aesCipher{key: bytes.Clone(key)}
// Note: 0 is success, contradicting the usual BoringCrypto convention.
if C._goboringcrypto_AES_set_decrypt_key((*C.uint8_t)(unsafe.Pointer(&c.key[0])), C.uint(8*len(c.key)), &c.dec) != 0 ||
C._goboringcrypto_AES_set_encrypt_key((*C.uint8_t)(unsafe.Pointer(&c.key[0])), C.uint(8*len(c.key)), &c.enc) != 0 {
// #include "goboringcrypto.h"
import "C"
import (
+ "bytes"
"crypto"
"hash"
"runtime"
}
// Note: Could hash down long keys here using EVP_Digest.
- hkey := make([]byte, len(key))
- copy(hkey, key)
+ hkey := bytes.Clone(key)
hmac := &boringHMAC{
md: md,
size: ch.Size(),
package macOS
import (
+ "bytes"
"errors"
"internal/abi"
"runtime"
length := CFDataGetLength(data)
ptr := CFDataGetBytePtr(data)
src := unsafe.Slice((*byte)(unsafe.Pointer(ptr)), length)
- out := make([]byte, length)
- copy(out, src)
- return out
+ return bytes.Clone(src)
}
// CFStringToString returns a Go string representation of the passed
package x509
import (
+ "bytes"
"errors"
"syscall"
"unsafe"
// Copy the buf, since ParseCertificate does not create its own copy.
cert := elements[i].CertContext
encodedCert := unsafe.Slice(cert.EncodedCert, cert.Length)
- buf := make([]byte, cert.Length)
- copy(buf, encodedCert)
+ buf := bytes.Clone(encodedCert)
parsedCert, err := ParseCertificate(buf)
if err != nil {
return nil, err