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.

59 lines
1.3 KiB

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