You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sum_s390x.go 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. import (
  7. "golang.org/x/sys/cpu"
  8. )
  9. // poly1305vx is an assembly implementation of Poly1305 that uses vector
  10. // instructions. It must only be called if the vector facility (vx) is
  11. // available.
  12. //go:noescape
  13. func poly1305vx(out *[16]byte, m *byte, mlen uint64, key *[32]byte)
  14. // poly1305vmsl is an assembly implementation of Poly1305 that uses vector
  15. // instructions, including VMSL. It must only be called if the vector facility (vx) is
  16. // available and if VMSL is supported.
  17. //go:noescape
  18. func poly1305vmsl(out *[16]byte, m *byte, mlen uint64, key *[32]byte)
  19. // Sum generates an authenticator for m using a one-time key and puts the
  20. // 16-byte result into out. Authenticating two different messages with the same
  21. // key allows an attacker to forge messages at will.
  22. func Sum(out *[16]byte, m []byte, key *[32]byte) {
  23. if cpu.S390X.HasVX {
  24. var mPtr *byte
  25. if len(m) > 0 {
  26. mPtr = &m[0]
  27. }
  28. if cpu.S390X.HasVXE && len(m) > 256 {
  29. poly1305vmsl(out, mPtr, uint64(len(m)), key)
  30. } else {
  31. poly1305vx(out, mPtr, uint64(len(m)), key)
  32. }
  33. } else {
  34. sumGeneric(out, m, key)
  35. }
  36. }