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

50 строки
1.5 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 s390x,go1.11,!gccgo,!appengine
  5. package poly1305
  6. // hasVectorFacility reports whether the machine supports
  7. // the vector facility (vx).
  8. func hasVectorFacility() bool
  9. // hasVMSLFacility reports whether the machine supports
  10. // Vector Multiply Sum Logical (VMSL).
  11. func hasVMSLFacility() bool
  12. var hasVX = hasVectorFacility()
  13. var hasVMSL = hasVMSLFacility()
  14. // poly1305vx is an assembly implementation of Poly1305 that uses vector
  15. // instructions. It must only be called if the vector facility (vx) is
  16. // available.
  17. //go:noescape
  18. func poly1305vx(out *[16]byte, m *byte, mlen uint64, key *[32]byte)
  19. // poly1305vmsl is an assembly implementation of Poly1305 that uses vector
  20. // instructions, including VMSL. It must only be called if the vector facility (vx) is
  21. // available and if VMSL is supported.
  22. //go:noescape
  23. func poly1305vmsl(out *[16]byte, m *byte, mlen uint64, key *[32]byte)
  24. // Sum generates an authenticator for m using a one-time key and puts the
  25. // 16-byte result into out. Authenticating two different messages with the same
  26. // key allows an attacker to forge messages at will.
  27. func Sum(out *[16]byte, m []byte, key *[32]byte) {
  28. if hasVX {
  29. var mPtr *byte
  30. if len(m) > 0 {
  31. mPtr = &m[0]
  32. }
  33. if hasVMSL && len(m) > 256 {
  34. poly1305vmsl(out, mPtr, uint64(len(m)), key)
  35. } else {
  36. poly1305vx(out, mPtr, uint64(len(m)), key)
  37. }
  38. } else {
  39. sumGeneric(out, m, key)
  40. }
  41. }