This avoids an import conflict with crypto/subtle.
CL 424175 does the same for x/crypto.
Change-Id: Id4a319b3283b8affaaf769062388325b31fe1715
Reviewed-on: https://go-review.googlesource.com/c/go/+/424194
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
import (
"crypto/cipher"
- subtleoverlap "crypto/internal/subtle"
+ "crypto/internal/alias"
"crypto/subtle"
"errors"
)
gcmAesData(&g.productTable, data, &tagOut)
ret, out := sliceForAppend(dst, len(plaintext)+g.tagSize)
- if subtleoverlap.InexactOverlap(out[:len(plaintext)], plaintext) {
+ if alias.InexactOverlap(out[:len(plaintext)], plaintext) {
panic("crypto/cipher: invalid buffer overlap")
}
if len(plaintext) > 0 {
gcmAesData(&g.productTable, data, &expectedTag)
ret, out := sliceForAppend(dst, len(ciphertext))
- if subtleoverlap.InexactOverlap(out, ciphertext) {
+ if alias.InexactOverlap(out, ciphertext) {
panic("crypto/cipher: invalid buffer overlap")
}
if len(ciphertext) > 0 {
import (
"crypto/cipher"
- "crypto/internal/subtle"
+ "crypto/internal/alias"
)
// Assert that aesCipherAsm implements the cbcEncAble and cbcDecAble interfaces.
if len(dst) < len(src) {
panic("crypto/cipher: output smaller than input")
}
- if subtle.InexactOverlap(dst[:len(src)], src) {
+ if alias.InexactOverlap(dst[:len(src)], src) {
panic("crypto/cipher: invalid buffer overlap")
}
if len(src) > 0 {
import (
"crypto/cipher"
- "crypto/internal/subtle"
+ "crypto/internal/alias"
)
// Assert that aesCipherAsm implements the cbcEncAble and cbcDecAble interfaces.
if len(dst) < len(src) {
panic("crypto/cipher: output smaller than input")
}
- if subtle.InexactOverlap(dst[:len(src)], src) {
+ if alias.InexactOverlap(dst[:len(src)], src) {
panic("crypto/cipher: invalid buffer overlap")
}
if len(src) > 0 {
import (
"crypto/cipher"
+ "crypto/internal/alias"
"crypto/internal/boring"
- "crypto/internal/subtle"
"strconv"
)
if len(dst) < BlockSize {
panic("crypto/aes: output not full block")
}
- if subtle.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
+ if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("crypto/aes: invalid buffer overlap")
}
encryptBlockGo(c.enc, dst, src)
if len(dst) < BlockSize {
panic("crypto/aes: output not full block")
}
- if subtle.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
+ if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("crypto/aes: invalid buffer overlap")
}
decryptBlockGo(c.dec, dst, src)
import (
"crypto/cipher"
+ "crypto/internal/alias"
"crypto/internal/boring"
- "crypto/internal/subtle"
"internal/cpu"
"internal/goarch"
)
if len(dst) < BlockSize {
panic("crypto/aes: output not full block")
}
- if subtle.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
+ if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("crypto/aes: invalid buffer overlap")
}
encryptBlockAsm(len(c.enc)/4-1, &c.enc[0], &dst[0], &src[0])
if len(dst) < BlockSize {
panic("crypto/aes: output not full block")
}
- if subtle.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
+ if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("crypto/aes: invalid buffer overlap")
}
decryptBlockAsm(len(c.dec)/4-1, &c.dec[0], &dst[0], &src[0])
import (
"crypto/cipher"
- "crypto/internal/subtle"
+ "crypto/internal/alias"
"internal/cpu"
)
if len(dst) < BlockSize {
panic("crypto/aes: output not full block")
}
- if subtle.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
+ if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("crypto/aes: invalid buffer overlap")
}
cryptBlocks(c.function, &c.key[0], &dst[0], &src[0], BlockSize)
if len(dst) < BlockSize {
panic("crypto/aes: output not full block")
}
- if subtle.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
+ if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("crypto/aes: invalid buffer overlap")
}
// The decrypt function code is equal to the function code + 128.
import (
"crypto/cipher"
- "crypto/internal/subtle"
+ "crypto/internal/alias"
"encoding/binary"
)
if len(dst) < len(src) {
panic("crypto/cipher: output smaller than input")
}
- if subtle.InexactOverlap(dst[:len(src)], src) {
+ if alias.InexactOverlap(dst[:len(src)], src) {
panic("crypto/cipher: invalid buffer overlap")
}
for len(src) > 0 {
import (
"crypto/cipher"
- subtleoverlap "crypto/internal/subtle"
+ "crypto/internal/alias"
"crypto/subtle"
"encoding/binary"
"errors"
}
ret, out := sliceForAppend(dst, len(plaintext)+g.tagSize)
- if subtleoverlap.InexactOverlap(out[:len(plaintext)], plaintext) {
+ if alias.InexactOverlap(out[:len(plaintext)], plaintext) {
panic("crypto/cipher: invalid buffer overlap")
}
g.auth(expectedTag[:], ciphertext, data, &tagMask)
ret, out := sliceForAppend(dst, len(ciphertext))
- if subtleoverlap.InexactOverlap(out, ciphertext) {
+ if alias.InexactOverlap(out, ciphertext) {
panic("crypto/cipher: invalid buffer overlap")
}
}
ret, out := sliceForAppend(dst, len(plaintext)+g.tagSize)
- if subtleoverlap.InexactOverlap(out[:len(plaintext)], plaintext) {
+ if alias.InexactOverlap(out[:len(plaintext)], plaintext) {
panic("crypto/cipher: invalid buffer overlap")
}
tag := ciphertext[len(ciphertext)-g.tagSize:]
ciphertext = ciphertext[:len(ciphertext)-g.tagSize]
ret, out := sliceForAppend(dst, len(ciphertext))
- if subtleoverlap.InexactOverlap(out, ciphertext) {
+ if alias.InexactOverlap(out, ciphertext) {
panic("crypto/cipher: invalid buffer overlap")
}
package cipher
-import "crypto/internal/subtle"
+import "crypto/internal/alias"
type cbc struct {
b Block
if len(dst) < len(src) {
panic("crypto/cipher: output smaller than input")
}
- if subtle.InexactOverlap(dst[:len(src)], src) {
+ if alias.InexactOverlap(dst[:len(src)], src) {
panic("crypto/cipher: invalid buffer overlap")
}
if len(dst) < len(src) {
panic("crypto/cipher: output smaller than input")
}
- if subtle.InexactOverlap(dst[:len(src)], src) {
+ if alias.InexactOverlap(dst[:len(src)], src) {
panic("crypto/cipher: invalid buffer overlap")
}
if len(src) == 0 {
package cipher
-import "crypto/internal/subtle"
+import "crypto/internal/alias"
type cfb struct {
b Block
if len(dst) < len(src) {
panic("crypto/cipher: output smaller than input")
}
- if subtle.InexactOverlap(dst[:len(src)], src) {
+ if alias.InexactOverlap(dst[:len(src)], src) {
panic("crypto/cipher: invalid buffer overlap")
}
for len(src) > 0 {
package cipher
-import "crypto/internal/subtle"
+import "crypto/internal/alias"
type ctr struct {
b Block
if len(dst) < len(src) {
panic("crypto/cipher: output smaller than input")
}
- if subtle.InexactOverlap(dst[:len(src)], src) {
+ if alias.InexactOverlap(dst[:len(src)], src) {
panic("crypto/cipher: invalid buffer overlap")
}
for len(src) > 0 {
package cipher
import (
- subtleoverlap "crypto/internal/subtle"
+ "crypto/internal/alias"
"crypto/subtle"
"encoding/binary"
"errors"
}
ret, out := sliceForAppend(dst, len(plaintext)+g.tagSize)
- if subtleoverlap.InexactOverlap(out, plaintext) {
+ if alias.InexactOverlap(out, plaintext) {
panic("crypto/cipher: invalid buffer overlap")
}
g.auth(expectedTag[:], ciphertext, data, &tagMask)
ret, out := sliceForAppend(dst, len(ciphertext))
- if subtleoverlap.InexactOverlap(out, ciphertext) {
+ if alias.InexactOverlap(out, ciphertext) {
panic("crypto/cipher: invalid buffer overlap")
}
package cipher
-import "crypto/internal/subtle"
+import "crypto/internal/alias"
type ofb struct {
b Block
if len(dst) < len(src) {
panic("crypto/cipher: output smaller than input")
}
- if subtle.InexactOverlap(dst[:len(src)], src) {
+ if alias.InexactOverlap(dst[:len(src)], src) {
panic("crypto/cipher: invalid buffer overlap")
}
for len(src) > 0 {
import (
"crypto/cipher"
- "crypto/internal/subtle"
+ "crypto/internal/alias"
"encoding/binary"
"strconv"
)
if len(dst) < BlockSize {
panic("crypto/des: output not full block")
}
- if subtle.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
+ if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("crypto/des: invalid buffer overlap")
}
encryptBlock(c.subkeys[:], dst, src)
if len(dst) < BlockSize {
panic("crypto/des: output not full block")
}
- if subtle.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
+ if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("crypto/des: invalid buffer overlap")
}
decryptBlock(c.subkeys[:], dst, src)
if len(dst) < BlockSize {
panic("crypto/des: output not full block")
}
- if subtle.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
+ if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("crypto/des: invalid buffer overlap")
}
if len(dst) < BlockSize {
panic("crypto/des: output not full block")
}
- if subtle.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
+ if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("crypto/des: invalid buffer overlap")
}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build !appengine
-
-// Package subtle implements functions that are often useful in cryptographic
-// code but require careful thought to use correctly.
-//
-// This is a mirror of golang.org/x/crypto/internal/subtle.
-package subtle // import "crypto/internal/subtle"
+// Package alias implements memory alaising tests.
+// This code also exists as golang.org/x/crypto/internal/alias.
+package alias
import "unsafe"
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package subtle_test
+package alias
-import (
- "testing"
-
- "crypto/internal/subtle"
-)
+import "testing"
var a, b [100]byte
}
func testAliasing(t *testing.T, i int, x, y []byte, anyOverlap, inexactOverlap bool) {
- any := subtle.AnyOverlap(x, y)
+ any := AnyOverlap(x, y)
if any != anyOverlap {
t.Errorf("%d: wrong AnyOverlap result, expected %v, got %v", i, anyOverlap, any)
}
- inexact := subtle.InexactOverlap(x, y)
+ inexact := InexactOverlap(x, y)
if inexact != inexactOverlap {
t.Errorf("%d: wrong InexactOverlap result, expected %v, got %v", i, inexactOverlap, any)
}
+++ /dev/null
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build appengine
-
-// Package subtle implements functions that are often useful in cryptographic
-// code but require careful thought to use correctly.
-//
-// This is a mirror of golang.org/x/crypto/internal/subtle.
-package subtle // import "crypto/internal/subtle"
-
-// This is the Google App Engine standard variant based on reflect
-// because the unsafe package and cgo are disallowed.
-
-import "reflect"
-
-// AnyOverlap reports whether x and y share memory at any (not necessarily
-// corresponding) index. The memory beyond the slice length is ignored.
-func AnyOverlap(x, y []byte) bool {
- return len(x) > 0 && len(y) > 0 &&
- reflect.ValueOf(&x[0]).Pointer() <= reflect.ValueOf(&y[len(y)-1]).Pointer() &&
- reflect.ValueOf(&y[0]).Pointer() <= reflect.ValueOf(&x[len(x)-1]).Pointer()
-}
-
-// InexactOverlap reports whether x and y share memory at any non-corresponding
-// index. The memory beyond the slice length is ignored. Note that x and y can
-// have different lengths and still not have any inexact overlap.
-//
-// InexactOverlap can be used to implement the requirements of the crypto/cipher
-// AEAD, Block, BlockMode and Stream interfaces.
-func InexactOverlap(x, y []byte) bool {
- if len(x) == 0 || len(y) == 0 || &x[0] == &y[0] {
- return false
- }
- return AnyOverlap(x, y)
-}
package rc4
import (
- "crypto/internal/subtle"
+ "crypto/internal/alias"
"strconv"
)
if len(src) == 0 {
return
}
- if subtle.InexactOverlap(dst[:len(src)], src) {
+ if alias.InexactOverlap(dst[:len(src)], src) {
panic("crypto/rc4: invalid buffer overlap")
}
i, j := c.i, c.j
hash, embed
< crypto
< crypto/subtle
- < crypto/internal/subtle
+ < crypto/internal/alias
< crypto/internal/randutil
< crypto/internal/nistec/fiat
< crypto/internal/nistec
# TLS, Prince of Dependencies.
CRYPTO-MATH, NET, container/list, encoding/hex, encoding/pem
+ < golang.org/x/crypto/internal/alias
< golang.org/x/crypto/internal/subtle
< golang.org/x/crypto/chacha20
< golang.org/x/crypto/internal/poly1305