]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/internal/subtle: rename to crypto/internal/alias
authorRuss Cox <rsc@golang.org>
Tue, 16 Aug 2022 14:50:35 +0000 (10:50 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 17 Aug 2022 18:46:05 +0000 (18:46 +0000)
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>

19 files changed:
src/crypto/aes/aes_gcm.go
src/crypto/aes/cbc_ppc64x.go
src/crypto/aes/cbc_s390x.go
src/crypto/aes/cipher.go
src/crypto/aes/cipher_asm.go
src/crypto/aes/cipher_s390x.go
src/crypto/aes/ctr_s390x.go
src/crypto/aes/gcm_s390x.go
src/crypto/cipher/cbc.go
src/crypto/cipher/cfb.go
src/crypto/cipher/ctr.go
src/crypto/cipher/gcm.go
src/crypto/cipher/ofb.go
src/crypto/des/cipher.go
src/crypto/internal/alias/alias.go [moved from src/crypto/internal/subtle/aliasing.go with 79% similarity]
src/crypto/internal/alias/alias_test.go [moved from src/crypto/internal/subtle/aliasing_test.go with 89% similarity]
src/crypto/internal/subtle/aliasing_appengine.go [deleted file]
src/crypto/rc4/rc4.go
src/go/build/deps_test.go

index ebae646a135a95e71eb73cbbdc5d61859d7c9e26..f77d27969a40d7c77dbd3f9f0cc27bfc0090e864 100644 (file)
@@ -8,7 +8,7 @@ package aes
 
 import (
        "crypto/cipher"
-       subtleoverlap "crypto/internal/subtle"
+       "crypto/internal/alias"
        "crypto/subtle"
        "errors"
 )
@@ -114,7 +114,7 @@ func (g *gcmAsm) Seal(dst, nonce, plaintext, data []byte) []byte {
        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 {
@@ -167,7 +167,7 @@ func (g *gcmAsm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
        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 {
index 797023e9ec3d75a75ecbea0737176dbe91fc352f..c23c37156e517909e87b9b3fbe41d13248283ef2 100644 (file)
@@ -8,7 +8,7 @@ package aes
 
 import (
        "crypto/cipher"
-       "crypto/internal/subtle"
+       "crypto/internal/alias"
 )
 
 // Assert that aesCipherAsm implements the cbcEncAble and cbcDecAble interfaces.
@@ -54,7 +54,7 @@ func (x *cbc) CryptBlocks(dst, src []byte) {
        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 {
index 766247abffb8d525cf56e5d9fe3f58571574da1a..eaa21f8a65f2ccab64434597f4775eb907f96eca 100644 (file)
@@ -6,7 +6,7 @@ package aes
 
 import (
        "crypto/cipher"
-       "crypto/internal/subtle"
+       "crypto/internal/alias"
 )
 
 // Assert that aesCipherAsm implements the cbcEncAble and cbcDecAble interfaces.
@@ -50,7 +50,7 @@ func (x *cbc) CryptBlocks(dst, src []byte) {
        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 {
index db0ee38b78cea57e44cff31868025a58cfcff7e3..183c1697c867b2caf167127603fdef05c20cec1c 100644 (file)
@@ -6,8 +6,8 @@ package aes
 
 import (
        "crypto/cipher"
+       "crypto/internal/alias"
        "crypto/internal/boring"
-       "crypto/internal/subtle"
        "strconv"
 )
 
@@ -62,7 +62,7 @@ func (c *aesCipher) Encrypt(dst, src []byte) {
        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)
@@ -75,7 +75,7 @@ func (c *aesCipher) Decrypt(dst, src []byte) {
        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)
index 1482b22d08b5f4a392e2401402607e7629af8033..90031c5e2c58e6b0ef43060c45423ad948252bba 100644 (file)
@@ -8,8 +8,8 @@ package aes
 
 import (
        "crypto/cipher"
+       "crypto/internal/alias"
        "crypto/internal/boring"
-       "crypto/internal/subtle"
        "internal/cpu"
        "internal/goarch"
 )
@@ -75,7 +75,7 @@ func (c *aesCipherAsm) Encrypt(dst, src []byte) {
        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])
@@ -89,7 +89,7 @@ func (c *aesCipherAsm) Decrypt(dst, src []byte) {
        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])
index e357851143130b760ebce5f966676b9236f0267c..8dd3d8f0537fd3b86229449168204a473a4ea4f8 100644 (file)
@@ -6,7 +6,7 @@ package aes
 
 import (
        "crypto/cipher"
-       "crypto/internal/subtle"
+       "crypto/internal/alias"
        "internal/cpu"
 )
 
@@ -69,7 +69,7 @@ func (c *aesCipherAsm) Encrypt(dst, src []byte) {
        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)
@@ -82,7 +82,7 @@ func (c *aesCipherAsm) Decrypt(dst, src []byte) {
        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.
index f5c33d529928b1b9e4337f4c8e64cb99a431d931..0d3a58e0347dc0d07fde4165f90cc4f7bb8362f4 100644 (file)
@@ -6,7 +6,7 @@ package aes
 
 import (
        "crypto/cipher"
-       "crypto/internal/subtle"
+       "crypto/internal/alias"
        "encoding/binary"
 )
 
@@ -69,7 +69,7 @@ func (c *aesctr) XORKeyStream(dst, src []byte) {
        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 {
index 98d530aeda1af027c06240937300dee3a1f6a3e4..d95f1694c66578c9c7226e1b7af780150eba1dd0 100644 (file)
@@ -6,7 +6,7 @@ package aes
 
 import (
        "crypto/cipher"
-       subtleoverlap "crypto/internal/subtle"
+       "crypto/internal/alias"
        "crypto/subtle"
        "encoding/binary"
        "errors"
@@ -211,7 +211,7 @@ func (g *gcmAsm) Seal(dst, nonce, plaintext, data []byte) []byte {
        }
 
        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")
        }
 
@@ -260,7 +260,7 @@ func (g *gcmAsm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
        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")
        }
 
@@ -312,7 +312,7 @@ func (g *gcmKMA) Seal(dst, nonce, plaintext, data []byte) []byte {
        }
 
        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")
        }
 
@@ -342,7 +342,7 @@ func (g *gcmKMA) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
        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")
        }
 
index a719b61e24c089e62479b1cf183786650afd9cca..1ce165e7915651d3bc83e592ef78b73f31e3669c 100644 (file)
@@ -11,7 +11,7 @@
 
 package cipher
 
-import "crypto/internal/subtle"
+import "crypto/internal/alias"
 
 type cbc struct {
        b         Block
@@ -72,7 +72,7 @@ func (x *cbcEncrypter) CryptBlocks(dst, src []byte) {
        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")
        }
 
@@ -143,7 +143,7 @@ func (x *cbcDecrypter) CryptBlocks(dst, src []byte) {
        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 {
index 80c9bc24ea01f71293bab3055d2a38f04e7c0a2f..33615b01d55d1fe60c44f0f9fb86f16ae763b867 100644 (file)
@@ -6,7 +6,7 @@
 
 package cipher
 
-import "crypto/internal/subtle"
+import "crypto/internal/alias"
 
 type cfb struct {
        b       Block
@@ -21,7 +21,7 @@ func (x *cfb) XORKeyStream(dst, src []byte) {
        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 {
index cba028d2a4453c9cfd41feafa44b0706e1749c12..3b8e32a9a4f5b75d2640b497250c0f4b703f24e2 100644 (file)
@@ -12,7 +12,7 @@
 
 package cipher
 
-import "crypto/internal/subtle"
+import "crypto/internal/alias"
 
 type ctr struct {
        b       Block
@@ -76,7 +76,7 @@ func (x *ctr) XORKeyStream(dst, src []byte) {
        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 {
index 5b14c0a7e2d224fd4dcf5bed5f34caa567a9c04a..a23ebb1d90cbb1a8f26183e5a6e4cbcfcd649e21 100644 (file)
@@ -5,7 +5,7 @@
 package cipher
 
 import (
-       subtleoverlap "crypto/internal/subtle"
+       "crypto/internal/alias"
        "crypto/subtle"
        "encoding/binary"
        "errors"
@@ -174,7 +174,7 @@ func (g *gcm) Seal(dst, nonce, plaintext, data []byte) []byte {
        }
 
        ret, out := sliceForAppend(dst, len(plaintext)+g.tagSize)
-       if subtleoverlap.InexactOverlap(out, plaintext) {
+       if alias.InexactOverlap(out, plaintext) {
                panic("crypto/cipher: invalid buffer overlap")
        }
 
@@ -225,7 +225,7 @@ func (g *gcm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
        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")
        }
 
index fc477248658c8d83c9b360faeae2ba3830d55c32..64e34a9676ed242ea874b656d61e592920400aec 100644 (file)
@@ -6,7 +6,7 @@
 
 package cipher
 
-import "crypto/internal/subtle"
+import "crypto/internal/alias"
 
 type ofb struct {
        b       Block
@@ -59,7 +59,7 @@ func (x *ofb) XORKeyStream(dst, src []byte) {
        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 {
index 9e6779c216b5f85ddf2e5e4c9ee2cf198191b70d..ece764f171ad7b71771d73884f4ba341fd2f38f2 100644 (file)
@@ -6,7 +6,7 @@ package des
 
 import (
        "crypto/cipher"
-       "crypto/internal/subtle"
+       "crypto/internal/alias"
        "encoding/binary"
        "strconv"
 )
@@ -45,7 +45,7 @@ func (c *desCipher) Encrypt(dst, src []byte) {
        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)
@@ -58,7 +58,7 @@ func (c *desCipher) Decrypt(dst, src []byte) {
        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)
@@ -91,7 +91,7 @@ func (c *tripleDESCipher) Encrypt(dst, src []byte) {
        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")
        }
 
@@ -126,7 +126,7 @@ func (c *tripleDESCipher) Decrypt(dst, src []byte) {
        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")
        }
 
similarity index 79%
rename from src/crypto/internal/subtle/aliasing.go
rename to src/crypto/internal/alias/alias.go
index 16e2fcab124814cc809f8fb4afdfa8c1ac07ee99..936cc253e31353a74617a7a4d485e8f690b4e9dd 100644 (file)
@@ -2,13 +2,9 @@
 // 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"
 
similarity index 89%
rename from src/crypto/internal/subtle/aliasing_test.go
rename to src/crypto/internal/alias/alias_test.go
index f1e723848124fd3f9c2d2018070c29c60b7331f8..a68fb33667bf633067dbef222387f230ca51a918 100644 (file)
@@ -2,13 +2,9 @@
 // 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
 
@@ -32,11 +28,11 @@ var aliasingTests = []struct {
 }
 
 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)
        }
diff --git a/src/crypto/internal/subtle/aliasing_appengine.go b/src/crypto/internal/subtle/aliasing_appengine.go
deleted file mode 100644 (file)
index 90ac4b6..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-// 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)
-}
index c2df0db2dc8984711cd301adb2e2e77fafabbcfa..f08da0e469cd07788fc8506205639490fa0d1088 100644 (file)
@@ -10,7 +10,7 @@
 package rc4
 
 import (
-       "crypto/internal/subtle"
+       "crypto/internal/alias"
        "strconv"
 )
 
@@ -62,7 +62,7 @@ func (c *Cipher) XORKeyStream(dst, src []byte) {
        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
index 061345f64b69180751caacc90e7fcad877d51dcb..07bac04dcb4136857b7038736808c4b7427b3b01 100644 (file)
@@ -381,7 +381,7 @@ var depsRules = `
        hash, embed
        < crypto
        < crypto/subtle
-       < crypto/internal/subtle
+       < crypto/internal/alias
        < crypto/internal/randutil
        < crypto/internal/nistec/fiat
        < crypto/internal/nistec
@@ -415,6 +415,7 @@ var depsRules = `
 
        # 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