sha3-ruby 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,934 @@
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 rInLen 16 //(2 regs)
46
+ #define rT1 18
47
+ #define rT2 19
48
+ #define rT3 20
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*2 //clear state (4 bytes each iteration)
90
+ clearStateLoop:
91
+ st z+, zero
92
+ st z+, zero
93
+ st z+, zero
94
+ st z+, zero
95
+ dec rT3
96
+ brne clearStateLoop
97
+
98
+ // Full blocks
99
+ cpi rInLen, cKeccakR_SizeInBytes
100
+ cpc rInLen+1, zero
101
+ brcs ch_lastblock
102
+
103
+ ch_FullRateLoop:
104
+ ldi rT3, cKeccakR_SizeInBytes/8
105
+ movw rZ, rpState
106
+ ch_XorLanesLoop:
107
+ ld rT1, Y+
108
+ ld rT2, Z
109
+ eor rT1, rT2
110
+ st Z+, rT1
111
+ ld rT1, Y+
112
+ ld rT2, Z
113
+ eor rT1, rT2
114
+ st Z+, rT1
115
+ ld rT1, Y+
116
+ ld rT2, Z
117
+ eor rT1, rT2
118
+ st Z+, rT1
119
+ ld rT1, Y+
120
+ ld rT2, Z
121
+ eor rT1, rT2
122
+ st Z+, rT1
123
+ ld rT1, Y+
124
+ ld rT2, Z
125
+ eor rT1, rT2
126
+ st Z+, rT1
127
+ ld rT1, Y+
128
+ ld rT2, Z
129
+ eor rT1, rT2
130
+ st Z+, rT1
131
+ ld rT1, Y+
132
+ ld rT2, Z
133
+ eor rT1, rT2
134
+ st Z+, rT1
135
+ ld rT1, Y+
136
+ ld rT2, Z
137
+ eor rT1, rT2
138
+ st Z+, rT1
139
+
140
+ subi rT3, 1
141
+ brne ch_XorLanesLoop
142
+
143
+ push rY
144
+ push rY+1
145
+ push rInLen
146
+ push rInLen+1
147
+ call KeccakF
148
+ pop rInLen+1
149
+ pop rInLen
150
+ pop rY+1
151
+ pop rY
152
+
153
+ subi rInLen, cKeccakR_SizeInBytes
154
+ sbci rInLen+1, 0
155
+ cpi rInLen, cKeccakR_SizeInBytes
156
+ cpc rInLen+1, zero
157
+ brcc ch_FullRateLoop
158
+
159
+ ch_lastblock: // XOR last uncomplete block into state
160
+ movw rZ, rpState
161
+
162
+ lsr rInLen
163
+ brcc ch_xorBytes2
164
+ ld rT1, Y+
165
+ ld rT2, Z
166
+ eor rT1, rT2
167
+ st Z+, rT1
168
+ subi rInLen, 0
169
+ ch_xorBytes2:
170
+ breq ch_Padding
171
+ ch_xorBytes2Loop:
172
+ ld rT1, Y+
173
+ ld rT2, Z
174
+ eor rT1, rT2
175
+ st Z+, rT1
176
+ ld rT1, Y+
177
+ ld rT2, Z
178
+ eor rT1, rT2
179
+ st Z+, rT1
180
+ subi rInLen, 1
181
+ brne ch_xorBytes2Loop
182
+
183
+ ch_Padding:
184
+ ldi rT1, 1
185
+ ld rT2, Z
186
+ eor rT1, rT2
187
+ st Z, rT1
188
+
189
+ ldi rZ, cKeccakR_SizeInBytes-1
190
+ add rZ, rpState
191
+ mov rZ+1, rpState+1
192
+ adc rZ+1, zero
193
+ ld rT1, Z
194
+ subi rT1, 0x80
195
+ st Z, rT1
196
+
197
+ call KeccakF
198
+
199
+ //output
200
+ ldi rT3, crypto_hash_BYTES/4 ; copy 4 bytes per iteration
201
+ movw rY, rpState
202
+ pop rZ+1 ; restore out pointer
203
+ pop rZ
204
+ outputLoop:
205
+ ld rT1, Y+
206
+ st Z+, rT1
207
+ ld rT1, Y+
208
+ st Z+, rT1
209
+ ld rT1, Y+
210
+ st Z+, rT1
211
+ ld rT1, Y+
212
+ st Z+, rT1
213
+ dec rT3
214
+ brne outputLoop
215
+
216
+
217
+ // Free state and pop registers
218
+ ldi rZ, 199
219
+ add rpState, rZ
220
+ adc rpState+1, zero
221
+ in r0, 0x3F
222
+ cli
223
+ out sp+1, rpState+1
224
+ out sp, rpState
225
+ out 0x3F, r0
226
+
227
+ pop r29
228
+ pop r28
229
+ pop r17
230
+ pop r16
231
+ pop r15
232
+ pop r14
233
+ pop r13
234
+ pop r12
235
+ pop r11
236
+ pop r10
237
+ pop r9
238
+ pop r8
239
+ pop r7
240
+ pop r6
241
+ pop r5
242
+ pop r4
243
+ pop r3
244
+ pop r2
245
+
246
+ // return 0
247
+ mov r24, zero
248
+ mov r25, zero
249
+
250
+ #undef rInLen
251
+ #undef rT1
252
+ #undef rT2
253
+ #undef rT3
254
+ #undef sp
255
+
256
+ ret
257
+
258
+
259
+ #define ROT_BIT(a) ((a) & 7)
260
+ #define ROT_BYTE(a) ((((a)/8 + !!(((a)%8) > 4)) & 7) * 9)
261
+
262
+ KeccakF_RhoPiConstants:
263
+ .BYTE ROT_BIT( 1), ROT_BYTE( 3), 10 * 8
264
+ .BYTE ROT_BIT( 3), ROT_BYTE( 6), 7 * 8
265
+ .BYTE ROT_BIT( 6), ROT_BYTE(10), 11 * 8
266
+ .BYTE ROT_BIT(10), ROT_BYTE(15), 17 * 8
267
+ .BYTE ROT_BIT(15), ROT_BYTE(21), 18 * 8
268
+ .BYTE ROT_BIT(21), ROT_BYTE(28), 3 * 8
269
+ .BYTE ROT_BIT(28), ROT_BYTE(36), 5 * 8
270
+ .BYTE ROT_BIT(36), ROT_BYTE(45), 16 * 8
271
+ .BYTE ROT_BIT(45), ROT_BYTE(55), 8 * 8
272
+ .BYTE ROT_BIT(55), ROT_BYTE( 2), 21 * 8
273
+ .BYTE ROT_BIT( 2), ROT_BYTE(14), 24 * 8
274
+ .BYTE ROT_BIT(14), ROT_BYTE(27), 4 * 8
275
+ .BYTE ROT_BIT(27), ROT_BYTE(41), 15 * 8
276
+ .BYTE ROT_BIT(41), ROT_BYTE(56), 23 * 8
277
+ .BYTE ROT_BIT(56), ROT_BYTE( 8), 19 * 8
278
+ .BYTE ROT_BIT( 8), ROT_BYTE(25), 13 * 8
279
+ .BYTE ROT_BIT(25), ROT_BYTE(43), 12 * 8
280
+ .BYTE ROT_BIT(43), ROT_BYTE(62), 2 * 8
281
+ .BYTE ROT_BIT(62), ROT_BYTE(18), 20 * 8
282
+ .BYTE ROT_BIT(18), ROT_BYTE(39), 14 * 8
283
+ .BYTE ROT_BIT(39), ROT_BYTE(61), 22 * 8
284
+ .BYTE ROT_BIT(61), ROT_BYTE(20), 9 * 8
285
+ .BYTE ROT_BIT(20), ROT_BYTE(44), 6 * 8
286
+ .BYTE ROT_BIT(44), ROT_BYTE( 1), 1 * 8
287
+
288
+
289
+ KeccakF_RoundConstants:
290
+ .BYTE 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
291
+ .BYTE 0x82, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
292
+ .BYTE 0x8a, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
293
+ .BYTE 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80
294
+ .BYTE 0x8b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
295
+ .BYTE 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
296
+ .BYTE 0x81, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80
297
+ .BYTE 0x09, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
298
+ .BYTE 0x8a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
299
+ .BYTE 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
300
+ .BYTE 0x09, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
301
+ .BYTE 0x0a, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
302
+ .BYTE 0x8b, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
303
+ .BYTE 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
304
+ .BYTE 0x89, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
305
+ .BYTE 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
306
+ .BYTE 0x02, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
307
+ .BYTE 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
308
+ .BYTE 0x0a, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
309
+ .BYTE 0x0a, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80
310
+ .BYTE 0x81, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80
311
+ .BYTE 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
312
+ .BYTE 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
313
+ .BYTE 0x08, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80
314
+ .BYTE 0xFF, 0 //terminator
315
+
316
+ .text
317
+
318
+
319
+
320
+ // KeccakF
321
+ // Not callable from C!
322
+ //
323
+ // argument rpState is passed in r24:r25
324
+ //
325
+ KeccakF:
326
+
327
+ // Variables used in multiple operations
328
+ #define rTemp 2 // 8 regs (2-9)
329
+ #define rTempBis 10 // 8 regs (10-17)
330
+ #define rTempTer 18 // 4 regs (18-21)
331
+ #define pRound 22 // 2 regs (22-23)
332
+
333
+ // Initial Prepare Theta
334
+ #define TCIPx rTempTer
335
+
336
+ movw rZ, rpState // Z points to 8 C
337
+ sbiw rZ, 40
338
+ ldi TCIPx, 5
339
+ movw rY, rpState
340
+ KeccakInitialPrepTheta_Loop:
341
+ ld rTemp+0, Y+ ;state[x]
342
+ ld rTemp+1, Y+
343
+ ld rTemp+2, Y+
344
+ ld rTemp+3, Y+
345
+ ld rTemp+4, Y+
346
+ ld rTemp+5, Y+
347
+ ld rTemp+6, Y+
348
+ ld rTemp+7, Y+
349
+
350
+ adiw rY, 32
351
+ ld r0, Y+ ;state[5+x]
352
+ eor rTemp+0, r0
353
+ ld r0, Y+
354
+ eor rTemp+1, r0
355
+ ld r0, Y+
356
+ eor rTemp+2, r0
357
+ ld r0, Y+
358
+ eor rTemp+3, r0
359
+ ld r0, Y+
360
+ eor rTemp+4, r0
361
+ ld r0, Y+
362
+ eor rTemp+5, r0
363
+ ld r0, Y+
364
+ eor rTemp+6, r0
365
+ ld r0, Y+
366
+ eor rTemp+7, r0
367
+
368
+ adiw rY, 32
369
+ ld r0, Y+ ;state[10+x]
370
+ eor rTemp+0, r0
371
+ ld r0, Y+
372
+ eor rTemp+1, r0
373
+ ld r0, Y+
374
+ eor rTemp+2, r0
375
+ ld r0, Y+
376
+ eor rTemp+3, r0
377
+ ld r0, Y+
378
+ eor rTemp+4, r0
379
+ ld r0, Y+
380
+ eor rTemp+5, r0
381
+ ld r0, Y+
382
+ eor rTemp+6, r0
383
+ ld r0, Y+
384
+ eor rTemp+7, r0
385
+
386
+ adiw rY, 32
387
+ ld r0, Y+ ;state[15+x]
388
+ eor rTemp+0, r0
389
+ ld r0, Y+
390
+ eor rTemp+1, r0
391
+ ld r0, Y+
392
+ eor rTemp+2, r0
393
+ ld r0, Y+
394
+ eor rTemp+3, r0
395
+ ld r0, Y+
396
+ eor rTemp+4, r0
397
+ ld r0, Y+
398
+ eor rTemp+5, r0
399
+ ld r0, Y+
400
+ eor rTemp+6, r0
401
+ ld r0, Y+
402
+ eor rTemp+7, r0
403
+
404
+ adiw rY, 32
405
+ ld r0, Y+ ;state[20+x]
406
+ eor rTemp+0, r0
407
+ ld r0, Y+
408
+ eor rTemp+1, r0
409
+ ld r0, Y+
410
+ eor rTemp+2, r0
411
+ ld r0, Y+
412
+ eor rTemp+3, r0
413
+ ld r0, Y+
414
+ eor rTemp+4, r0
415
+ ld r0, Y+
416
+ eor rTemp+5, r0
417
+ ld r0, Y+
418
+ eor rTemp+6, r0
419
+ ld r0, Y+
420
+ eor rTemp+7, r0
421
+
422
+ st Z+, rTemp+0
423
+ st Z+, rTemp+1
424
+ st Z+, rTemp+2
425
+ st Z+, rTemp+3
426
+ st Z+, rTemp+4
427
+ st Z+, rTemp+5
428
+ st Z+, rTemp+6
429
+ st Z+, rTemp+7
430
+
431
+ subi rY, 160
432
+ sbc rY+1, zero
433
+
434
+ subi TCIPx, 1
435
+ breq KeccakInitialPrepTheta_Done
436
+ rjmp KeccakInitialPrepTheta_Loop
437
+ KeccakInitialPrepTheta_Done:
438
+ #undef TCIPx
439
+
440
+ ldi pRound, lo8(KeccakF_RoundConstants)
441
+ ldi pRound+1, hi8(KeccakF_RoundConstants)
442
+ Keccak_RoundLoop:
443
+
444
+ // Theta
445
+ #define TCplus rX
446
+ #define TCminus rZ
447
+ #define TCcoordX rTempTer
448
+ #define TCcoordY rTempTer+1
449
+
450
+ movw TCminus, rpState
451
+ sbiw TCminus, 1*8
452
+ movw TCplus, rpState
453
+ sbiw TCplus, 4*8
454
+ movw rY, rpState
455
+
456
+ ldi TCcoordX, 0x16
457
+ KeccakTheta_Loop1:
458
+ ld rTemp+0, X+
459
+ ld rTemp+1, X+
460
+ ld rTemp+2, X+
461
+ ld rTemp+3, X+
462
+ ld rTemp+4, X+
463
+ ld rTemp+5, X+
464
+ ld rTemp+6, X+
465
+ ld rTemp+7, X+
466
+
467
+ lsl rTemp+0
468
+ rol rTemp+1
469
+ rol rTemp+2
470
+ rol rTemp+3
471
+ rol rTemp+4
472
+ rol rTemp+5
473
+ rol rTemp+6
474
+ rol rTemp+7
475
+ adc rTemp+0, zero
476
+
477
+ ld r0, Z+
478
+ eor rTemp+0, r0
479
+ ld r0, Z+
480
+ eor rTemp+1, r0
481
+ ld r0, Z+
482
+ eor rTemp+2, r0
483
+ ld r0, Z+
484
+ eor rTemp+3, r0
485
+ ld r0, Z+
486
+ eor rTemp+4, r0
487
+ ld r0, Z+
488
+ eor rTemp+5, r0
489
+ ld r0, Z+
490
+ eor rTemp+6, r0
491
+ ld r0, Z+
492
+ eor rTemp+7, r0
493
+
494
+ ldi TCcoordY, 5
495
+ KeccakTheta_Loop2:
496
+ ld r0, Y
497
+ eor r0, rTemp+0
498
+ st Y+, r0
499
+ ld r0, Y
500
+ eor r0, rTemp+1
501
+ st Y+, r0
502
+ ld r0, Y
503
+ eor r0, rTemp+2
504
+ st Y+, r0
505
+ ld r0, Y
506
+ eor r0, rTemp+3
507
+ st Y+, r0
508
+ ld r0, Y
509
+ eor r0, rTemp+4
510
+ st Y+, r0
511
+ ld r0, Y
512
+ eor r0, rTemp+5
513
+ st Y+, r0
514
+ ld r0, Y
515
+ eor r0, rTemp+6
516
+ st Y+, r0
517
+ ld r0, Y
518
+ eor r0, rTemp+7
519
+ st Y+, r0
520
+ adiw rY, 32
521
+
522
+ dec TCcoordY
523
+ brne KeccakTheta_Loop2
524
+
525
+ subi rY, 200-8
526
+ sbc rY+1, zero
527
+
528
+ lsr TCcoordX
529
+ brcc 1f
530
+ breq KeccakTheta_End
531
+ rjmp KeccakTheta_Loop1
532
+ 1:
533
+ cpi TCcoordX, 0x0B
534
+ brne 2f
535
+ sbiw TCminus, 40
536
+ rjmp KeccakTheta_Loop1
537
+ 2:
538
+ sbiw TCplus, 40
539
+ rjmp KeccakTheta_Loop1
540
+
541
+ KeccakTheta_End:
542
+ #undef TCplus
543
+ #undef TCminus
544
+ #undef TCcoordX
545
+ #undef TCcoordY
546
+
547
+
548
+ // Rho Pi
549
+ #define RPpConst rTempTer // 2 regs
550
+ #define RPindex rTempTer+2
551
+ #define RPpBitRot rX
552
+ #define RPpByteRot pRound
553
+
554
+ sbiw rY, 32
555
+
556
+ ld rTemp+0, Y+
557
+ ld rTemp+1, Y+
558
+ ld rTemp+2, Y+
559
+ ld rTemp+3, Y+
560
+ ld rTemp+4, Y+
561
+ ld rTemp+5, Y+
562
+ ld rTemp+6, Y+
563
+ ld rTemp+7, Y+
564
+
565
+ push pRound
566
+ push pRound+1
567
+ ldi RPpConst, lo8(KeccakF_RhoPiConstants)
568
+ ldi RPpConst+1, hi8(KeccakF_RhoPiConstants)
569
+ ldi RPpBitRot, pm_lo8(bit_rot_jmp_table)
570
+ ldi RPpBitRot+1, pm_hi8(bit_rot_jmp_table)
571
+ ldi RPpByteRot, pm_lo8(rotate64_0byte_left)
572
+ ldi RPpByteRot+1, pm_hi8(rotate64_0byte_left)
573
+
574
+ KeccakRhoPi_Loop:
575
+ ; get rotation codes and state index
576
+ movw rZ, RPpConst
577
+ lpm r0, Z+ ;bits
578
+ lpm rTempBis, Z+ ;bytes
579
+ lpm RPindex, Z+
580
+ movw RPpConst, rZ
581
+
582
+ ; do bit rotation
583
+ movw rZ, RPpBitRot
584
+ add rZ, r0
585
+ adc rZ+1, zero
586
+ ijmp
587
+
588
+ KeccakRhoPi_RhoBitRotateDone:
589
+ movw rY, rpState
590
+ add rY, RPindex
591
+ adc rY+1, zero
592
+
593
+ movw rZ, RPpByteRot
594
+ add rZ, rTempBis
595
+ adc rZ+1, zero
596
+ ijmp
597
+
598
+ KeccakRhoPi_PiStore:
599
+ sbiw rY, 8
600
+ st Y+, rTemp+0
601
+ st Y+, rTemp+1
602
+ st Y+, rTemp+2
603
+ st Y+, rTemp+3
604
+ st Y+, rTemp+4
605
+ st Y+, rTemp+5
606
+ st Y+, rTemp+6
607
+ st Y+, rTemp+7
608
+
609
+ movw rTemp+0, rTempBis+0
610
+ movw rTemp+2, rTempBis+2
611
+ movw rTemp+4, rTempBis+4
612
+ movw rTemp+6, rTempBis+6
613
+ KeccakRhoPi_RhoDone:
614
+ subi RPindex, 8
615
+ brne KeccakRhoPi_Loop
616
+ pop pRound+1
617
+ pop pRound
618
+
619
+ #undef RPpConst
620
+ #undef RPindex
621
+ #undef RPpBitRot
622
+ #undef RPpByteRot
623
+
624
+
625
+ // Chi Iota prepare Theta
626
+ #define CIPTa0 rTemp
627
+ #define CIPTa1 rTemp+1
628
+ #define CIPTa2 rTemp+2
629
+ #define CIPTa3 rTemp+3
630
+ #define CIPTa4 rTemp+4
631
+ #define CIPTc0 rTempBis
632
+ #define CIPTc1 rTempBis+1
633
+ #define CIPTc2 rTempBis+2
634
+ #define CIPTc3 rTempBis+3
635
+ #define CIPTc4 rTempBis+4
636
+ #define CIPTz rTempBis+6
637
+ #define CIPTy rTempBis+7
638
+
639
+ movw rY, rpState
640
+ movw rX, rpState ; 5 * C
641
+ sbiw rX, 40
642
+ movw rZ, pRound
643
+
644
+ ldi CIPTz, 8
645
+ KeccakChiIotaPrepareTheta_zLoop:
646
+ mov CIPTc0, zero
647
+ mov CIPTc1, zero
648
+ movw CIPTc2, CIPTc0
649
+ mov CIPTc4, zero
650
+
651
+ ldi CIPTy, 5
652
+ KeccakChiIotaPrepareTheta_yLoop:
653
+ ld CIPTa0, Y
654
+ ldd CIPTa1, Y+8
655
+ ldd CIPTa2, Y+16
656
+ ldd CIPTa3, Y+24
657
+ ldd CIPTa4, Y+32
658
+
659
+ ;*p = t = a0 ^ ((~a1) & a2); c0 ^= t;
660
+ mov r0, CIPTa1
661
+ com r0
662
+ and r0, CIPTa2
663
+ eor r0, CIPTa0
664
+ eor CIPTc0, r0
665
+ st Y, r0
666
+
667
+ ;*(p+8) = t = a1 ^ ((~a2) & a3); c1 ^= t;
668
+ mov r0, CIPTa2
669
+ com r0
670
+ and r0, CIPTa3
671
+ eor r0, CIPTa1
672
+ eor CIPTc1, r0
673
+ std Y+8, r0
674
+
675
+ ;*(p+16) = a2 ^= ((~a3) & a4); c2 ^= a2;
676
+ mov r0, CIPTa3
677
+ com r0
678
+ and r0, CIPTa4
679
+ eor r0, CIPTa2
680
+ eor CIPTc2, r0
681
+ std Y+16, r0
682
+
683
+ ;*(p+24) = a3 ^= ((~a4) & a0); c3 ^= a3;
684
+ mov r0, CIPTa4
685
+ com r0
686
+ and r0, CIPTa0
687
+ eor r0, CIPTa3
688
+ eor CIPTc3, r0
689
+ std Y+24, r0
690
+
691
+ ;*(p+32) = a4 ^= ((~a0) & a1); c4 ^= a4;
692
+ com CIPTa0
693
+ and CIPTa0, CIPTa1
694
+ eor CIPTa0, CIPTa4
695
+ eor CIPTc4, CIPTa0
696
+ std Y+32, CIPTa0
697
+
698
+ adiw rY, 40
699
+ dec CIPTy
700
+ brne KeccakChiIotaPrepareTheta_yLoop
701
+
702
+ subi rY, 200
703
+ sbc rY+1, zero
704
+
705
+ lpm r0, Z+ ;Round Constant
706
+ ld CIPTa0, Y
707
+ eor CIPTa0, r0
708
+ st Y+, CIPTa0
709
+
710
+ movw pRound, rZ
711
+ movw rZ, rX
712
+ eor CIPTc0, r0
713
+ st Z+, CIPTc0
714
+ std Z+7, CIPTc1
715
+ std Z+15, CIPTc2
716
+ std Z+23, CIPTc3
717
+ std Z+31, CIPTc4
718
+ movw rX, rZ
719
+ movw rZ, pRound
720
+
721
+ dec CIPTz
722
+ brne KeccakChiIotaPrepareTheta_zLoop
723
+
724
+ #undef CIPTa0
725
+ #undef CIPTa1
726
+ #undef CIPTa2
727
+ #undef CIPTa3
728
+ #undef CIPTa4
729
+ #undef CIPTc0
730
+ #undef CIPTc1
731
+ #undef CIPTc2
732
+ #undef CIPTc3
733
+ #undef CIPTc4
734
+ #undef CIPTz
735
+ #undef CIPTy
736
+
737
+
738
+ ;Check for terminator
739
+ lpm r0, Z
740
+ inc r0
741
+ breq Keccak_Done
742
+ rjmp Keccak_RoundLoop
743
+ Keccak_Done:
744
+ ret
745
+
746
+
747
+ bit_rot_jmp_table:
748
+ rjmp KeccakRhoPi_RhoBitRotateDone
749
+ rjmp rotate64_1bit_left
750
+ rjmp rotate64_2bit_left
751
+ rjmp rotate64_3bit_left
752
+ rjmp rotate64_4bit_left
753
+ rjmp rotate64_3bit_right
754
+ rjmp rotate64_2bit_right
755
+ rjmp rotate64_1bit_right
756
+
757
+ rotate64_4bit_left:
758
+ lsl rTemp
759
+ rol rTemp+1
760
+ rol rTemp+2
761
+ rol rTemp+3
762
+ rol rTemp+4
763
+ rol rTemp+5
764
+ rol rTemp+6
765
+ rol rTemp+7
766
+ adc rTemp, r1
767
+ rotate64_3bit_left:
768
+ lsl rTemp
769
+ rol rTemp+1
770
+ rol rTemp+2
771
+ rol rTemp+3
772
+ rol rTemp+4
773
+ rol rTemp+5
774
+ rol rTemp+6
775
+ rol rTemp+7
776
+ adc rTemp, r1
777
+ rotate64_2bit_left:
778
+ lsl rTemp
779
+ rol rTemp+1
780
+ rol rTemp+2
781
+ rol rTemp+3
782
+ rol rTemp+4
783
+ rol rTemp+5
784
+ rol rTemp+6
785
+ rol rTemp+7
786
+ adc rTemp, r1
787
+ rotate64_1bit_left:
788
+ lsl rTemp
789
+ rol rTemp+1
790
+ rol rTemp+2
791
+ rol rTemp+3
792
+ rol rTemp+4
793
+ rol rTemp+5
794
+ rol rTemp+6
795
+ rol rTemp+7
796
+ adc rTemp, r1
797
+ rjmp KeccakRhoPi_RhoBitRotateDone
798
+
799
+ rotate64_3bit_right:
800
+ bst rTemp, 0
801
+ ror rTemp+7
802
+ ror rTemp+6
803
+ ror rTemp+5
804
+ ror rTemp+4
805
+ ror rTemp+3
806
+ ror rTemp+2
807
+ ror rTemp+1
808
+ ror rTemp
809
+ bld rTemp+7, 7
810
+ rotate64_2bit_right:
811
+ bst rTemp, 0
812
+ ror rTemp+7
813
+ ror rTemp+6
814
+ ror rTemp+5
815
+ ror rTemp+4
816
+ ror rTemp+3
817
+ ror rTemp+2
818
+ ror rTemp+1
819
+ ror rTemp
820
+ bld rTemp+7, 7
821
+ rotate64_1bit_right:
822
+ bst rTemp, 0
823
+ ror rTemp+7
824
+ ror rTemp+6
825
+ ror rTemp+5
826
+ ror rTemp+4
827
+ ror rTemp+3
828
+ ror rTemp+2
829
+ ror rTemp+1
830
+ ror rTemp
831
+ bld rTemp+7, 7
832
+ rjmp KeccakRhoPi_RhoBitRotateDone
833
+
834
+ /*
835
+ ** Each byte rotate routine must be 9 instructions long.
836
+ */
837
+ rotate64_0byte_left:
838
+ ld rTempBis+0, Y+
839
+ ld rTempBis+1, Y+
840
+ ld rTempBis+2, Y+
841
+ ld rTempBis+3, Y+
842
+ ld rTempBis+4, Y+
843
+ ld rTempBis+5, Y+
844
+ ld rTempBis+6, Y+
845
+ ld rTempBis+7, Y+
846
+ rjmp KeccakRhoPi_PiStore
847
+
848
+ rotate64_1byte_left:
849
+ ld rTempBis+1, Y+
850
+ ld rTempBis+2, Y+
851
+ ld rTempBis+3, Y+
852
+ ld rTempBis+4, Y+
853
+ ld rTempBis+5, Y+
854
+ ld rTempBis+6, Y+
855
+ ld rTempBis+7, Y+
856
+ ld rTempBis+0, Y+
857
+ rjmp KeccakRhoPi_PiStore
858
+
859
+ rotate64_2byte_left:
860
+ ld rTempBis+2, Y+
861
+ ld rTempBis+3, Y+
862
+ ld rTempBis+4, Y+
863
+ ld rTempBis+5, Y+
864
+ ld rTempBis+6, Y+
865
+ ld rTempBis+7, Y+
866
+ ld rTempBis+0, Y+
867
+ ld rTempBis+1, Y+
868
+ rjmp KeccakRhoPi_PiStore
869
+
870
+ rotate64_3byte_left:
871
+ ld rTempBis+3, Y+
872
+ ld rTempBis+4, Y+
873
+ ld rTempBis+5, Y+
874
+ ld rTempBis+6, Y+
875
+ ld rTempBis+7, Y+
876
+ ld rTempBis+0, Y+
877
+ ld rTempBis+1, Y+
878
+ ld rTempBis+2, Y+
879
+ rjmp KeccakRhoPi_PiStore
880
+
881
+ rotate64_4byte_left:
882
+ ld rTempBis+4, Y+
883
+ ld rTempBis+5, Y+
884
+ ld rTempBis+6, Y+
885
+ ld rTempBis+7, Y+
886
+ ld rTempBis+0, Y+
887
+ ld rTempBis+1, Y+
888
+ ld rTempBis+2, Y+
889
+ ld rTempBis+3, Y+
890
+ rjmp KeccakRhoPi_PiStore
891
+
892
+ rotate64_5byte_left:
893
+ ld rTempBis+5, Y+
894
+ ld rTempBis+6, Y+
895
+ ld rTempBis+7, Y+
896
+ ld rTempBis+0, Y+
897
+ ld rTempBis+1, Y+
898
+ ld rTempBis+2, Y+
899
+ ld rTempBis+3, Y+
900
+ ld rTempBis+4, Y+
901
+ rjmp KeccakRhoPi_PiStore
902
+
903
+ rotate64_6byte_left:
904
+ ld rTempBis+6, Y+
905
+ ld rTempBis+7, Y+
906
+ ld rTempBis+0, Y+
907
+ ld rTempBis+1, Y+
908
+ ld rTempBis+2, Y+
909
+ ld rTempBis+3, Y+
910
+ ld rTempBis+4, Y+
911
+ ld rTempBis+5, Y+
912
+ rjmp KeccakRhoPi_PiStore
913
+
914
+ rotate64_7byte_left:
915
+ ld rTempBis+7, Y+
916
+ ld rTempBis+0, Y+
917
+ ld rTempBis+1, Y+
918
+ ld rTempBis+2, Y+
919
+ ld rTempBis+3, Y+
920
+ ld rTempBis+4, Y+
921
+ ld rTempBis+5, Y+
922
+ ld rTempBis+6, Y+
923
+ rjmp KeccakRhoPi_PiStore
924
+
925
+ #undef rTemp
926
+ #undef rTempBis
927
+ #undef rTempTer
928
+ #undef pRound
929
+
930
+ #undef rpState
931
+ #undef zero
932
+ #undef rX
933
+ #undef rY
934
+ #undef rZ