Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

36 строки
1.4 KiB

  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. // +build appengine
  5. // Package subtle implements functions that are often useful in cryptographic
  6. // code but require careful thought to use correctly.
  7. package subtle // import "golang.org/x/crypto/internal/subtle"
  8. // This is the Google App Engine standard variant based on reflect
  9. // because the unsafe package and cgo are disallowed.
  10. import "reflect"
  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. reflect.ValueOf(&x[0]).Pointer() <= reflect.ValueOf(&y[len(y)-1]).Pointer() &&
  16. reflect.ValueOf(&y[0]).Pointer() <= reflect.ValueOf(&x[len(x)-1]).Pointer()
  17. }
  18. // InexactOverlap reports whether x and y share memory at any non-corresponding
  19. // index. The memory beyond the slice length is ignored. Note that x and y can
  20. // have different lengths and still not have any inexact overlap.
  21. //
  22. // InexactOverlap can be used to implement the requirements of the crypto/cipher
  23. // AEAD, Block, BlockMode and Stream interfaces.
  24. func InexactOverlap(x, y []byte) bool {
  25. if len(x) == 0 || len(y) == 0 || &x[0] == &y[0] {
  26. return false
  27. }
  28. return AnyOverlap(x, y)
  29. }