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.

82 lines
2.1 KiB

  1. /*
  2. This file contains the byte & uint64 implementations that are used as reference
  3. to test the bits implementations of the other files.
  4. The methods in this file are modifyied versions of methods from: https://github.com/ebfe/keccak
  5. */
  6. package keccak
  7. func thetaU64Version(a [25]uint64) [25]uint64 {
  8. var c0, c1, c2, c3, c4, d uint64
  9. var r [25]uint64
  10. c0 = a[0] ^ a[5] ^ a[10] ^ a[15] ^ a[20]
  11. c1 = a[1] ^ a[6] ^ a[11] ^ a[16] ^ a[21]
  12. c2 = a[2] ^ a[7] ^ a[12] ^ a[17] ^ a[22]
  13. c3 = a[3] ^ a[8] ^ a[13] ^ a[18] ^ a[23]
  14. c4 = a[4] ^ a[9] ^ a[14] ^ a[19] ^ a[24]
  15. d = c4 ^ (c1<<1 | c1>>(64-1))
  16. r[0] = a[0] ^ d
  17. r[5] = a[5] ^ d
  18. r[10] = a[10] ^ d
  19. r[15] = a[15] ^ d
  20. r[20] = a[20] ^ d
  21. d = c0 ^ (c2<<1 | c2>>(64-1))
  22. r[1] = a[1] ^ d
  23. r[6] = a[6] ^ d
  24. r[11] = a[11] ^ d
  25. r[16] = a[16] ^ d
  26. r[21] = a[21] ^ d
  27. d = c1 ^ (c3<<1 | c3>>(64-1))
  28. r[2] = a[2] ^ d
  29. r[7] = a[7] ^ d
  30. r[12] = a[12] ^ d
  31. r[17] = a[17] ^ d
  32. r[22] = a[22] ^ d
  33. d = c2 ^ (c4<<1 | c4>>(64-1))
  34. r[3] = a[3] ^ d
  35. r[8] = a[8] ^ d
  36. r[13] = a[13] ^ d
  37. r[18] = a[18] ^ d
  38. r[23] = a[23] ^ d
  39. d = c3 ^ (c0<<1 | c0>>(64-1))
  40. r[4] = a[4] ^ d
  41. r[9] = a[9] ^ d
  42. r[14] = a[14] ^ d
  43. r[19] = a[19] ^ d
  44. r[24] = a[24] ^ d
  45. return r
  46. }
  47. func rhopiU64Version(a [25]uint64) [25]uint64 {
  48. var t uint64
  49. t = a[1]
  50. t, a[10] = a[10], t<<1|t>>(64-1)
  51. t, a[7] = a[7], t<<3|t>>(64-3)
  52. t, a[11] = a[11], t<<6|t>>(64-6)
  53. t, a[17] = a[17], t<<10|t>>(64-10)
  54. t, a[18] = a[18], t<<15|t>>(64-15)
  55. t, a[3] = a[3], t<<21|t>>(64-21)
  56. t, a[5] = a[5], t<<28|t>>(64-28)
  57. t, a[16] = a[16], t<<36|t>>(64-36)
  58. t, a[8] = a[8], t<<45|t>>(64-45)
  59. t, a[21] = a[21], t<<55|t>>(64-55)
  60. t, a[24] = a[24], t<<2|t>>(64-2)
  61. t, a[4] = a[4], t<<14|t>>(64-14)
  62. t, a[15] = a[15], t<<27|t>>(64-27)
  63. t, a[23] = a[23], t<<41|t>>(64-41)
  64. t, a[19] = a[19], t<<56|t>>(64-56)
  65. t, a[13] = a[13], t<<8|t>>(64-8)
  66. t, a[12] = a[12], t<<25|t>>(64-25)
  67. t, a[2] = a[2], t<<43|t>>(64-43)
  68. t, a[20] = a[20], t<<62|t>>(64-62)
  69. t, a[14] = a[14], t<<18|t>>(64-18)
  70. t, a[22] = a[22], t<<39|t>>(64-39)
  71. t, a[9] = a[9], t<<61|t>>(64-61)
  72. t, a[6] = a[6], t<<20|t>>(64-20)
  73. a[1] = t<<44 | t>>(64-44)
  74. return a
  75. }