本站源代码
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.

61 lines
1.3KB

  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. // +build amd64,!gccgo,!appengine
  5. package argon2
  6. import "golang.org/x/sys/cpu"
  7. func init() {
  8. useSSE4 = cpu.X86.HasSSE41
  9. }
  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. }
上海开阖软件有限公司 沪ICP备12045867号-1