sha3-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +29 -0
  5. data/Rakefile +7 -0
  6. data/ext/sha3/KeccakReferenceAndOptimized/KeccakCompact.vcproj +207 -0
  7. data/ext/sha3/KeccakReferenceAndOptimized/KeccakCompact8.vcproj +207 -0
  8. data/ext/sha3/KeccakReferenceAndOptimized/KeccakInplace.vcproj +203 -0
  9. data/ext/sha3/KeccakReferenceAndOptimized/KeccakInplace32BI.vcproj +201 -0
  10. data/ext/sha3/KeccakReferenceAndOptimized/KeccakOptimized32.vcproj +267 -0
  11. data/ext/sha3/KeccakReferenceAndOptimized/KeccakOptimized64.vcproj +267 -0
  12. data/ext/sha3/KeccakReferenceAndOptimized/KeccakReference.vcproj +243 -0
  13. data/ext/sha3/KeccakReferenceAndOptimized/KeccakReference32BI.vcproj +243 -0
  14. data/ext/sha3/KeccakReferenceAndOptimized/KeccakReferenceAndOptimized.sln +62 -0
  15. data/ext/sha3/KeccakReferenceAndOptimized/KeccakSimple.vcproj +203 -0
  16. data/ext/sha3/KeccakReferenceAndOptimized/KeccakSimple32BI.vcproj +201 -0
  17. data/ext/sha3/KeccakReferenceAndOptimized/Sources/AVR8-rotate64.h +27 -0
  18. data/ext/sha3/KeccakReferenceAndOptimized/Sources/AVR8-rotate64.s +285 -0
  19. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-avr8-settings.h +2 -0
  20. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-avr8-test.c +142 -0
  21. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-avr8-util.h +15 -0
  22. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-avr8-util.s +119 -0
  23. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-avr8.c +184 -0
  24. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-avr8.h +25 -0
  25. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact-settings.h +3 -0
  26. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact-test.c +317 -0
  27. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact.c +341 -0
  28. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact.h +50 -0
  29. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact8-settings.h +2 -0
  30. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact8-test.c +192 -0
  31. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact8.c +375 -0
  32. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact8.h +47 -0
  33. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-crypto_hash-inplace-armgcc-ARMv7A-NEON.s +406 -0
  34. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace-minimal-test.c +231 -0
  35. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace-settings.h +3 -0
  36. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace-test.c +221 -0
  37. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace.c +445 -0
  38. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace32BI-armgcc-ARMv6M.s +844 -0
  39. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace32BI-armgcc-ARMv7A.s +687 -0
  40. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace32BI-armgcc-ARMv7M.s +687 -0
  41. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace32BI.c +849 -0
  42. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-simple-settings.h +3 -0
  43. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-simple-test.c +221 -0
  44. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-simple.c +403 -0
  45. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-simple32BI.c +673 -0
  46. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakDuplex.c +68 -0
  47. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakDuplex.h +59 -0
  48. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-32-rvk.macros +555 -0
  49. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-32-s1.macros +1187 -0
  50. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-32-s2.macros +1187 -0
  51. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-32.macros +26 -0
  52. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-64.macros +728 -0
  53. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-arm.c +123 -0
  54. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-armcc.s +653 -0
  55. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-armgcc.s +686 -0
  56. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-avr8.c +163 -0
  57. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-avr8asm-compact.s +647 -0
  58. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-avr8asm-fast.s +934 -0
  59. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-inplace-armgcc-ARMv7A-NEON.s +446 -0
  60. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-int-set.h +6 -0
  61. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-interface.h +46 -0
  62. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-opt32-settings.h +4 -0
  63. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-opt32.c +524 -0
  64. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-opt64-settings.h +7 -0
  65. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-opt64.c +504 -0
  66. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-reference.c +300 -0
  67. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-reference.h +20 -0
  68. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-reference.o +0 -0
  69. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-reference32BI.c +371 -0
  70. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-simd128.macros +651 -0
  71. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-simd64.macros +517 -0
  72. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-unrolling.macros +124 -0
  73. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-x86-64-asm.c +62 -0
  74. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-x86-64-gas.s +766 -0
  75. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-x86-64-shld-gas.s +766 -0
  76. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-xop.macros +573 -0
  77. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakNISTInterface.c +81 -0
  78. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakNISTInterface.h +70 -0
  79. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakNISTInterface.o +0 -0
  80. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakSponge.c +266 -0
  81. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakSponge.h +76 -0
  82. data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakSponge.o +0 -0
  83. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccakc1024-crypto_hash-inplace-armgcc-ARMv7A-NEON.s +296 -0
  84. data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccakc512-crypto_hash-inplace-armgcc-ARMv7A-NEON.s +429 -0
  85. data/ext/sha3/KeccakReferenceAndOptimized/Sources/brg_endian.h +142 -0
  86. data/ext/sha3/KeccakReferenceAndOptimized/Sources/crypto_hash.h +0 -0
  87. data/ext/sha3/KeccakReferenceAndOptimized/Sources/displayIntermediateValues.c +117 -0
  88. data/ext/sha3/KeccakReferenceAndOptimized/Sources/displayIntermediateValues.h +29 -0
  89. data/ext/sha3/KeccakReferenceAndOptimized/Sources/displayIntermediateValues.o +0 -0
  90. data/ext/sha3/KeccakReferenceAndOptimized/Sources/genKAT.c +692 -0
  91. data/ext/sha3/KeccakReferenceAndOptimized/Sources/mainARM.c +88 -0
  92. data/ext/sha3/KeccakReferenceAndOptimized/Sources/mainOptimized.c +23 -0
  93. data/ext/sha3/KeccakReferenceAndOptimized/Sources/mainReference.c +381 -0
  94. data/ext/sha3/KeccakReferenceAndOptimized/Sources/timing.c +436 -0
  95. data/ext/sha3/KeccakReferenceAndOptimized/Sources/timing.h +13 -0
  96. data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/DoublePermutation-config.h +2 -0
  97. data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/DoublePermutation.c +572 -0
  98. data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/DoublePermutation.h +38 -0
  99. data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/KeccakF-1600-unrolling.macros +124 -0
  100. data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/Keccakc256TreeD2.c +81 -0
  101. data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/Keccakc256TreeD2.h +18 -0
  102. data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/Keccakc512TreeD2.c +81 -0
  103. data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/Keccakc512TreeD2.h +18 -0
  104. data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/crypto_hash.h +0 -0
  105. data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/mainOptimized.c +112 -0
  106. data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/timing-Double.c +225 -0
  107. data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/timing-Double.h +20 -0
  108. data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/makefile +68 -0
  109. data/ext/sha3/KeccakReferenceAndOptimized/bin/KeccakCompact +0 -0
  110. data/ext/sha3/KeccakReferenceAndOptimized/bin/KeccakOptimized32 +0 -0
  111. data/ext/sha3/KeccakReferenceAndOptimized/bin/KeccakOptimized64 +0 -0
  112. data/ext/sha3/KeccakReferenceAndOptimized/bin/KeccakReference +0 -0
  113. data/ext/sha3/KeccakReferenceAndOptimized/bin/KeccakReference32BI +0 -0
  114. data/ext/sha3/KeccakReferenceAndOptimized/bin/KeccakSimple +0 -0
  115. data/ext/sha3/KeccakReferenceAndOptimized/bin/KeccakSimple32BI +0 -0
  116. data/ext/sha3/KeccakReferenceAndOptimized/bin/compact/Keccak-compact-test.o +0 -0
  117. data/ext/sha3/KeccakReferenceAndOptimized/bin/compact/Keccak-compact.o +0 -0
  118. data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized32/KeccakDuplex.o +0 -0
  119. data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized32/KeccakF-1600-opt32.o +0 -0
  120. data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized32/KeccakNISTInterface.o +0 -0
  121. data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized32/KeccakSponge.o +0 -0
  122. data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized32/genKAT.o +0 -0
  123. data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized32/mainOptimized.o +0 -0
  124. data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized32/timing.o +0 -0
  125. data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized64/KeccakDuplex.o +0 -0
  126. data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized64/KeccakF-1600-opt64.o +0 -0
  127. data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized64/KeccakNISTInterface.o +0 -0
  128. data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized64/KeccakSponge.o +0 -0
  129. data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized64/genKAT.o +0 -0
  130. data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized64/mainOptimized.o +0 -0
  131. data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized64/timing.o +0 -0
  132. data/ext/sha3/KeccakReferenceAndOptimized/bin/reference/KeccakDuplex.o +0 -0
  133. data/ext/sha3/KeccakReferenceAndOptimized/bin/reference/KeccakF-1600-reference.o +0 -0
  134. data/ext/sha3/KeccakReferenceAndOptimized/bin/reference/KeccakNISTInterface.o +0 -0
  135. data/ext/sha3/KeccakReferenceAndOptimized/bin/reference/KeccakSponge.o +0 -0
  136. data/ext/sha3/KeccakReferenceAndOptimized/bin/reference/displayIntermediateValues.o +0 -0
  137. data/ext/sha3/KeccakReferenceAndOptimized/bin/reference/genKAT.o +0 -0
  138. data/ext/sha3/KeccakReferenceAndOptimized/bin/reference/mainReference.o +0 -0
  139. data/ext/sha3/KeccakReferenceAndOptimized/bin/reference32bi/KeccakDuplex.o +0 -0
  140. data/ext/sha3/KeccakReferenceAndOptimized/bin/reference32bi/KeccakF-1600-reference32BI.o +0 -0
  141. data/ext/sha3/KeccakReferenceAndOptimized/bin/reference32bi/KeccakNISTInterface.o +0 -0
  142. data/ext/sha3/KeccakReferenceAndOptimized/bin/reference32bi/KeccakSponge.o +0 -0
  143. data/ext/sha3/KeccakReferenceAndOptimized/bin/reference32bi/displayIntermediateValues.o +0 -0
  144. data/ext/sha3/KeccakReferenceAndOptimized/bin/reference32bi/genKAT.o +0 -0
  145. data/ext/sha3/KeccakReferenceAndOptimized/bin/reference32bi/mainReference.o +0 -0
  146. data/ext/sha3/KeccakReferenceAndOptimized/bin/simple/Keccak-simple-test.o +0 -0
  147. data/ext/sha3/KeccakReferenceAndOptimized/bin/simple/Keccak-simple.o +0 -0
  148. data/ext/sha3/KeccakReferenceAndOptimized/bin/simple32BI/Keccak-simple-test.o +0 -0
  149. data/ext/sha3/KeccakReferenceAndOptimized/bin/simple32BI/Keccak-simple32BI.o +0 -0
  150. data/ext/sha3/KeccakReferenceAndOptimized/compile64.bat +1 -0
  151. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccak +1 -0
  152. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccakc1024 +1 -0
  153. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccakc256 +1 -0
  154. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccakc256treed2 +1 -0
  155. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccakc448 +1 -0
  156. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccakc512 +1 -0
  157. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccakc512treed2 +1 -0
  158. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccakc768 +1 -0
  159. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/hash-keccak.c +11 -0
  160. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/hash-keccakc1024.c +11 -0
  161. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/hash-keccakc256.c +11 -0
  162. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/hash-keccakc448.c +11 -0
  163. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/hash-keccakc512.c +11 -0
  164. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/hash-keccakc768.c +11 -0
  165. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/int-set-keccak.h +1 -0
  166. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/int-set-keccakc1024.h +1 -0
  167. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/int-set-keccakc256.h +1 -0
  168. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/int-set-keccakc448.h +1 -0
  169. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/int-set-keccakc512.h +1 -0
  170. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/int-set-keccakc768.h +1 -0
  171. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/populate.py +506 -0
  172. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/simple-keccak.h +2 -0
  173. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/simple-keccakc1024.h +2 -0
  174. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/simple-keccakc256.h +2 -0
  175. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/simple-keccakc448.h +2 -0
  176. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/simple-keccakc512.h +2 -0
  177. data/ext/sha3/KeccakReferenceAndOptimized/eBASH/simple-keccakc768.h +2 -0
  178. data/ext/sha3/KeccakReferenceAndOptimized/makefile +327 -0
  179. data/ext/sha3/Makefile +240 -0
  180. data/ext/sha3/depend +28 -0
  181. data/ext/sha3/extconf.rb +21 -0
  182. data/ext/sha3/sha3.c +95 -0
  183. data/lib/sha3-ruby.rb +27 -0
  184. data/lib/sha3-ruby/version.rb +5 -0
  185. data/sha3-ruby.gemspec +21 -0
  186. metadata +233 -0
