chacha20_amd64.go 936 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // chacha20_amd64.go - AMD64 optimized chacha20.
  2. //
  3. // To the extent possible under law, Yawning Angel has waived all copyright
  4. // and related or neighboring rights to chacha20, using the Creative
  5. // Commons "CC0" public domain dedication. See LICENSE or
  6. // <http://creativecommons.org/publicdomain/zero/1.0/> for full details.
  7. // +build amd64,!gccgo,!appengine
  8. package chacha20
  9. import (
  10. "math"
  11. )
  12. func blocksAmd64SSE2(x *uint32, in, out *byte, nrBlocks uint)
  13. func blocksAmd64(x *[stateSize]uint32, in []byte, out []byte, nrBlocks int, isIetf bool) {
  14. if isIetf {
  15. var totalBlocks uint64
  16. totalBlocks = uint64(x[8]) + uint64(nrBlocks)
  17. if totalBlocks > math.MaxUint32 {
  18. panic("chacha20: Exceeded keystream per nonce limit")
  19. }
  20. }
  21. if in == nil {
  22. for i := range out {
  23. out[i] = 0
  24. }
  25. in = out
  26. }
  27. blocksAmd64SSE2(&x[0], &in[0], &out[0], uint(nrBlocks))
  28. }
  29. func init() {
  30. blocksFn = blocksAmd64
  31. usingVectors = true
  32. }