"Fossies" - the Fresh Open Source Software Archive

Member "buildah-1.23.1/vendor/golang.org/x/crypto/internal/subtle/aliasing_purego.go" (28 Sep 2021, 1407 Bytes) of package /linux/misc/buildah-1.23.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright 2018 The Go Authors. All rights reserved.
    2 // Use of this source code is governed by a BSD-style
    3 // license that can be found in the LICENSE file.
    4 
    5 //go:build purego
    6 // +build purego
    7 
    8 // Package subtle implements functions that are often useful in cryptographic
    9 // code but require careful thought to use correctly.
   10 package subtle // import "golang.org/x/crypto/internal/subtle"
   11 
   12 // This is the Google App Engine standard variant based on reflect
   13 // because the unsafe package and cgo are disallowed.
   14 
   15 import "reflect"
   16 
   17 // AnyOverlap reports whether x and y share memory at any (not necessarily
   18 // corresponding) index. The memory beyond the slice length is ignored.
   19 func AnyOverlap(x, y []byte) bool {
   20     return len(x) > 0 && len(y) > 0 &&
   21         reflect.ValueOf(&x[0]).Pointer() <= reflect.ValueOf(&y[len(y)-1]).Pointer() &&
   22         reflect.ValueOf(&y[0]).Pointer() <= reflect.ValueOf(&x[len(x)-1]).Pointer()
   23 }
   24 
   25 // InexactOverlap reports whether x and y share memory at any non-corresponding
   26 // index. The memory beyond the slice length is ignored. Note that x and y can
   27 // have different lengths and still not have any inexact overlap.
   28 //
   29 // InexactOverlap can be used to implement the requirements of the crypto/cipher
   30 // AEAD, Block, BlockMode and Stream interfaces.
   31 func InexactOverlap(x, y []byte) bool {
   32     if len(x) == 0 || len(y) == 0 || &x[0] == &y[0] {
   33         return false
   34     }
   35     return AnyOverlap(x, y)
   36 }