@@ -46,6 +46,7 @@ import "C"
46
46
import (
47
47
"bytes"
48
48
"crypto/cipher"
49
+ "crypto/internal/alias"
49
50
"errors"
50
51
"runtime"
51
52
"strconv"
@@ -89,7 +90,7 @@ func NewAESCipher(key []byte) (cipher.Block, error) {
89
90
func (c * aesCipher ) BlockSize () int { return aesBlockSize }
90
91
91
92
func (c * aesCipher ) Encrypt (dst , src []byte ) {
92
- if inexactOverlap (dst , src ) {
93
+ if alias . InexactOverlap (dst , src ) {
93
94
panic ("crypto/cipher: invalid buffer overlap" )
94
95
}
95
96
if len (src ) < aesBlockSize {
@@ -105,7 +106,7 @@ func (c *aesCipher) Encrypt(dst, src []byte) {
105
106
}
106
107
107
108
func (c * aesCipher ) Decrypt (dst , src []byte ) {
108
- if inexactOverlap (dst , src ) {
109
+ if alias . InexactOverlap (dst , src ) {
109
110
panic ("crypto/cipher: invalid buffer overlap" )
110
111
}
111
112
if len (src ) < aesBlockSize {
@@ -129,7 +130,7 @@ type aesCBC struct {
129
130
func (x * aesCBC ) BlockSize () int { return aesBlockSize }
130
131
131
132
func (x * aesCBC ) CryptBlocks (dst , src []byte ) {
132
- if inexactOverlap (dst , src ) {
133
+ if alias . InexactOverlap (dst , src ) {
133
134
panic ("crypto/cipher: invalid buffer overlap" )
134
135
}
135
136
if len (src )% aesBlockSize != 0 {
@@ -174,7 +175,7 @@ type aesCTR struct {
174
175
}
175
176
176
177
func (x * aesCTR ) XORKeyStream (dst , src []byte ) {
177
- if inexactOverlap (dst , src ) {
178
+ if alias . InexactOverlap (dst , src ) {
178
179
panic ("crypto/cipher: invalid buffer overlap" )
179
180
}
180
181
if len (dst ) < len (src ) {
@@ -329,7 +330,7 @@ func (g *aesGCM) Seal(dst, nonce, plaintext, additionalData []byte) []byte {
329
330
dst = dst [:n + len (plaintext )+ gcmTagSize ]
330
331
331
332
// Check delayed until now to make sure len(dst) is accurate.
332
- if inexactOverlap (dst [n :], plaintext ) {
333
+ if alias . InexactOverlap (dst [n :], plaintext ) {
333
334
panic ("cipher: invalid buffer overlap" )
334
335
}
335
336
@@ -368,7 +369,7 @@ func (g *aesGCM) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, er
368
369
dst = dst [:n + len (ciphertext )- gcmTagSize ]
369
370
370
371
// Check delayed until now to make sure len(dst) is accurate.
371
- if inexactOverlap (dst [n :], ciphertext ) {
372
+ if alias . InexactOverlap (dst [n :], ciphertext ) {
372
373
panic ("cipher: invalid buffer overlap" )
373
374
}
374
375
@@ -385,16 +386,3 @@ func (g *aesGCM) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, er
385
386
}
386
387
return dst [:n + int (outLen )], nil
387
388
}
388
-
389
- func anyOverlap (x , y []byte ) bool {
390
- return len (x ) > 0 && len (y ) > 0 &&
391
- uintptr (unsafe .Pointer (& x [0 ])) <= uintptr (unsafe .Pointer (& y [len (y )- 1 ])) &&
392
- uintptr (unsafe .Pointer (& y [0 ])) <= uintptr (unsafe .Pointer (& x [len (x )- 1 ]))
393
- }
394
-
395
- func inexactOverlap (x , y []byte ) bool {
396
- if len (x ) == 0 || len (y ) == 0 || & x [0 ] == & y [0 ] {
397
- return false
398
- }
399
- return anyOverlap (x , y )
400
- }
0 commit comments