blamka_amd64.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2017 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. //go:build amd64 && gc && !purego
  5. // +build amd64,gc,!purego
  6. package argon2
  7. import "golang.org/x/sys/cpu"
  8. func init() {
  9. useSSE4 = cpu.X86.HasSSE41
  10. }
  11. //go:noescape
  12. func mixBlocksSSE2(out, a, b, c *block)
  13. //go:noescape
  14. func xorBlocksSSE2(out, a, b, c *block)
  15. //go:noescape
  16. func blamkaSSE4(b *block)
  17. func processBlockSSE(out, in1, in2 *block, xor bool) {
  18. var t block
  19. mixBlocksSSE2(&t, in1, in2, &t)
  20. if useSSE4 {
  21. blamkaSSE4(&t)
  22. } else {
  23. for i := 0; i < blockLength; i += 16 {
  24. blamkaGeneric(
  25. &t[i+0], &t[i+1], &t[i+2], &t[i+3],
  26. &t[i+4], &t[i+5], &t[i+6], &t[i+7],
  27. &t[i+8], &t[i+9], &t[i+10], &t[i+11],
  28. &t[i+12], &t[i+13], &t[i+14], &t[i+15],
  29. )
  30. }
  31. for i := 0; i < blockLength/8; i += 2 {
  32. blamkaGeneric(
  33. &t[i], &t[i+1], &t[16+i], &t[16+i+1],
  34. &t[32+i], &t[32+i+1], &t[48+i], &t[48+i+1],
  35. &t[64+i], &t[64+i+1], &t[80+i], &t[80+i+1],
  36. &t[96+i], &t[96+i+1], &t[112+i], &t[112+i+1],
  37. )
  38. }
  39. }
  40. if xor {
  41. xorBlocksSSE2(out, in1, in2, &t)
  42. } else {
  43. mixBlocksSSE2(out, in1, in2, &t)
  44. }
  45. }
  46. func processBlock(out, in1, in2 *block) {
  47. processBlockSSE(out, in1, in2, false)
  48. }
  49. func processBlockXOR(out, in1, in2 *block) {
  50. processBlockSSE(out, in1, in2, true)
  51. }