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.

137 lines
3.0 KiB

3 years ago
  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. }
  76. func chiU64Version(a [25]uint64) [25]uint64 {
  77. var bc0, bc1, bc2, bc3, bc4 uint64
  78. bc0 = a[0]
  79. bc1 = a[1]
  80. bc2 = a[2]
  81. bc3 = a[3]
  82. bc4 = a[4]
  83. a[0] ^= (^bc1) & bc2
  84. a[1] ^= (^bc2) & bc3
  85. a[2] ^= (^bc3) & bc4
  86. a[3] ^= (^bc4) & bc0
  87. a[4] ^= (^bc0) & bc1
  88. bc0 = a[5]
  89. bc1 = a[6]
  90. bc2 = a[7]
  91. bc3 = a[8]
  92. bc4 = a[9]
  93. a[5] ^= (^bc1) & bc2
  94. a[6] ^= (^bc2) & bc3
  95. a[7] ^= (^bc3) & bc4
  96. a[8] ^= (^bc4) & bc0
  97. a[9] ^= (^bc0) & bc1
  98. bc0 = a[10]
  99. bc1 = a[11]
  100. bc2 = a[12]
  101. bc3 = a[13]
  102. bc4 = a[14]
  103. a[10] ^= (^bc1) & bc2
  104. a[11] ^= (^bc2) & bc3
  105. a[12] ^= (^bc3) & bc4
  106. a[13] ^= (^bc4) & bc0
  107. a[14] ^= (^bc0) & bc1
  108. bc0 = a[15]
  109. bc1 = a[16]
  110. bc2 = a[17]
  111. bc3 = a[18]
  112. bc4 = a[19]
  113. a[15] ^= (^bc1) & bc2
  114. a[16] ^= (^bc2) & bc3
  115. a[17] ^= (^bc3) & bc4
  116. a[18] ^= (^bc4) & bc0
  117. a[19] ^= (^bc0) & bc1
  118. bc0 = a[20]
  119. bc1 = a[21]
  120. bc2 = a[22]
  121. bc3 = a[23]
  122. bc4 = a[24]
  123. a[20] ^= (^bc1) & bc2
  124. a[21] ^= (^bc2) & bc3
  125. a[22] ^= (^bc3) & bc4
  126. a[23] ^= (^bc4) & bc0
  127. a[24] ^= (^bc0) & bc1
  128. return a
  129. }