gitee.com/curryzheng/dm@v0.0.1/security/zz.go (about) 1 /* 2 * Copyright (c) 2000-2018, 达梦数据库有限公司. 3 * All rights reserved. 4 */ 5 6 // This is a mirror of golang.org/x/crypto/internal/subtle. 7 package security 8 9 import "unsafe" 10 11 // AnyOverlap reports whether x and y share memory at any (not necessarily 12 // corresponding) index. The memory beyond the slice length is ignored. 13 func AnyOverlap(x, y []byte) bool { 14 return len(x) > 0 && len(y) > 0 && 15 uintptr(unsafe.Pointer(&x[0])) <= uintptr(unsafe.Pointer(&y[len(y)-1])) && 16 uintptr(unsafe.Pointer(&y[0])) <= uintptr(unsafe.Pointer(&x[len(x)-1])) 17 } 18 19 // InexactOverlap reports whether x and y share memory at any non-corresponding 20 // index. The memory beyond the slice length is ignored. Note that x and y can 21 // have different lengths and still not have any inexact overlap. 22 // 23 // InexactOverlap can be used to implement the requirements of the crypto/cipher 24 // AEAD, Block, BlockMode and Stream interfaces. 25 func InexactOverlap(x, y []byte) bool { 26 if len(x) == 0 || len(y) == 0 || &x[0] == &y[0] { 27 return false 28 } 29 return AnyOverlap(x, y) 30 }