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,687 @@
1
+ @ The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
2
+ @ Michaël Peeters and Gilles Van Assche. For more information, feedback or
3
+ @ questions, please refer to our website: http://keccak.noekeon.org/
4
+ @
5
+ @ Implementation by Ronny Van Keer, hereby denoted as "the implementer".
6
+ @
7
+ @ To the extent possible under law, the implementer has waived all copyright
8
+ @ and related or neighboring rights to the source code in this file.
9
+ @ http://creativecommons.org/publicdomain/zero/1.0/
10
+
11
+ @ This file was created from a .asm file
12
+ @ using the ads2gas.pl script.
13
+ .equ DO1STROUNDING, 0
14
+
15
+ @ PRESERVE8
16
+ .text
17
+
18
+ @// --- defines
19
+ .equ cKeccakLaneSizeInBytes, 8
20
+ .equ cKeccakR_SizeInBytes, 576/8 @576/8 1024/8 1088/8 // populate.py, please set cKeccakR_SizeInBytes
21
+ .equ crypto_hash_BYTES , cKeccakR_SizeInBytes @// populate.py, please set crypto_hash_BYTES
22
+
23
+
24
+ @// --- offsets in state
25
+ .equ Aba0, 0*4
26
+ .equ Aba1, 1*4
27
+ .equ Abe0, 2*4
28
+ .equ Abe1, 3*4
29
+ .equ Abi0, 4*4
30
+ .equ Abi1, 5*4
31
+ .equ Abo0, 6*4
32
+ .equ Abo1, 7*4
33
+ .equ Abu0, 8*4
34
+ .equ Abu1, 9*4
35
+ .equ Aga0, 10*4
36
+ .equ Aga1, 11*4
37
+ .equ Age0, 12*4
38
+ .equ Age1, 13*4
39
+ .equ Agi0, 14*4
40
+ .equ Agi1, 15*4
41
+ .equ Ago0, 16*4
42
+ .equ Ago1, 17*4
43
+ .equ Agu0, 18*4
44
+ .equ Agu1, 19*4
45
+ .equ Aka0, 20*4
46
+ .equ Aka1, 21*4
47
+ .equ Ake0, 22*4
48
+ .equ Ake1, 23*4
49
+ .equ Aki0, 24*4
50
+ .equ Aki1, 25*4
51
+ .equ Ako0, 26*4
52
+ .equ Ako1, 27*4
53
+ .equ Aku0, 28*4
54
+ .equ Aku1, 29*4
55
+ .equ Ama0, 30*4
56
+ .equ Ama1, 31*4
57
+ .equ Ame0, 32*4
58
+ .equ Ame1, 33*4
59
+ .equ Ami0, 34*4
60
+ .equ Ami1, 35*4
61
+ .equ Amo0, 36*4
62
+ .equ Amo1, 37*4
63
+ .equ Amu0, 38*4
64
+ .equ Amu1, 39*4
65
+ .equ Asa0, 40*4
66
+ .equ Asa1, 41*4
67
+ .equ Ase0, 42*4
68
+ .equ Ase1, 43*4
69
+ .equ Asi0, 44*4
70
+ .equ Asi1, 45*4
71
+ .equ Aso0, 46*4
72
+ .equ Aso1, 47*4
73
+ .equ Asu0, 48*4
74
+ .equ Asu1, 49*4
75
+
76
+ @// --- offsets on stack
77
+ .equ mDa0, 50*4
78
+ .equ mDa1, 51*4
79
+ .equ mDo0, 52*4
80
+ .equ mDo1, 53*4
81
+ .equ mDi0, 54*4
82
+ .equ mRC , 55*4
83
+ .equ mRet, 56*4
84
+ .equ mIn , 57*4
85
+ .equ mOut, 58*4
86
+ .equ mLen, 59*4
87
+
88
+ @// --- macros
89
+
90
+ @// Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002
91
+ .macro interleaveLane x0,x1,s0,s1,t,m55,m33,m0F,mFF,tt
92
+
93
+ and \t,\x0,\m55
94
+ and \tt,\x1,\m55
95
+ orr \t,\t,\t, LSR #1
96
+ orr \tt,\tt,\tt, LSR #1
97
+ and \t,\t,\m33
98
+ and \tt,\tt,\m33
99
+ orr \t,\t,\t, LSR #2
100
+ orr \tt,\tt,\tt, LSR #2
101
+ and \t,\t,\m0F
102
+ and \tt,\tt,\m0F
103
+ orr \t,\t,\t, LSR #4
104
+ orr \tt,\tt,\tt, LSR #4
105
+ and \t,\t,\mFF
106
+ and \tt,\tt,\mFF
107
+ bfi \t,\t,#8, #8
108
+ orr \tt,\tt,\tt, LSR #8
109
+ eor \s0,\s0,\t, LSR #8
110
+
111
+ and \t,\x0,\m55, LSL #1
112
+ eor \s0,\s0,\tt, LSL #16
113
+ and \tt,\x1,\m55, LSL #1
114
+ orr \t,\t,\t, LSL #1
115
+ orr \tt,\tt,\tt, LSL #1
116
+ and \t,\t,\m33, LSL #2
117
+ and \tt,\tt,\m33, LSL #2
118
+ orr \t,\t,\t, LSL #2
119
+ orr \tt,\tt,\tt, LSL #2
120
+ and \t,\t,\m0F, LSL #4
121
+ and \tt,\tt,\m0F, LSL #4
122
+ orr \t,\t,\t, LSL #4
123
+ orr \tt,\tt,\tt, LSL #4
124
+ and \t,\t,\mFF, LSL #8
125
+ and \tt,\tt,\mFF, LSL #8
126
+ orr \t,\t,\t, LSL #8
127
+ orr \tt,\tt,\tt, LSL #8
128
+ eor \s1,\s1,\t, LSR #16
129
+ bfc \tt, #0, #16
130
+ eors \s1,\s1,\tt
131
+ .endm
132
+
133
+ @// Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002
134
+ .macro uninterleaveLane x0, x1, t, mFF, mF0, m0C, m22, tt
135
+
136
+ mov \t, \x0
137
+ bfi \x0, \x1, #16, #16
138
+ bfc \x1, #0, #16
139
+ orr \x1, \x1, \t, LSR #16
140
+
141
+ eor \t, \x0, \x0, LSR #8
142
+ eor \tt, \x1, \x1, LSR #8
143
+ and \t, \mFF
144
+ and \tt, \mFF
145
+ eor \x0, \x0, \t
146
+ eor \x1, \x1, \tt
147
+ eor \x0, \x0, \t, LSL #8
148
+ eor \x1, \x1, \tt, LSL #8
149
+
150
+ eor \t, \x0, \x0, LSR #4
151
+ eor \tt, \x1, \x1, LSR #4
152
+ and \t, \mF0
153
+ and \tt, \mF0
154
+ eor \x0, \x0, \t
155
+ eor \x1, \x1, \tt
156
+ eor \x0, \x0, \t, LSL #4
157
+ eor \x1, \x1, \tt, LSL #4
158
+
159
+ eor \t, \x0, \x0, LSR #2
160
+ eor \tt, \x1, \x1, LSR #2
161
+ and \t, \m0C
162
+ and \tt, \m0C
163
+ eor \x0, \x0, \t
164
+ eor \x1, \x1, \tt
165
+ eor \x0, \x0, \t, LSL #2
166
+ eor \x1, \x1, \tt, LSL #2
167
+
168
+ eor \t, \x0, \x0, LSR #1
169
+ eor \tt, \x1, \x1, LSR #1
170
+ and \t, \m22
171
+ and \tt, \m22
172
+ eor \x0, \x0, \t
173
+ eor \x1, \x1, \tt
174
+ eor \x0, \x0, \t, LSL #1
175
+ eor \x1, \x1, \tt, LSL #1
176
+ .endm
177
+
178
+ .macro xor55 result1,b1,g1,k1,m1,s1,result2,b2,g2,k2,m2,s2
179
+
180
+ ldr \result1, [sp, #\b1]
181
+ ldr \result2, [sp, #\b2]
182
+ ldr r1, [sp, #\g1]
183
+ ldr r2, [sp, #\g2]
184
+ eor \result1, \result1, r1
185
+ ldr r1, [sp, #\k1]
186
+ eor \result2, \result2, r2
187
+ ldr r2, [sp, #\k2]
188
+ eor \result1, \result1, r1
189
+ ldr r1, [sp, #\m1]
190
+ eor \result2, \result2, r2
191
+ ldr r2, [sp, #\m2]
192
+ eor \result1, \result1, r1
193
+ ldr r1, [sp, #\s1]
194
+ eor \result2, \result2, r2
195
+ ldr r2, [sp, #\s2]
196
+ eor \result1, \result1, r1
197
+ eor \result2, \result2, r2
198
+ .endm
199
+
200
+
201
+ .macro KeccakThetaRhoPiChiIota aA1, aDax, aA2, aDex, rot2, aA3, aDix, rot3, aA4, aDox, rot4, aA5, aDux, rot5, offset, last
202
+ ldr r3, [sp, #\aA1]
203
+ ldr r4, [sp, #\aA2]
204
+ eor r3, r3, \aDax
205
+ ldr r5, [sp, #\aA3]
206
+ eor r4, r4, \aDex
207
+ ldr r6, [sp, #\aA4]
208
+ eor r5, r5, \aDix
209
+ ldr r7, [sp, #\aA5]
210
+ ror r4, #32-\rot2
211
+ eor r6, r6, \aDox
212
+ ror r5, #32-\rot3
213
+ eor r7, r7, \aDux
214
+ ror r6, #32-\rot4
215
+ ror r7, #32-\rot5
216
+
217
+ bic r1, r6, r5
218
+ bic r2, r7, r6
219
+ eor r1, r1, r4
220
+ eor r2, r2, r5
221
+ str r1, [sp, #\aA2]
222
+
223
+ bic r1, r3, r7
224
+ str r2, [sp, #\aA3]
225
+ bic r2, r4, r3
226
+ eor r1, r1, r6
227
+ eor r2, r2, r7
228
+ str r1, [sp, #\aA4]
229
+ ldr r1, [sp, #mRC]
230
+ bic r5, r5, r4
231
+ ldr r4, [r1, #\offset]
232
+ eor r3, r3, r5
233
+ str r2, [sp, #\aA5]
234
+ .if \last == 1
235
+ ldr r2, [r1, #32]!
236
+ .endif
237
+ eor r3, r3, r4
238
+ .if \last == 1
239
+ str r1, [sp, #mRC]
240
+ cmp r2, #0xFFFFFFFF
241
+ .endif
242
+ str r3, [sp, #\aA1]
243
+ .endm
244
+
245
+ .macro KeccakThetaRhoPiChi aB1, aA1, aDax, rot1, aB2, aA2, aDex, rot2, aB3, aA3, aDix, rot3, aB4, aA4, aDox, rot4, aB5, aA5, aDux, rot5
246
+ ldr \aB1, [sp, #\aA1]
247
+ ldr \aB2, [sp, #\aA2]
248
+ eor \aB1, \aB1, \aDax
249
+ ldr \aB3, [sp, #\aA3]
250
+ eor \aB2, \aB2, \aDex
251
+ ldr \aB4, [sp, #\aA4]
252
+ ror \aB1, #32-\rot1
253
+ eor \aB3, \aB3, \aDix
254
+ .if \rot2 > 0
255
+ ror \aB2, #32-\rot2
256
+ .endif
257
+ ldr \aB5, [sp, #\aA5]
258
+ ror \aB3, #32-\rot3
259
+ eor \aB4, \aB4, \aDox
260
+ eor \aB5, \aB5, \aDux
261
+ ror \aB4, #32-\rot4
262
+ ror \aB5, #32-\rot5
263
+
264
+ bic r1, r7, r6
265
+ bic r2, r3, r7
266
+ eor r1, r1, r5
267
+ eor r2, r2, r6
268
+ bic r6, r6, r5
269
+ bic r5, r5, r4
270
+ str r1, [sp, #\aA3]
271
+ eor r6, r6, r4
272
+ str r2, [sp, #\aA4]
273
+ bic r4, r4, r3
274
+ str r6, [sp, #\aA2]
275
+ eor r5, r5, r3
276
+ eor r4, r4, r7
277
+ str r5, [sp, #\aA1]
278
+ str r4, [sp, #\aA5]
279
+
280
+ .endm
281
+
282
+ .macro KeccakRound0
283
+
284
+ xor55 r3, Abu0, Agu0, Aku0, Amu0, Asu0, r7, Abe1, Age1, Ake1, Ame1, Ase1
285
+ xor55 r6, Abu1, Agu1, Aku1, Amu1, Asu1, r12, Abe0, Age0, Ake0, Ame0, Ase0
286
+ eor r1, r3, r7, ROR #31
287
+ eor r8, r6, r12
288
+ str r1, [sp, #mDa0]
289
+
290
+ xor55 r5, Abi0, Agi0, Aki0, Ami0, Asi0, r4, Abi1, Agi1, Aki1, Ami1, Asi1
291
+ str r8, [sp, #mDa1]
292
+ eor r0, r5, r6, ROR #31
293
+ eor r11, r4, r3
294
+ str r0, [sp, #mDo0]
295
+
296
+ xor55 r3, Aba0, Aga0, Aka0, Ama0, Asa0, r6, Aba1, Aga1, Aka1, Ama1, Asa1
297
+ str r11, [sp, #mDo1]
298
+ eor r10, r3, r4, ROR #31
299
+ eor r11, r6, r5
300
+
301
+ xor55 r4, Abo1, Ago1, Ako1, Amo1, Aso1, r5, Abo0, Ago0, Ako0, Amo0, Aso0
302
+ eor r12, r12, r4, ROR #31
303
+ eor r9, r7, r5
304
+ str r12, [sp, #mDi0]
305
+
306
+ eor r12, r5, r6, ROR #31
307
+ eor lr, r4, r3
308
+
309
+ KeccakThetaRhoPiChi r5, Aka1, r8, 2, r6, Ame1, r11, 23, r7, Asi1, r9, 31, r3, Abo0, r0, 14, r4, Agu0, r12, 10
310
+ KeccakThetaRhoPiChi r7, Asa1, r8, 9, r3, Abe0, r10, 0, r4, Agi1, r9, 3, r5, Ako0, r0, 12, r6, Amu1, lr, 4
311
+ ldr r8, [sp, #mDa0]
312
+ KeccakThetaRhoPiChi r4, Aga0, r8, 18, r5, Ake0, r10, 5, r6, Ami1, r9, 8, r7, Aso0, r0, 28, r3, Abu1, lr, 14
313
+ KeccakThetaRhoPiChi r6, Ama0, r8, 20, r7, Ase1, r11, 1, r3, Abi1, r9, 31, r4, Ago0, r0, 27, r5, Aku0, r12, 19
314
+ ldr r0, [sp, #mDo1]
315
+ KeccakThetaRhoPiChiIota Aba0, r8, Age0, r10, 22, Aki1, r9, 22, Amo1, r0, 11, Asu0, r12, 7, 0, 0
316
+
317
+ ldr r9, [sp, #mDi0]
318
+ KeccakThetaRhoPiChi r5, Aka0, r8, 1, r6, Ame0, r10, 22, r7, Asi0, r9, 30, r3, Abo1, r0, 14, r4, Agu1, lr, 10
319
+ KeccakThetaRhoPiChi r7, Asa0, r8, 9, r3, Abe1, r11, 1, r4, Agi0, r9, 3, r5, Ako1, r0, 13, r6, Amu0, r12, 4
320
+ ldr r8, [sp, #mDa1]
321
+ KeccakThetaRhoPiChi r4, Aga1, r8, 18, r5, Ake1, r11, 5, r6, Ami0, r9, 7, r7, Aso1, r0, 28, r3, Abu0, r12, 13
322
+ KeccakThetaRhoPiChi r6, Ama1, r8, 21, r7, Ase0, r10, 1, r3, Abi0, r9, 31, r4, Ago1, r0, 28, r5, Aku1, lr, 20
323
+ ldr r0, [sp, #mDo0]
324
+ KeccakThetaRhoPiChiIota Aba1, r8, Age1, r11, 22, Aki0, r9, 21, Amo0, r0, 10, Asu1, lr, 7, 4, 0
325
+ .endm
326
+
327
+ .macro KeccakRound1
328
+
329
+ xor55 r3, Asu0, Agu0, Amu0, Abu1, Aku1, r7, Age1, Ame0, Abe0, Ake1, Ase1
330
+ xor55 r6, Asu1, Agu1, Amu1, Abu0, Aku0, r12, Age0, Ame1, Abe1, Ake0, Ase0
331
+ eor r1, r3, r7, ROR #31
332
+ eor r8, r6, r12
333
+ str r1, [sp, #mDa0]
334
+
335
+ xor55 r5, Aki1, Asi1, Agi0, Ami1, Abi0, r4, Aki0, Asi0, Agi1, Ami0, Abi1
336
+ str r8, [sp, #mDa1]
337
+ eor r0, r5, r6, ROR #31
338
+ eor r11, r4, r3
339
+ str r0, [sp, #mDo0]
340
+
341
+ xor55 r3, Aba0, Aka1, Asa0, Aga0, Ama1, r6, Aba1, Aka0, Asa1, Aga1, Ama0
342
+ str r11, [sp, #mDo1]
343
+ eor r10, r3, r4, ROR #31
344
+ eor r11, r6, r5
345
+
346
+ xor55 r4, Amo0, Abo1, Ako0, Aso1, Ago0, r5, Amo1, Abo0, Ako1, Aso0, Ago1
347
+ eor r12, r12, r4, ROR #31
348
+ eor r9, r7, r5
349
+ str r12, [sp, #mDi0]
350
+
351
+ eor r12, r5, r6, ROR #31
352
+ eor lr, r4, r3
353
+
354
+ KeccakThetaRhoPiChi r5, Asa1, r8, 2, r6, Ake1, r11, 23, r7, Abi1, r9, 31, r3, Amo1, r0, 14, r4, Agu0, r12, 10
355
+ KeccakThetaRhoPiChi r7, Ama0, r8, 9, r3, Age0, r10, 0, r4, Asi0, r9, 3, r5, Ako1, r0, 12, r6, Abu0, lr, 4
356
+ ldr r8, [sp, #mDa0]
357
+ KeccakThetaRhoPiChi r4, Aka1, r8, 18, r5, Abe1, r10, 5, r6, Ami0, r9, 8, r7, Ago1, r0, 28, r3, Asu1, lr, 14
358
+ KeccakThetaRhoPiChi r6, Aga0, r8, 20, r7, Ase1, r11, 1, r3, Aki0, r9, 31, r4, Abo0, r0, 27, r5, Amu0, r12, 19
359
+ ldr r0, [sp, #mDo1]
360
+ KeccakThetaRhoPiChiIota Aba0, r8, Ame1, r10, 22, Agi1, r9, 22, Aso1, r0, 11, Aku1, r12, 7, 8, 0
361
+
362
+ ldr r9, [sp, #mDi0]
363
+ KeccakThetaRhoPiChi r5, Asa0, r8, 1, r6, Ake0, r10, 22, r7, Abi0, r9, 30, r3, Amo0, r0, 14, r4, Agu1, lr, 10
364
+ KeccakThetaRhoPiChi r7, Ama1, r8, 9, r3, Age1, r11, 1, r4, Asi1, r9, 3, r5, Ako0, r0, 13, r6, Abu1, r12, 4
365
+ ldr r8, [sp, #mDa1]
366
+ KeccakThetaRhoPiChi r4, Aka0, r8, 18, r5, Abe0, r11, 5, r6, Ami1, r9, 7, r7, Ago0, r0, 28, r3, Asu0, r12, 13
367
+ KeccakThetaRhoPiChi r6, Aga1, r8, 21, r7, Ase0, r10, 1, r3, Aki1, r9, 31, r4, Abo1, r0, 28, r5, Amu1, lr, 20
368
+ ldr r0, [sp, #mDo0]
369
+ KeccakThetaRhoPiChiIota Aba1, r8, Ame0, r11, 22, Agi0, r9, 21, Aso0, r0, 10, Aku0, lr, 7, 12, 0
370
+ .endm
371
+
372
+ .macro KeccakRound2
373
+
374
+ xor55 r3, Aku1, Agu0, Abu1, Asu1, Amu1, r7, Ame0, Ake0, Age0, Abe0, Ase1
375
+ xor55 r6, Aku0, Agu1, Abu0, Asu0, Amu0, r12, Ame1, Ake1, Age1, Abe1, Ase0
376
+ eor r1, r3, r7, ROR #31
377
+ eor r8, r6, r12
378
+ str r1, [sp, #mDa0]
379
+
380
+ xor55 r5, Agi1, Abi1, Asi1, Ami0, Aki1, r4, Agi0, Abi0, Asi0, Ami1, Aki0
381
+ str r8, [sp, #mDa1]
382
+ eor r0, r5, r6, ROR #31
383
+ eor r11, r4, r3
384
+ str r0, [sp, #mDo0]
385
+
386
+ xor55 r3, Aba0, Asa1, Ama1, Aka1, Aga1, r6, Aba1, Asa0, Ama0, Aka0, Aga0
387
+ str r11, [sp, #mDo1]
388
+ eor r10, r3, r4, ROR #31
389
+ eor r11, r6, r5
390
+
391
+ xor55 r4, Aso0, Amo0, Ako1, Ago0, Abo0, r5, Aso1, Amo1, Ako0, Ago1, Abo1
392
+ eor r12, r12, r4, ROR #31
393
+ eor r9, r7, r5
394
+ str r12, [sp, #mDi0]
395
+
396
+ eor r12, r5, r6, ROR #31
397
+ eor lr, r4, r3
398
+
399
+ KeccakThetaRhoPiChi r5, Ama0, r8, 2, r6, Abe0, r11, 23, r7, Aki0, r9, 31, r3, Aso1, r0, 14, r4, Agu0, r12, 10
400
+ KeccakThetaRhoPiChi r7, Aga0, r8, 9, r3, Ame1, r10, 0, r4, Abi0, r9, 3, r5, Ako0, r0, 12, r6, Asu0, lr, 4
401
+ ldr r8, [sp, #mDa0]
402
+ KeccakThetaRhoPiChi r4, Asa1, r8, 18, r5, Age1, r10, 5, r6, Ami1, r9, 8, r7, Abo1, r0, 28, r3, Aku0, lr, 14
403
+ KeccakThetaRhoPiChi r6, Aka1, r8, 20, r7, Ase1, r11, 1, r3, Agi0, r9, 31, r4, Amo1, r0, 27, r5, Abu1, r12, 19
404
+ ldr r0, [sp, #mDo1]
405
+ KeccakThetaRhoPiChiIota Aba0, r8, Ake1, r10, 22, Asi0, r9, 22, Ago0, r0, 11, Amu1, r12, 7, 16, 0
406
+
407
+ ldr r9, [sp, #mDi0]
408
+ KeccakThetaRhoPiChi r5, Ama1, r8, 1, r6, Abe1, r10, 22, r7, Aki1, r9, 30, r3, Aso0, r0, 14, r4, Agu1, lr, 10
409
+ KeccakThetaRhoPiChi r7, Aga1, r8, 9, r3, Ame0, r11, 1, r4, Abi1, r9, 3, r5, Ako1, r0, 13, r6, Asu1, r12, 4
410
+ ldr r8, [sp, #mDa1]
411
+ KeccakThetaRhoPiChi r4, Asa0, r8, 18, r5, Age0, r11, 5, r6, Ami0, r9, 7, r7, Abo0, r0, 28, r3, Aku1, r12, 13
412
+ KeccakThetaRhoPiChi r6, Aka0, r8, 21, r7, Ase0, r10, 1, r3, Agi1, r9, 31, r4, Amo0, r0, 28, r5, Abu0, lr, 20
413
+ ldr r0, [sp, #mDo0]
414
+ KeccakThetaRhoPiChiIota Aba1, r8, Ake0, r11, 22, Asi1, r9, 21, Ago1, r0, 10, Amu0, lr, 7, 20, 0
415
+ .endm
416
+
417
+ .macro KeccakRound3
418
+
419
+ xor55 r3, Amu1, Agu0, Asu1, Aku0, Abu0, r7, Ake0, Abe1, Ame1, Age0, Ase1
420
+ xor55 r6, Amu0, Agu1, Asu0, Aku1, Abu1, r12, Ake1, Abe0, Ame0, Age1, Ase0
421
+ eor r1, r3, r7, ROR #31
422
+ eor r8, r6, r12
423
+ str r1, [sp, #mDa0]
424
+
425
+ xor55 r5, Asi0, Aki0, Abi1, Ami1, Agi1, r4, Asi1, Aki1, Abi0, Ami0, Agi0
426
+ str r8, [sp, #mDa1]
427
+ eor r0, r5, r6, ROR #31
428
+ eor r11, r4, r3
429
+ str r0, [sp, #mDo0]
430
+
431
+ xor55 r3, Aba0, Ama0, Aga1, Asa1, Aka0, r6, Aba1, Ama1, Aga0, Asa0, Aka1
432
+ str r11, [sp, #mDo1]
433
+ eor r10, r3, r4, ROR #31
434
+ eor r11, r6, r5
435
+
436
+ xor55 r4, Ago1, Aso0, Ako0, Abo0, Amo1, r5, Ago0, Aso1, Ako1, Abo1, Amo0
437
+ eor r12, r12, r4, ROR #31
438
+ eor r9, r7, r5
439
+ str r12, [sp, #mDi0]
440
+
441
+ eor r12, r5, r6, ROR #31
442
+ eor lr, r4, r3
443
+
444
+ KeccakThetaRhoPiChi r5, Aga0, r8, 2, r6, Age0, r11, 23, r7, Agi0, r9, 31, r3, Ago0, r0, 14, r4, Agu0, r12, 10
445
+ KeccakThetaRhoPiChi r7, Aka1, r8, 9, r3, Ake1, r10, 0, r4, Aki1, r9, 3, r5, Ako1, r0, 12, r6, Aku1, lr, 4
446
+ ldr r8, [sp, #mDa0]
447
+ KeccakThetaRhoPiChi r4, Ama0, r8, 18, r5, Ame0, r10, 5, r6, Ami0, r9, 8, r7, Amo0, r0, 28, r3, Amu0, lr, 14
448
+ KeccakThetaRhoPiChi r6, Asa1, r8, 20, r7, Ase1, r11, 1, r3, Asi1, r9, 31, r4, Aso1, r0, 27, r5, Asu1, r12, 19
449
+ ldr r0, [sp, #mDo1]
450
+ KeccakThetaRhoPiChiIota Aba0, r8, Abe0, r10, 22, Abi0, r9, 22, Abo0, r0, 11, Abu0, r12, 7, 24, 0
451
+
452
+ ldr r9, [sp, #mDi0]
453
+ KeccakThetaRhoPiChi r5, Aga1, r8, 1, r6, Age1, r10, 22, r7, Agi1, r9, 30, r3, Ago1, r0, 14, r4, Agu1, lr, 10
454
+ KeccakThetaRhoPiChi r7, Aka0, r8, 9, r3, Ake0, r11, 1, r4, Aki0, r9, 3, r5, Ako0, r0, 13, r6, Aku0, r12, 4
455
+ ldr r8, [sp, #mDa1]
456
+ KeccakThetaRhoPiChi r4, Ama1, r8, 18, r5, Ame1, r11, 5, r6, Ami1, r9, 7, r7, Amo1, r0, 28, r3, Amu1, r12, 13
457
+ KeccakThetaRhoPiChi r6, Asa0, r8, 21, r7, Ase0, r10, 1, r3, Asi0, r9, 31, r4, Aso0, r0, 28, r5, Asu0, lr, 20
458
+ ldr r0, [sp, #mDo0]
459
+ KeccakThetaRhoPiChiIota Aba1, r8, Abe1, r11, 22, Abi1, r9, 21, Abo1, r0, 10, Abu1, lr, 7, 28, 1
460
+ .endm
461
+
462
+ @// --- code and constants
463
+
464
+ @//int crypto_hash( unsigned char *out, const unsigned char *in, unsigned long long inlen )
465
+ .global crypto_hash @// populate.py, please update crypto_hash
466
+ crypto_hash: @// populate.py, please update crypto_hash
467
+
468
+ push {r4-r12,lr}
469
+ sub sp, sp, #10*4
470
+
471
+ @//allocate and clear state
472
+ mov r3, #0
473
+ mov r4, #0
474
+ mov r5, #0
475
+ mov r6, #0
476
+ mov r7, #0
477
+ push {r3-r7}
478
+ push {r3-r7}
479
+ push {r3-r7}
480
+ push {r3-r7}
481
+ push {r3-r7}
482
+ push {r3-r7}
483
+ push {r3-r7}
484
+ push {r3-r7}
485
+ push {r3-r7}
486
+ push {r3-r7}
487
+
488
+ str r0, [sp, #mOut] @// save out pointer
489
+
490
+ @// Complete rate loop
491
+ subs r4, r2, #cKeccakR_SizeInBytes
492
+ adr r3, KeccakF1600RoundConstantsWithTerminator
493
+ str r1, [sp, #mIn] @// save in pointer
494
+ adr r0, crypto_hash_LoopRet
495
+ str r3, [sp, #mRC] @// save Round Constants pointer
496
+ str r0, [sp, #mRet] @// save return address
497
+ bcc crypto_hash_LoopEnd
498
+
499
+ str r4, [sp, #mLen] @// save inlen (ignore upper 32-bit word, since CPU address space is only 32-bit wide)
500
+ mov r4, #cKeccakR_SizeInBytes/cKeccakLaneSizeInBytes
501
+ b KeccakF_FullRate
502
+ crypto_hash_LoopRet:
503
+ ldr r2, [sp, #mLen]
504
+ adr r0, KeccakF1600RoundConstantsWithTerminator
505
+ subs r4, r2, #cKeccakR_SizeInBytes
506
+ str r0, [sp, #mRC] @// save Round Constants pointer
507
+ str r4, [sp, #mLen]
508
+ mov r4, #cKeccakR_SizeInBytes/cKeccakLaneSizeInBytes
509
+ bcs KeccakF_FullRate
510
+ crypto_hash_LoopEnd:
511
+
512
+ @// Last incomplete lane and padding
513
+ mov r4, r2, LSR #3 @// r4 nbrFullLanes = len >> 3@
514
+ and r6, r2, #7 @// r6 len &= 7@ length last incomplete lane
515
+
516
+ mov r0, #1 @// XOR first padding bit into state: state[nbrFullLanes << 1] ^= 1 << (len * 4)@
517
+ mov r1, r6, LSL #2
518
+ lsl r0, r0, r1
519
+ ldr r1, [sp, r4, LSL #3]
520
+ eor r1, r1, r0
521
+ str r1, [sp, r4, LSL #3]
522
+
523
+ @// XOR last incomplete lane if needed
524
+ adr r1, crypto_hash_leftBranchTab
525
+ ldr r3, [sp, #mIn] @// get in pointer
526
+ add r3, r3, r4, LSL #3 @// p = in + nbrFullLanes << 3@
527
+ ldr pc, [r1, r6, LSL #2]
528
+ crypto_hash_leftBranchTab:
529
+ .long crypto_hash_IncompleteDone @//0 left
530
+ .long crypto_hash_1left
531
+ .long crypto_hash_2left
532
+ .long crypto_hash_3left
533
+ .long crypto_hash_4left
534
+ .long crypto_hash_5left
535
+ .long crypto_hash_6left
536
+ .long crypto_hash_7left
537
+
538
+ crypto_hash_1left:
539
+ ldrb r0, [r3]
540
+ mov r1, #0 @// x1 = 0
541
+ b crypto_hash_Interleave
542
+ crypto_hash_2left:
543
+ ldrh r0, [r3]
544
+ mov r1, #0 @// x1 = 0
545
+ b crypto_hash_Interleave
546
+ crypto_hash_3left:
547
+ ldrh r0, [r3]
548
+ ldrb r1, [r3, #2]
549
+ orr r0, r0, r1, LSL #16
550
+ mov r1, #0 @// x1 = 0
551
+ b crypto_hash_Interleave
552
+ crypto_hash_4left:
553
+ ldr r0, [r3]
554
+ mov r1, #0 @// x1 = 0
555
+ b crypto_hash_Interleave
556
+ crypto_hash_5left:
557
+ ldr r0, [r3]
558
+ ldrb r1, [r3, #4]
559
+ b crypto_hash_Interleave
560
+ crypto_hash_6left:
561
+ ldr r0, [r3]
562
+ ldrh r1, [r3, #4]
563
+ b crypto_hash_Interleave
564
+ crypto_hash_7left:
565
+ ldrh r1, [r3, #4]
566
+ ldrb r0, [r3, #6]
567
+ orr r1, r1, r0, LSL #16
568
+ ldr r0, [r3]
569
+
570
+ crypto_hash_Interleave:
571
+ add r8, sp, r4, LSL #3
572
+ movw r9, #0x5555
573
+ movw r10, #0x3333
574
+ movw r11, #0x0F0F
575
+ movw r12, #0x00FF
576
+ ldrd r2, r3, [r8]
577
+ movt r9, #0x5555
578
+ movt r10, #0x3333
579
+ movt r11, #0x0F0F
580
+ movt r12, #0x00FF
581
+ interleaveLane r0, r1, r2, r3, r6, r9, r10, r11, r12, lr
582
+ strd r2, r3, [r8]
583
+ crypto_hash_IncompleteDone:
584
+ ldr r0, [sp, #cKeccakR_SizeInBytes-4] @// XOR second padding bit into state
585
+ eor r0, #0x80000000
586
+ str r0, [sp, #cKeccakR_SizeInBytes-4]
587
+
588
+ adr r0, crypto_hash_SqueezeRet
589
+ str r0, [sp, #mRet] @// save return address
590
+ b KeccakF
591
+ crypto_hash_SqueezeRet:
592
+
593
+ ldr r7, [sp, #mOut] @// save return address
594
+ mov r4, #crypto_hash_BYTES/cKeccakLaneSizeInBytes @len = crypto_hash_BYTES / cKeccakLaneSizeInBytes@
595
+ mov r3, sp
596
+ movw r9, #0xFF00
597
+ movw r10, #0x00F0
598
+ movw r11, #0x0C0C
599
+ movw r12, #0x2222
600
+ movt r10, #0x00F0
601
+ movt r11, #0x0C0C
602
+ movt r12, #0x2222
603
+ crypto_hash_OutputLoop:
604
+ ldrd r0, r1, [r3], #8
605
+ uninterleaveLane r0, r1, r2, r9, r10, r11, r12, lr
606
+ str r0, [r7], #4
607
+ subs r4, r4, #1
608
+ str r1, [r7], #4
609
+ bne crypto_hash_OutputLoop
610
+
611
+ add sp, sp, #5*5*2*4+10*4
612
+ mov r0, #0
613
+ pop {r4-r12,pc}
614
+
615
+ .align 8
616
+ .ltorg
617
+ KeccakF1600RoundConstantsWithTerminator:
618
+ @// 0 1
619
+ .long 0x00000001, 0x00000000
620
+ .long 0x00000000, 0x00000089
621
+ .long 0x00000000, 0x8000008b
622
+ .long 0x00000000, 0x80008080
623
+
624
+ .long 0x00000001, 0x0000008b
625
+ .long 0x00000001, 0x00008000
626
+ .long 0x00000001, 0x80008088
627
+ .long 0x00000001, 0x80000082
628
+
629
+ .long 0x00000000, 0x0000000b
630
+ .long 0x00000000, 0x0000000a
631
+ .long 0x00000001, 0x00008082
632
+ .long 0x00000000, 0x00008003
633
+
634
+ .long 0x00000001, 0x0000808b
635
+ .long 0x00000001, 0x8000000b
636
+ .long 0x00000001, 0x8000008a
637
+ .long 0x00000001, 0x80000081
638
+
639
+ .long 0x00000000, 0x80000081
640
+ .long 0x00000000, 0x80000008
641
+ .long 0x00000000, 0x00000083
642
+ .long 0x00000000, 0x80008003
643
+
644
+ .long 0x00000001, 0x80008088
645
+ .long 0x00000000, 0x80000088
646
+ .long 0x00000001, 0x00008000
647
+ .long 0x00000000, 0x80008082
648
+
649
+ .long 0xFFFFFFFF @//terminator
650
+
651
+ .align 8
652
+
653
+ KeccakF:
654
+ cmp r4, #0
655
+ beq roundLoop
656
+ KeccakF_FullRate:
657
+ mov r8, sp
658
+ ldr r1, [sp, #mIn]
659
+ movw r9, #0x5555
660
+ movw r10, #0x3333
661
+ movw r11, #0x0F0F
662
+ movw r12, #0x00FF
663
+ movt r9, #0x5555
664
+ movt r10, #0x3333
665
+ movt r11, #0x0F0F
666
+ movt r12, #0x00FF
667
+ interleaveLoop:
668
+ ldr r2, [r1], #4
669
+ ldr r5, [r1], #4
670
+ ldrd r6, r7, [r8]
671
+ interleaveLane r2, r5, r6, r7, r3, r9, r10, r11, r12, lr
672
+ subs r4, r4, #1
673
+ strd r6,r7,[r8], #8
674
+ bne interleaveLoop
675
+ str r1, [sp, #mIn]
676
+
677
+ roundLoop:
678
+ KeccakRound0
679
+ KeccakRound1
680
+ KeccakRound2
681
+ KeccakRound3
682
+ bne roundLoop
683
+ ldr pc, [sp, #mRet]
684
+
685
+ @
686
+ .align 8
687
+