Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fe20b73

Browse files
committed
crypto/internal/boring: Use alias.InexactOverlap
Signed-off-by: aimuz <mr.imuz@gmail.com>
1 parent ad6ee21 commit fe20b73

File tree

1 file changed

+7
-19
lines changed
  • src/crypto/internal/boring

1 file changed

+7
-19
lines changed

‎src/crypto/internal/boring/aes.go

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import "C"
4646
import (
4747
"bytes"
4848
"crypto/cipher"
49+
"crypto/internal/alias"
4950
"errors"
5051
"runtime"
5152
"strconv"
@@ -89,7 +90,7 @@ func NewAESCipher(key []byte) (cipher.Block, error) {
8990
func (c *aesCipher) BlockSize() int { return aesBlockSize }
9091

9192
func (c *aesCipher) Encrypt(dst, src []byte) {
92-
if inexactOverlap(dst, src) {
93+
if alias.InexactOverlap(dst, src) {
9394
panic("crypto/cipher: invalid buffer overlap")
9495
}
9596
if len(src) < aesBlockSize {
@@ -105,7 +106,7 @@ func (c *aesCipher) Encrypt(dst, src []byte) {
105106
}
106107

107108
func (c *aesCipher) Decrypt(dst, src []byte) {
108-
if inexactOverlap(dst, src) {
109+
if alias.InexactOverlap(dst, src) {
109110
panic("crypto/cipher: invalid buffer overlap")
110111
}
111112
if len(src) < aesBlockSize {
@@ -129,7 +130,7 @@ type aesCBC struct {
129130
func (x *aesCBC) BlockSize() int { return aesBlockSize }
130131

131132
func (x *aesCBC) CryptBlocks(dst, src []byte) {
132-
if inexactOverlap(dst, src) {
133+
if alias.InexactOverlap(dst, src) {
133134
panic("crypto/cipher: invalid buffer overlap")
134135
}
135136
if len(src)%aesBlockSize != 0 {
@@ -174,7 +175,7 @@ type aesCTR struct {
174175
}
175176

176177
func (x *aesCTR) XORKeyStream(dst, src []byte) {
177-
if inexactOverlap(dst, src) {
178+
if alias.InexactOverlap(dst, src) {
178179
panic("crypto/cipher: invalid buffer overlap")
179180
}
180181
if len(dst) < len(src) {
@@ -329,7 +330,7 @@ func (g *aesGCM) Seal(dst, nonce, plaintext, additionalData []byte) []byte {
329330
dst = dst[:n+len(plaintext)+gcmTagSize]
330331

331332
// Check delayed until now to make sure len(dst) is accurate.
332-
if inexactOverlap(dst[n:], plaintext) {
333+
if alias.InexactOverlap(dst[n:], plaintext) {
333334
panic("cipher: invalid buffer overlap")
334335
}
335336

@@ -368,7 +369,7 @@ func (g *aesGCM) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, er
368369
dst = dst[:n+len(ciphertext)-gcmTagSize]
369370

370371
// Check delayed until now to make sure len(dst) is accurate.
371-
if inexactOverlap(dst[n:], ciphertext) {
372+
if alias.InexactOverlap(dst[n:], ciphertext) {
372373
panic("cipher: invalid buffer overlap")
373374
}
374375

@@ -385,16 +386,3 @@ func (g *aesGCM) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, er
385386
}
386387
return dst[:n+int(outLen)], nil
387388
}
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /