From 106aa62c63960c7931e4f811923250e9f4e48f8b Mon Sep 17 00:00:00 2001 From: sina Date: Sat, 30 Jul 2022 19:04:32 +0430 Subject: overlaps --- applap.go | 18 ------------------ cipher.go | 8 ++++---- genlap.go | 18 ------------------ 3 files changed, 4 insertions(+), 40 deletions(-) delete mode 100644 applap.go delete mode 100644 genlap.go diff --git a/applap.go b/applap.go deleted file mode 100644 index 9d7f7c7..0000000 --- a/applap.go +++ /dev/null @@ -1,18 +0,0 @@ -//go:build purego - -package rabaead - -import "reflect" - -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() -} - -func inexactOverlap(x, y []byte) bool { - if len(x) == 0 || len(y) == 0 || &x[0] == &y[0] { - return false - } - return anyOverlap(x, y) -} diff --git a/cipher.go b/cipher.go index 89441c3..278172d 100644 --- a/cipher.go +++ b/cipher.go @@ -44,8 +44,8 @@ func (c *rabbitPoly1305) NonceSize() int { return c.noncesize } func (c *rabbitPoly1305) sealRabbit(dst, nonce, plaintext, ad []byte) []byte { ret, out := headtail(dst, len(plaintext)+poly1305.TagSize) ciphertext, tag := out[:len(plaintext)], out[len(plaintext):] - if inexactOverlap(out, plaintext) { - panic("rabaead: invalid buffer memory overlap") //should never happen + if rabbitio.InexactOverlap(out, plaintext) { + panic("rabaead: invalid buffer memory overlap") } var polyKey [polykeylen]byte @@ -91,8 +91,8 @@ func (c *rabbitPoly1305) openRabbit(dst, nonce, ciphertext, ad []byte) ([]byte, writeUint64(p, len(ciphertext)) ret, out := headtail(dst, len(ciphertext)) - if inexactOverlap(out, ciphertext) { - panic("rabaead: invalid buffer memory overlap") //should never happen + if rabbitio.InexactOverlap(out, ciphertext) { + panic("rabaead: invalid buffer memory overlap") } // check data integrity diff --git a/genlap.go b/genlap.go deleted file mode 100644 index b63fb57..0000000 --- a/genlap.go +++ /dev/null @@ -1,18 +0,0 @@ -//go:build !purego - -package rabaead - -import "unsafe" - -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) -} -- cgit v1.2.3