@@ -0,0 +1,163 @@
1
+ /*
2
+ The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
3
+ Michaël Peeters and Gilles Van Assche. For more information, feedback or
4
+ questions, please refer to our website: http://keccak.noekeon.org/
5
+
6
+ Implementation by Ronny Van Keer,
7
+ hereby denoted as "the implementer".
8
+
9
+ To the extent possible under law, the implementer has waived all copyright
10
+ and related or neighboring rights to the source code in this file.
11
+ http://creativecommons.org/publicdomain/zero/1.0/
12
+ */
13
+
14
+ #include <string.h>
15
+ #include <avr/pgmspace.h>
16
+ #include "AVR8-rotate64.h"
17
+
18
+ typedef unsigned char UINT8;
19
+ typedef UINT8 tSmallUInt;
20
+ typedef unsigned long long UINT64;
21
+ typedef UINT64 tKeccakLane;
22
+
23
+ #define cKeccakLaneSizeInBits (sizeof(tKeccakLane) * 8)
24
+
25
+ #define cKeccakNumberOfRounds 24
26
+
27
+ static tKeccakLane KeccakF_RoundConstants[cKeccakNumberOfRounds] PROGMEM =
28
+ {
29
+ (tKeccakLane)0x0000000000000001ULL,
30
+ (tKeccakLane)0x0000000000008082ULL,
31
+ (tKeccakLane)0x800000000000808aULL,
32
+ (tKeccakLane)0x8000000080008000ULL,
33
+ (tKeccakLane)0x000000000000808bULL,
34
+ (tKeccakLane)0x0000000080000001ULL,
35
+ (tKeccakLane)0x8000000080008081ULL,
36
+ (tKeccakLane)0x8000000000008009ULL,
37
+ (tKeccakLane)0x000000000000008aULL,
38
+ (tKeccakLane)0x0000000000000088ULL,
39
+ (tKeccakLane)0x0000000080008009ULL,
40
+ (tKeccakLane)0x000000008000000aULL,
41
+ (tKeccakLane)0x000000008000808bULL,
42
+ (tKeccakLane)0x800000000000008bULL,
43
+ (tKeccakLane)0x8000000000008089ULL,
44
+ (tKeccakLane)0x8000000000008003ULL,
45
+ (tKeccakLane)0x8000000000008002ULL,
46
+ (tKeccakLane)0x8000000000000080ULL,
47
+ (tKeccakLane)0x000000000000800aULL,
48
+ (tKeccakLane)0x800000008000000aULL,
49
+ (tKeccakLane)0x8000000080008081ULL,
50
+ (tKeccakLane)0x8000000000008080ULL,
51
+ (tKeccakLane)0x0000000080000001ULL,
52
+ (tKeccakLane)0x8000000080008008ULL
53
+ };
54
+
55
+ static tSmallUInt KeccakF_RotationConstants[24] PROGMEM =
56
+ {
57
+ ROT_CODE( 1), ROT_CODE( 3), ROT_CODE( 6), ROT_CODE(10), ROT_CODE(15),
58
+ ROT_CODE(21), ROT_CODE(28), ROT_CODE(36), ROT_CODE(45), ROT_CODE(55),
59
+ ROT_CODE( 2), ROT_CODE(14), ROT_CODE(27), ROT_CODE(41), ROT_CODE(56),
60
+ ROT_CODE( 8), ROT_CODE(25), ROT_CODE(43), ROT_CODE(62), ROT_CODE(18),
61
+ ROT_CODE(39), ROT_CODE(61), ROT_CODE(20), ROT_CODE(44)
62
+ };
63
+
64
+ static tSmallUInt KeccakF_PiLane[24] PROGMEM =
65
+ {
66
+ 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1
67
+ };
68
+
69
+ static tSmallUInt KeccakF_Mod5[10] PROGMEM =
70
+ {
71
+ 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
72
+ };
73
+
74
+
75
+ void KeccakF( tKeccakLane * state )
76
+ {
77
+ tSmallUInt round;
78
+ tKeccakLane C[5];
79
+
80
+ // prepare Theta
81
+ {
82
+ tSmallUInt x;
83
+ tKeccakLane * pC;
84
+ for ( x = 0, pC = C; x < 5; ++x, ++pC )
85
+ {
86
+ *pC = state[x] ^ state[5 + x] ^ state[10 + x] ^ state[15 + x] ^ state[20 + x];
87
+ }
88
+ }
89
+
90
+ for( round = 0; round < cKeccakNumberOfRounds; ++round )
91
+ {
92
+ // Theta
93
+ {
94
+ tSmallUInt x;
95
+ for ( x = 0; x < 5; ++x )
96
+ {
97
+ tKeccakLane temp;
98
+ tSmallUInt y;
99
+ temp = rotate64_1bit_left( C[pgm_read_byte((KeccakF_Mod5+1)+x)] );
100
+ temp ^= C[pgm_read_byte((KeccakF_Mod5+4)+x)];
101
+ for ( y = 0; y < 25; y += 5 )
102
+ {
103
+ state[y + x] ^= temp;
104
+ }
105
+ }
106
+ }
107
+
108
+ // Rho Pi
109
+ {
110
+ tKeccakLane temp;
111
+ tSmallUInt x;
112
+
113
+ temp = state[1];
114
+ for ( x = 0; x < 24; ++x )
115
+ {
116
+ tSmallUInt t;
117
+ tKeccakLane T[1];
118
+ t = pgm_read_byte(&KeccakF_PiLane[x]);
119
+ T[0] = state[t];
120
+ state[t] = rotate64left_code( temp, pgm_read_byte(&KeccakF_RotationConstants[x]) );
121
+ temp = T[0];
122
+ }
123
+ }
124
+
125
+ // Chi Iota Prepare Theta
126
+ {
127
+ tSmallUInt z;
128
+ UINT8 * p = (unsigned char *)state;
129
+ UINT8 * pC = (unsigned char *)C;
130
+
131
+ for( z = 0; z < 8; ++z, ++p, ++pC )
132
+ {
133
+ tSmallUInt y;
134
+ UINT8 c0, c1, c2, c3, c4, t;
135
+
136
+ c0 = c1 = c2 = c3 = c4 = 0;
137
+ for( y = 5; y != 0; --y, p += 40 )
138
+ {
139
+ UINT8 a0 = *p;
140
+ UINT8 a1 = *(p+8);
141
+ UINT8 a2 = *(p+16);
142
+ UINT8 a3 = *(p+24);
143
+ UINT8 a4 = *(p+32);
144
+
145
+ *p = t = a0 ^ ((~a1) & a2); c0 ^= t;
146
+ *(p+8) = t = a1 ^ ((~a2) & a3); c1 ^= t;
147
+ *(p+16) = a2 ^= ((~a3) & a4); c2 ^= a2;
148
+ *(p+24) = a3 ^= ((~a4) & a0); c3 ^= a3;
149
+ *(p+32) = a4 ^= ((~a0) & a1); c4 ^= a4;
150
+ }
151
+ p -= 5 * 5 * 8;
152
+ y = pgm_read_byte( (UINT8 *)(KeccakF_RoundConstants+round) + z );
153
+ *p ^= y;
154
+ *pC = c0 ^ y;
155
+ *(pC+ 8) = c1;
156
+ *(pC+16) = c2;
157
+ *(pC+24) = c3;
158
+ *(pC+32) = c4;
159
+ }
160
+ }
161
+ }
162
+
163
+ }
@@ -0,0 +1,647 @@
1
+ /*
2
+ The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
3
+ Michaël Peeters and Gilles Van Assche. For more information, feedback or
4
+ questions, please refer to our website: http://keccak.noekeon.org/
5
+
6
+ Implementation by Ronny Van Keer, hereby denoted as "the implementer".
7
+
8
+ To the extent possible under law, the implementer has waived all copyright
9
+ and related or neighboring rights to the source code in this file.
10
+ http://creativecommons.org/publicdomain/zero/1.0/
11
+ */
12
+
13
+ #include "Keccak-avr8-settings.h"
14
+ #include "crypto_hash.h"
15
+
16
+ #define cKeccakR_SizeInBytes (cKeccakR/8)
17
+
18
+ #ifndef crypto_hash_BYTES
19
+ #ifdef cKeccakFixedOutputLengthInBytes
20
+ #define crypto_hash_BYTES cKeccakFixedOutputLengthInBytes
21
+ #else
22
+ #define crypto_hash_BYTES cKeccakR_SizeInBytes
23
+ #endif
24
+ #endif
25
+
26
+ // Registers used in all routines
27
+ #define zero 1
28
+ #define rpState 24
29
+ #define rX 26
30
+ #define rY 28
31
+ #define rZ 30
32
+
33
+
34
+ /*
35
+ * int crypto_hash( unsigned char *out, const unsigned char *in, unsigned long long inlen )
36
+ *
37
+ * argument out is passed in r24:r25
38
+ * argument in is passed in r22:r23
39
+ * argument inlen is passed in r14:r21, only lowest 16-bits (r14-r15) are used
40
+ */
41
+ .global crypto_hash // populate.py, please update crypto_hash
42
+ crypto_hash: // populate.py, please update crypto_hash
43
+
44
+ // crypto_hash only registers
45
+ #define rT1 16
46
+ #define rT2 17
47
+ #define rT3 18
48
+ #define rInLen 22 //(2 regs)
49
+ #define sp 0x3D
50
+
51
+ push r2
52
+ push r3
53
+ push r4
54
+ push r5
55
+ push r6
56
+ push r7
57
+ push r8
58
+ push r9
59
+ push r10
60
+ push r11
61
+ push r12
62
+ push r13
63
+ push r14
64
+ push r15
65
+ push r16
66
+ push r17
67
+ push r28
68
+ push r29
69
+
70
+ // Allocate state (25*8) + C variables (5*8)
71
+ in rZ, sp
72
+ in rZ+1, sp+1
73
+ subi rZ, 240
74
+ sbci rZ+1, 0
75
+ in r0, 0x3F
76
+ cli
77
+ out sp+1, rZ+1
78
+ out sp, rZ
79
+ out 0x3F, r0
80
+ adiw rZ, 41 // pointer to start of state, end of C, compensate post decrement
81
+
82
+ push r24 // save out pointer
83
+ push r25
84
+
85
+ movw rpState, rZ
86
+ movw rY, r22 //y contains in pointer
87
+ movw rInLen, r14
88
+
89
+ ldi rT3, 5*5*8 //clear state
90
+ clearStateLoop:
91
+ st z+, zero
92
+ dec rT3
93
+ brne clearStateLoop
94
+
95
+ // Full blocks
96
+ cpi rInLen, cKeccakR_SizeInBytes
97
+ cpc rInLen+1, zero
98
+ brcs ch_lastblock
99
+
100
+ ch_FullRateLoop:
101
+ ldi rT3, cKeccakR_SizeInBytes
102
+ movw rZ, rpState
103
+ ch_XorLanesLoop:
104
+ ld rT1, Y+
105
+ ld rT2, Z
106
+ eor rT1, rT2
107
+ st Z+, rT1
108
+ subi rT3, 1
109
+ brne ch_XorLanesLoop
110
+
111
+ push rY
112
+ push rY+1
113
+ call KeccakF
114
+ pop rY+1
115
+ pop rY
116
+
117
+ subi rInLen, cKeccakR_SizeInBytes
118
+ sbci rInLen+1, 0
119
+ cpi rInLen, cKeccakR_SizeInBytes
120
+ cpc rInLen+1, zero
121
+ brcc ch_FullRateLoop
122
+
123
+ ch_lastblock: // XOR last uncomplete block into state
124
+ movw rZ, rpState
125
+
126
+ subi rInLen, 0
127
+ breq ch_Padding
128
+ ch_xorBytesLoop:
129
+ ld rT1, Y+
130
+ ld rT2, Z
131
+ eor rT1, rT2
132
+ st Z+, rT1
133
+ subi rInLen, 1
134
+ brne ch_xorBytesLoop
135
+
136
+ ch_Padding:
137
+ ldi rT1, 1
138
+ ld rT2, Z
139
+ eor rT1, rT2
140
+ st Z, rT1
141
+
142
+ ldi rZ, cKeccakR_SizeInBytes-1
143
+ add rZ, rpState
144
+ mov rZ+1, rpState+1
145
+ adc rZ+1, zero
146
+ ld rT1, Z
147
+ subi rT1, 0x80
148
+ st Z, rT1
149
+
150
+ call KeccakF
151
+
152
+ //output
153
+ ldi rT3, crypto_hash_BYTES
154
+ movw rY, rpState
155
+ pop rZ+1 ; restore out pointer
156
+ pop rZ
157
+ outputLoop:
158
+ ld rT1, Y+
159
+ st Z+, rT1
160
+ dec rT3
161
+ brne outputLoop
162
+
163
+
164
+ // Free state and pop registers
165
+ ldi rZ, 199
166
+ add rpState, rZ
167
+ adc rpState+1, zero
168
+ in r0, 0x3F
169
+ cli
170
+ out sp+1, rpState+1
171
+ out sp, rpState
172
+ out 0x3F, r0
173
+
174
+ pop r29
175
+ pop r28
176
+ pop r17
177
+ pop r16
178
+ pop r15
179
+ pop r14
180
+ pop r13
181
+ pop r12
182
+ pop r11
183
+ pop r10
184
+ pop r9
185
+ pop r8
186
+ pop r7
187
+ pop r6
188
+ pop r5
189
+ pop r4
190
+ pop r3
191
+ pop r2
192
+
193
+ // return 0
194
+ mov r24, zero
195
+ mov r25, zero
196
+
197
+ #undef rInLen
198
+ #undef rT1
199
+ #undef rT2
200
+ #undef rT3
201
+ #undef sp
202
+
203
+ ret
204
+
205
+
206
+ //#define ROT_BIT(a) (a <= 4) ? ((a == 0) ? 0x80 : (a & 7)) : (0x80 | (8-a))
207
+
208
+ #define ROT_BIT(a) ((a) & 7)
209
+ #define ROT_BYTE(a) (((a)/8 + !!(((a)%8) > 4)) & 7)
210
+
211
+ KeccakF_RhoPiConstants:
212
+ .BYTE ROT_BIT( 1), ROT_BYTE( 3), 10 * 8
213
+ .BYTE ROT_BIT( 3), ROT_BYTE( 6), 7 * 8
214
+ .BYTE ROT_BIT( 6), ROT_BYTE(10), 11 * 8
215
+ .BYTE ROT_BIT(10), ROT_BYTE(15), 17 * 8
216
+ .BYTE ROT_BIT(15), ROT_BYTE(21), 18 * 8
217
+ .BYTE ROT_BIT(21), ROT_BYTE(28), 3 * 8
218
+ .BYTE ROT_BIT(28), ROT_BYTE(36), 5 * 8
219
+ .BYTE ROT_BIT(36), ROT_BYTE(45), 16 * 8
220
+ .BYTE ROT_BIT(45), ROT_BYTE(55), 8 * 8
221
+ .BYTE ROT_BIT(55), ROT_BYTE( 2), 21 * 8
222
+ .BYTE ROT_BIT( 2), ROT_BYTE(14), 24 * 8
223
+ .BYTE ROT_BIT(14), ROT_BYTE(27), 4 * 8
224
+ .BYTE ROT_BIT(27), ROT_BYTE(41), 15 * 8
225
+ .BYTE ROT_BIT(41), ROT_BYTE(56), 23 * 8
226
+ .BYTE ROT_BIT(56), ROT_BYTE( 8), 19 * 8
227
+ .BYTE ROT_BIT( 8), ROT_BYTE(25), 13 * 8
228
+ .BYTE ROT_BIT(25), ROT_BYTE(43), 12 * 8
229
+ .BYTE ROT_BIT(43), ROT_BYTE(62), 2 * 8
230
+ .BYTE ROT_BIT(62), ROT_BYTE(18), 20 * 8
231
+ .BYTE ROT_BIT(18), ROT_BYTE(39), 14 * 8
232
+ .BYTE ROT_BIT(39), ROT_BYTE(61), 22 * 8
233
+ .BYTE ROT_BIT(61), ROT_BYTE(20), 9 * 8
234
+ .BYTE ROT_BIT(20), ROT_BYTE(44), 6 * 8
235
+ .BYTE ROT_BIT(44), ROT_BYTE( 1), 1 * 8
236
+
237
+
238
+ KeccakF_RoundConstants:
239
+ .BYTE 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
240
+ .BYTE 0x82, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
241
+ .BYTE 0x8a, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
242
+ .BYTE 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80
243
+ .BYTE 0x8b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
244
+ .BYTE 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
245
+ .BYTE 0x81, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80
246
+ .BYTE 0x09, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
247
+ .BYTE 0x8a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
248
+ .BYTE 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
249
+ .BYTE 0x09, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
250
+ .BYTE 0x0a, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
251
+ .BYTE 0x8b, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
252
+ .BYTE 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
253
+ .BYTE 0x89, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
254
+ .BYTE 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
255
+ .BYTE 0x02, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
256
+ .BYTE 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
257
+ .BYTE 0x0a, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
258
+ .BYTE 0x0a, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80
259
+ .BYTE 0x81, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80
260
+ .BYTE 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
261
+ .BYTE 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
262
+ .BYTE 0x08, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80
263
+ .BYTE 0xFF, 0 //terminator
264
+
265
+ .text
266
+
267
+
268
+
269
+ // KeccakF
270
+ // Not callable from C!
271
+ //
272
+ // argument rpState is passed in r24:r25
273
+ //
274
+ KeccakF:
275
+
276
+ // Variables used in multiple operations
277
+ #define rTemp 2 // 8 regs (2-9)
278
+ #define rTempBis 10 // 8 regs (10-17)
279
+ #define rTempTer 18 // 2 regs (18-19)
280
+ #define pRound 20 // 2 regs (20-21)
281
+
282
+ // Initial Prepare Theta
283
+ #define TCIPx rTempTer
284
+
285
+ movw rZ, rpState // Z points to 5 C lanes
286
+ sbiw rZ, 40
287
+ movw rY, rpState
288
+ ldi TCIPx, 5*8
289
+ KeccakInitialPrepTheta_Loop:
290
+ ld r0, Y
291
+ adiw rY, 40
292
+ ld rTemp, Y
293
+ adiw rY, 40
294
+ eor r0, rTemp
295
+ ld rTemp, Y
296
+ adiw rY, 40
297
+ eor r0, rTemp
298
+ ld rTemp, Y
299
+ eor r0, rTemp
300
+ ldd rTemp, Y+40
301
+ eor r0, rTemp
302
+ st Z+, r0
303
+ subi rY, 119
304
+ sbc rY+1, zero
305
+ dec TCIPx
306
+ brne KeccakInitialPrepTheta_Loop
307
+ #undef TCIPx
308
+
309
+ ldi pRound, lo8(KeccakF_RoundConstants)
310
+ ldi pRound+1, hi8(KeccakF_RoundConstants)
311
+ Keccak_RoundLoop:
312
+
313
+ // Theta
314
+ #define TCplus rX
315
+ #define TCminus rZ
316
+ #define TCcoordX rTempTer
317
+ #define TCcoordY rTempTer+1
318
+
319
+ movw TCminus, rpState
320
+ sbiw TCminus, 1*8
321
+ movw TCplus, rpState
322
+ sbiw TCplus, 4*8
323
+ movw rY, rpState
324
+
325
+ ldi TCcoordX, 0x16
326
+ KeccakTheta_Loop1:
327
+ ld rTemp+0, X+
328
+ ld rTemp+1, X+
329
+ ld rTemp+2, X+
330
+ ld rTemp+3, X+
331
+ ld rTemp+4, X+
332
+ ld rTemp+5, X+
333
+ ld rTemp+6, X+
334
+ ld rTemp+7, X+
335
+
336
+ lsl rTemp+0
337
+ rol rTemp+1
338
+ rol rTemp+2
339
+ rol rTemp+3
340
+ rol rTemp+4
341
+ rol rTemp+5
342
+ rol rTemp+6
343
+ rol rTemp+7
344
+ adc rTemp+0, zero
345
+
346
+ ld r0, Z+
347
+ eor rTemp+0, r0
348
+ ld r0, Z+
349
+ eor rTemp+1, r0
350
+ ld r0, Z+
351
+ eor rTemp+2, r0
352
+ ld r0, Z+
353
+ eor rTemp+3, r0
354
+ ld r0, Z+
355
+ eor rTemp+4, r0
356
+ ld r0, Z+
357
+ eor rTemp+5, r0
358
+ ld r0, Z+
359
+ eor rTemp+6, r0
360
+ ld r0, Z+
361
+ eor rTemp+7, r0
362
+
363
+ ldi TCcoordY, 5
364
+ KeccakTheta_Loop2:
365
+ ld r0, Y
366
+ eor r0, rTemp+0
367
+ st Y+, r0
368
+ ld r0, Y
369
+ eor r0, rTemp+1
370
+ st Y+, r0
371
+ ld r0, Y
372
+ eor r0, rTemp+2
373
+ st Y+, r0
374
+ ld r0, Y
375
+ eor r0, rTemp+3
376
+ st Y+, r0
377
+ ld r0, Y
378
+ eor r0, rTemp+4
379
+ st Y+, r0
380
+ ld r0, Y
381
+ eor r0, rTemp+5
382
+ st Y+, r0
383
+ ld r0, Y
384
+ eor r0, rTemp+6
385
+ st Y+, r0
386
+ ld r0, Y
387
+ eor r0, rTemp+7
388
+ st Y+, r0
389
+ adiw rY, 32
390
+
391
+ dec TCcoordY
392
+ brne KeccakTheta_Loop2
393
+
394
+ subi rY, 200-8
395
+ sbc rY+1, zero
396
+
397
+ lsr TCcoordX
398
+ brcc 1f
399
+ breq KeccakTheta_End
400
+ rjmp KeccakTheta_Loop1
401
+ 1:
402
+ cpi TCcoordX, 0x0B
403
+ brne 2f
404
+ sbiw TCminus, 40
405
+ rjmp KeccakTheta_Loop1
406
+ 2:
407
+ sbiw TCplus, 40
408
+ rjmp KeccakTheta_Loop1
409
+
410
+ KeccakTheta_End:
411
+ #undef TCplus
412
+ #undef TCminus
413
+ #undef TCcoordX
414
+ #undef TCcoordY
415
+
416
+
417
+ // Rho Pi
418
+ #define RPindex rTempTer+0
419
+ #define RPTemp rTempTer+1
420
+
421
+ sbiw rY, 32
422
+
423
+ ld rTemp+0, Y+
424
+ ld rTemp+1, Y+
425
+ ld rTemp+2, Y+
426
+ ld rTemp+3, Y+
427
+ ld rTemp+4, Y+
428
+ ld rTemp+5, Y+
429
+ ld rTemp+6, Y+
430
+ ld rTemp+7, Y+
431
+
432
+ ldi rZ, lo8(KeccakF_RhoPiConstants)
433
+ ldi rZ+1, hi8(KeccakF_RhoPiConstants)
434
+
435
+ KeccakRhoPi_Loop:
436
+ ; do bit rotation
437
+ lpm RPTemp, Z+ ;get nuber of bits to rotate
438
+ cpi RPTemp, 5
439
+ brcs rotate64_nbit_leftOrNot
440
+ neg RPTemp
441
+ andi RPTemp, 3
442
+
443
+ rotate64_nbit_right:
444
+ bst rTemp, 0
445
+ ror rTemp+7
446
+ ror rTemp+6
447
+ ror rTemp+5
448
+ ror rTemp+4
449
+ ror rTemp+3
450
+ ror rTemp+2
451
+ ror rTemp+1
452
+ ror rTemp
453
+ bld rTemp+7, 7
454
+ dec RPTemp
455
+ brne rotate64_nbit_right
456
+ rjmp KeccakRhoPi_RhoBitRotateDone
457
+
458
+ rotate64_nbit_leftOrNot:
459
+ tst RPTemp
460
+ breq KeccakRhoPi_RhoBitRotateDone
461
+ rotate64_nbit_left:
462
+ lsl rTemp
463
+ rol rTemp+1
464
+ rol rTemp+2
465
+ rol rTemp+3
466
+ rol rTemp+4
467
+ rol rTemp+5
468
+ rol rTemp+6
469
+ rol rTemp+7
470
+ adc rTemp, r1
471
+ dec RPTemp
472
+ brne rotate64_nbit_left
473
+
474
+ KeccakRhoPi_RhoBitRotateDone:
475
+ lpm r0, Z+ ;get number of bytes to rotate
476
+ lpm RPindex, Z+ ;get index in state
477
+ movw rY, rpState
478
+ add rY, RPindex
479
+ adc rY+1, zero
480
+
481
+ ldi rX, rTempBis
482
+ add rX, r0
483
+ mov rX+1, zero
484
+ ldi RPTemp, 8
485
+ KeccakRhoPi_PiByteRotLoop:
486
+ ld r0, Y+
487
+ st X+, r0
488
+ cpi rX, rTempBis+8
489
+ brne KeccakRhoPi_PiByteRotFirst
490
+ ldi rX, rTempBis
491
+ KeccakRhoPi_PiByteRotFirst:
492
+ dec RPTemp
493
+ brne KeccakRhoPi_PiByteRotLoop
494
+
495
+ sbiw rY, 8
496
+ st Y+, rTemp+0
497
+ st Y+, rTemp+1
498
+ st Y+, rTemp+2
499
+ st Y+, rTemp+3
500
+ st Y+, rTemp+4
501
+ st Y+, rTemp+5
502
+ st Y+, rTemp+6
503
+ st Y+, rTemp+7
504
+
505
+ movw rTemp+0, rTempBis+0
506
+ movw rTemp+2, rTempBis+2
507
+ movw rTemp+4, rTempBis+4
508
+ movw rTemp+6, rTempBis+6
509
+ KeccakRhoPi_RhoDone:
510
+ subi RPindex, 8
511
+ brne KeccakRhoPi_Loop
512
+
513
+ #undef RPindex
514
+ #undef RPTemp
515
+
516
+
517
+ // Chi Iota prepare Theta
518
+ #define CIPTa0 rTemp
519
+ #define CIPTa1 rTemp+1
520
+ #define CIPTa2 rTemp+2
521
+ #define CIPTa3 rTemp+3
522
+ #define CIPTa4 rTemp+4
523
+ #define CIPTc0 rTempBis
524
+ #define CIPTc1 rTempBis+1
525
+ #define CIPTc2 rTempBis+2
526
+ #define CIPTc3 rTempBis+3
527
+ #define CIPTc4 rTempBis+4
528
+ #define CIPTz rTempBis+6
529
+ #define CIPTy rTempBis+7
530
+
531
+ movw rY, rpState
532
+ movw rX, rpState ; 5 * C
533
+ sbiw rX, 40
534
+ movw rZ, pRound
535
+
536
+ ldi CIPTz, 8
537
+ KeccakChiIotaPrepareTheta_zLoop:
538
+ mov CIPTc0, zero
539
+ mov CIPTc1, zero
540
+ movw CIPTc2, CIPTc0
541
+ mov CIPTc4, zero
542
+
543
+ ldi CIPTy, 5
544
+ KeccakChiIotaPrepareTheta_yLoop:
545
+ ld CIPTa0, Y
546
+ ldd CIPTa1, Y+8
547
+ ldd CIPTa2, Y+16
548
+ ldd CIPTa3, Y+24
549
+ ldd CIPTa4, Y+32
550
+
551
+ ;*p = t = a0 ^ ((~a1) & a2); c0 ^= t;
552
+ mov r0, CIPTa1
553
+ com r0
554
+ and r0, CIPTa2
555
+ eor r0, CIPTa0
556
+ eor CIPTc0, r0
557
+ st Y, r0
558
+
559
+ ;*(p+8) = t = a1 ^ ((~a2) & a3); c1 ^= t;
560
+ mov r0, CIPTa2
561
+ com r0
562
+ and r0, CIPTa3
563
+ eor r0, CIPTa1
564
+ eor CIPTc1, r0
565
+ std Y+8, r0
566
+
567
+ ;*(p+16) = a2 ^= ((~a3) & a4); c2 ^= a2;
568
+ mov r0, CIPTa3
569
+ com r0
570
+ and r0, CIPTa4
571
+ eor r0, CIPTa2
572
+ eor CIPTc2, r0
573
+ std Y+16, r0
574
+
575
+ ;*(p+24) = a3 ^= ((~a4) & a0); c3 ^= a3;
576
+ mov r0, CIPTa4
577
+ com r0
578
+ and r0, CIPTa0
579
+ eor r0, CIPTa3
580
+ eor CIPTc3, r0
581
+ std Y+24, r0
582
+
583
+ ;*(p+32) = a4 ^= ((~a0) & a1); c4 ^= a4;
584
+ com CIPTa0
585
+ and CIPTa0, CIPTa1
586
+ eor CIPTa0, CIPTa4
587
+ eor CIPTc4, CIPTa0
588
+ std Y+32, CIPTa0
589
+
590
+ adiw rY, 40
591
+ dec CIPTy
592
+ brne KeccakChiIotaPrepareTheta_yLoop
593
+
594
+ subi rY, 200
595
+ sbc rY+1, zero
596
+
597
+ lpm r0, Z+ ;Round Constant
598
+ ld CIPTa0, Y
599
+ eor CIPTa0, r0
600
+ st Y+, CIPTa0
601
+
602
+ movw pRound, rZ
603
+ movw rZ, rX
604
+ eor CIPTc0, r0
605
+ st Z+, CIPTc0
606
+ std Z+7, CIPTc1
607
+ std Z+15, CIPTc2
608
+ std Z+23, CIPTc3
609
+ std Z+31, CIPTc4
610
+ movw rX, rZ
611
+ movw rZ, pRound
612
+
613
+ dec CIPTz
614
+ brne KeccakChiIotaPrepareTheta_zLoop
615
+
616
+ #undef CIPTa0
617
+ #undef CIPTa1
618
+ #undef CIPTa2
619
+ #undef CIPTa3
620
+ #undef CIPTa4
621
+ #undef CIPTc0
622
+ #undef CIPTc1
623
+ #undef CIPTc2
624
+ #undef CIPTc3
625
+ #undef CIPTc4
626
+ #undef CIPTz
627
+ #undef CIPTy
628
+
629
+
630
+ ;Check for terminator
631
+ lpm r0, Z
632
+ inc r0
633
+ breq Keccak_Done
634
+ rjmp Keccak_RoundLoop
635
+ Keccak_Done:
636
+ ret
637
+
638
+ #undef rTemp
639
+ #undef rTempBis
640
+ #undef rTempTer
641
+ #undef pRound
642
+
643
+ #undef rpState
644
+ #undef zero
645
+ #undef rX
646
+ #undef rY
647
+ #undef rZ