diff options
author | sina <sina@snix.ir> | 2022-07-30 19:04:32 +0430 |
---|---|---|
committer | sina <sina@snix.ir> | 2022-07-30 19:04:32 +0430 |
commit | 106aa62c63960c7931e4f811923250e9f4e48f8b (patch) | |
tree | aba0877860baa6bdb8bf9f7834203820f6bd6d1e | |
parent | 4caa361dfd77f64b5ea87703069544d51ea66387 (diff) |
overlaps
-rw-r--r-- | applap.go | 18 | ||||
-rw-r--r-- | cipher.go | 8 | ||||
-rw-r--r-- | genlap.go | 18 |
3 files changed, 4 insertions, 40 deletions
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) -} @@ -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) -} |