From 44e774416bc600f787276d938986089f3a1f2e98 Mon Sep 17 00:00:00 2001 From: aimuz Date: Fri, 13 Sep 2024 15:29:14 +0800 Subject: [PATCH] crypto/internal/boring: Use alias.InexactOverlap Signed-off-by: aimuz --- src/crypto/internal/boring/aes.go | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/crypto/internal/boring/aes.go b/src/crypto/internal/boring/aes.go index d18ed5cdc5c25..14f964e89be6c 100644 --- a/src/crypto/internal/boring/aes.go +++ b/src/crypto/internal/boring/aes.go @@ -46,6 +46,7 @@ import "C" import ( "bytes" "crypto/cipher" + "crypto/internal/alias" "errors" "runtime" "strconv" @@ -368,7 +369,7 @@ func (g *aesGCM) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, er dst = dst[:n+len(ciphertext)-gcmTagSize] // Check delayed until now to make sure len(dst) is accurate. - if inexactOverlap(dst[n:], ciphertext) { + if alias.InexactOverlap(dst[n:], ciphertext) { panic("cipher: invalid buffer overlap") } @@ -385,16 +386,3 @@ func (g *aesGCM) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, er } return dst[:n+int(outLen)], nil } - -func anyOverlap(x, y []byte) bool { - return len(x) > 0 && len(y) > 0 && - uintptr(unsafe.Pointer(&x[0])) <= uintptr(unsafe.Pointer(&y[len(y)-1])) && - uintptr(unsafe.Pointer(&y[0])) <= uintptr(unsafe.Pointer(&x[len(x)-1])) -} - -func inexactOverlap(x, y []byte) bool { - if len(x) == 0 || len(y) == 0 || &x[0] == &y[0] { - return false - } - return anyOverlap(x, y) -}