Skip to content

Commit 04dced1

Browse files
rscgopherbot
authored andcommitted
internal/subtle: rename to internal/alias
This avoids an import conflict in code that needs to import crypto/subtle as well. CL 424194 does the same for the main repo. Change-Id: Ic54cb62bbfdcf5c2cb6f15ac47075ee1c41981ad Reviewed-on: https://go-review.googlesource.com/c/crypto/+/424175 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org>
1 parent 630584e commit 04dced1

File tree

10 files changed

+27
-33
lines changed

10 files changed

+27
-33
lines changed

chacha20/chacha_generic.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"errors"
1313
"math/bits"
1414

15-
"golang.org/x/crypto/internal/subtle"
15+
"golang.org/x/crypto/internal/alias"
1616
)
1717

1818
const (
@@ -189,7 +189,7 @@ func (s *Cipher) XORKeyStream(dst, src []byte) {
189189
panic("chacha20: output smaller than input")
190190
}
191191
dst = dst[:len(src)]
192-
if subtle.InexactOverlap(dst, src) {
192+
if alias.InexactOverlap(dst, src) {
193193
panic("chacha20: invalid buffer overlap")
194194
}
195195

chacha20poly1305/chacha20poly1305_amd64.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package chacha20poly1305
1010
import (
1111
"encoding/binary"
1212

13-
"golang.org/x/crypto/internal/subtle"
13+
"golang.org/x/crypto/internal/alias"
1414
"golang.org/x/sys/cpu"
1515
)
1616

@@ -56,7 +56,7 @@ func (c *chacha20poly1305) seal(dst, nonce, plaintext, additionalData []byte) []
5656
setupState(&state, &c.key, nonce)
5757

5858
ret, out := sliceForAppend(dst, len(plaintext)+16)
59-
if subtle.InexactOverlap(out, plaintext) {
59+
if alias.InexactOverlap(out, plaintext) {
6060
panic("chacha20poly1305: invalid buffer overlap")
6161
}
6262
chacha20Poly1305Seal(out[:], state[:], plaintext, additionalData)
@@ -73,7 +73,7 @@ func (c *chacha20poly1305) open(dst, nonce, ciphertext, additionalData []byte) (
7373

7474
ciphertext = ciphertext[:len(ciphertext)-16]
7575
ret, out := sliceForAppend(dst, len(ciphertext))
76-
if subtle.InexactOverlap(out, ciphertext) {
76+
if alias.InexactOverlap(out, ciphertext) {
7777
panic("chacha20poly1305: invalid buffer overlap")
7878
}
7979
if !chacha20Poly1305Open(out, state[:], ciphertext, additionalData) {

chacha20poly1305/chacha20poly1305_generic.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"encoding/binary"
99

1010
"golang.org/x/crypto/chacha20"
11+
"golang.org/x/crypto/internal/alias"
1112
"golang.org/x/crypto/internal/poly1305"
12-
"golang.org/x/crypto/internal/subtle"
1313
)
1414

1515
func writeWithPadding(p *poly1305.MAC, b []byte) {
@@ -30,7 +30,7 @@ func writeUint64(p *poly1305.MAC, n int) {
3030
func (c *chacha20poly1305) sealGeneric(dst, nonce, plaintext, additionalData []byte) []byte {
3131
ret, out := sliceForAppend(dst, len(plaintext)+poly1305.TagSize)
3232
ciphertext, tag := out[:len(plaintext)], out[len(plaintext):]
33-
if subtle.InexactOverlap(out, plaintext) {
33+
if alias.InexactOverlap(out, plaintext) {
3434
panic("chacha20poly1305: invalid buffer overlap")
3535
}
3636

@@ -66,7 +66,7 @@ func (c *chacha20poly1305) openGeneric(dst, nonce, ciphertext, additionalData []
6666
writeUint64(p, len(ciphertext))
6767

6868
ret, out := sliceForAppend(dst, len(ciphertext))
69-
if subtle.InexactOverlap(out, ciphertext) {
69+
if alias.InexactOverlap(out, ciphertext) {
7070
panic("chacha20poly1305: invalid buffer overlap")
7171
}
7272
if !p.Verify(tag) {

internal/subtle/aliasing.go internal/alias/alias.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
//go:build !purego
66
// +build !purego
77

8-
// Package subtle implements functions that are often useful in cryptographic
9-
// code but require careful thought to use correctly.
10-
package subtle // import "golang.org/x/crypto/internal/subtle"
8+
// Package alias implements memory aliasing tests.
9+
package alias
1110

1211
import "unsafe"
1312

internal/subtle/aliasing_purego.go internal/alias/alias_purego.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
//go:build purego
66
// +build purego
77

8-
// Package subtle implements functions that are often useful in cryptographic
9-
// code but require careful thought to use correctly.
10-
package subtle // import "golang.org/x/crypto/internal/subtle"
8+
// Package alias implements memory aliasing tests.
9+
package alias
1110

1211
// This is the Google App Engine standard variant based on reflect
1312
// because the unsafe package and cgo are disallowed.

internal/subtle/aliasing_test.go internal/alias/alias_test.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package subtle_test
5+
package alias
66

7-
import (
8-
"testing"
9-
10-
"golang.org/x/crypto/internal/subtle"
11-
)
7+
import "testing"
128

139
var a, b [100]byte
1410

@@ -32,11 +28,11 @@ var aliasingTests = []struct {
3228
}
3329

3430
func testAliasing(t *testing.T, i int, x, y []byte, anyOverlap, inexactOverlap bool) {
35-
any := subtle.AnyOverlap(x, y)
31+
any := AnyOverlap(x, y)
3632
if any != anyOverlap {
3733
t.Errorf("%d: wrong AnyOverlap result, expected %v, got %v", i, anyOverlap, any)
3834
}
39-
inexact := subtle.InexactOverlap(x, y)
35+
inexact := InexactOverlap(x, y)
4036
if inexact != inexactOverlap {
4137
t.Errorf("%d: wrong InexactOverlap result, expected %v, got %v", i, inexactOverlap, any)
4238
}

nacl/secretbox/secretbox.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ This package is interoperable with NaCl: https://nacl.cr.yp.to/secretbox.html.
3535
package secretbox // import "golang.org/x/crypto/nacl/secretbox"
3636

3737
import (
38+
"golang.org/x/crypto/internal/alias"
3839
"golang.org/x/crypto/internal/poly1305"
39-
"golang.org/x/crypto/internal/subtle"
4040
"golang.org/x/crypto/salsa20/salsa"
4141
)
4242

@@ -88,7 +88,7 @@ func Seal(out, message []byte, nonce *[24]byte, key *[32]byte) []byte {
8888
copy(poly1305Key[:], firstBlock[:])
8989

9090
ret, out := sliceForAppend(out, len(message)+poly1305.TagSize)
91-
if subtle.AnyOverlap(out, message) {
91+
if alias.AnyOverlap(out, message) {
9292
panic("nacl: invalid buffer overlap")
9393
}
9494

@@ -147,7 +147,7 @@ func Open(out, box []byte, nonce *[24]byte, key *[32]byte) ([]byte, bool) {
147147
}
148148

149149
ret, out := sliceForAppend(out, len(box)-Overhead)
150-
if subtle.AnyOverlap(out, box) {
150+
if alias.AnyOverlap(out, box) {
151151
panic("nacl: invalid buffer overlap")
152152
}
153153

nacl/sign/sign.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"io"
2525

2626
"golang.org/x/crypto/ed25519"
27-
"golang.org/x/crypto/internal/subtle"
27+
"golang.org/x/crypto/internal/alias"
2828
)
2929

3030
// Overhead is the number of bytes of overhead when signing a message.
@@ -48,7 +48,7 @@ func GenerateKey(rand io.Reader) (publicKey *[32]byte, privateKey *[64]byte, err
4848
func Sign(out, message []byte, privateKey *[64]byte) []byte {
4949
sig := ed25519.Sign(ed25519.PrivateKey((*privateKey)[:]), message)
5050
ret, out := sliceForAppend(out, Overhead+len(message))
51-
if subtle.AnyOverlap(out, message) {
51+
if alias.AnyOverlap(out, message) {
5252
panic("nacl: invalid buffer overlap")
5353
}
5454
copy(out, sig)
@@ -67,7 +67,7 @@ func Open(out, signedMessage []byte, publicKey *[32]byte) ([]byte, bool) {
6767
return nil, false
6868
}
6969
ret, out := sliceForAppend(out, len(signedMessage)-Overhead)
70-
if subtle.AnyOverlap(out, signedMessage) {
70+
if alias.AnyOverlap(out, signedMessage) {
7171
panic("nacl: invalid buffer overlap")
7272
}
7373
copy(out, signedMessage[Overhead:])

salsa20/salsa20.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ package salsa20 // import "golang.org/x/crypto/salsa20"
2424
// TODO(agl): implement XORKeyStream12 and XORKeyStream8 - the reduced round variants of Salsa20.
2525

2626
import (
27-
"golang.org/x/crypto/internal/subtle"
27+
"golang.org/x/crypto/internal/alias"
2828
"golang.org/x/crypto/salsa20/salsa"
2929
)
3030

@@ -35,7 +35,7 @@ func XORKeyStream(out, in []byte, nonce []byte, key *[32]byte) {
3535
if len(out) < len(in) {
3636
panic("salsa20: output smaller than input")
3737
}
38-
if subtle.InexactOverlap(out[:len(in)], in) {
38+
if alias.InexactOverlap(out[:len(in)], in) {
3939
panic("salsa20: invalid buffer overlap")
4040
}
4141

xts/xts.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"errors"
3030
"sync"
3131

32-
"golang.org/x/crypto/internal/subtle"
32+
"golang.org/x/crypto/internal/alias"
3333
)
3434

3535
// Cipher contains an expanded key structure. It is safe for concurrent use if
@@ -75,7 +75,7 @@ func (c *Cipher) Encrypt(ciphertext, plaintext []byte, sectorNum uint64) {
7575
if len(plaintext)%blockSize != 0 {
7676
panic("xts: plaintext is not a multiple of the block size")
7777
}
78-
if subtle.InexactOverlap(ciphertext[:len(plaintext)], plaintext) {
78+
if alias.InexactOverlap(ciphertext[:len(plaintext)], plaintext) {
7979
panic("xts: invalid buffer overlap")
8080
}
8181

@@ -114,7 +114,7 @@ func (c *Cipher) Decrypt(plaintext, ciphertext []byte, sectorNum uint64) {
114114
if len(ciphertext)%blockSize != 0 {
115115
panic("xts: ciphertext is not a multiple of the block size")
116116
}
117-
if subtle.InexactOverlap(plaintext[:len(ciphertext)], ciphertext) {
117+
if alias.InexactOverlap(plaintext[:len(ciphertext)], ciphertext) {
118118
panic("xts: invalid buffer overlap")
119119
}
120120

0 commit comments

Comments
 (0)