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,46 @@
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 the designers,
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
+ #ifndef _KeccakPermutationInterface_h_
15
+ #define _KeccakPermutationInterface_h_
16
+
17
+ #include "KeccakF-1600-int-set.h"
18
+
19
+ void KeccakInitialize( void );
20
+ void KeccakInitializeState(unsigned char *state);
21
+ void KeccakPermutation(unsigned char *state);
22
+ #ifdef ProvideFast576
23
+ void KeccakAbsorb576bits(unsigned char *state, const unsigned char *data);
24
+ #endif
25
+ #ifdef ProvideFast832
26
+ void KeccakAbsorb832bits(unsigned char *state, const unsigned char *data);
27
+ #endif
28
+ #ifdef ProvideFast1024
29
+ void KeccakAbsorb1024bits(unsigned char *state, const unsigned char *data);
30
+ #endif
31
+ #ifdef ProvideFast1088
32
+ void KeccakAbsorb1088bits(unsigned char *state, const unsigned char *data);
33
+ #endif
34
+ #ifdef ProvideFast1152
35
+ void KeccakAbsorb1152bits(unsigned char *state, const unsigned char *data);
36
+ #endif
37
+ #ifdef ProvideFast1344
38
+ void KeccakAbsorb1344bits(unsigned char *state, const unsigned char *data);
39
+ #endif
40
+ void KeccakAbsorb(unsigned char *state, const unsigned char *data, unsigned int laneCount);
41
+ #ifdef ProvideFast1024
42
+ void KeccakExtract1024bits(const unsigned char *state, unsigned char *data);
43
+ #endif
44
+ void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int laneCount);
45
+
46
+ #endif
@@ -0,0 +1,4 @@
1
+ #define Unrolling 2
2
+ //#define UseBebigokimisa
3
+ //#define UseInterleaveTables
4
+ #define UseSchedule 3
@@ -0,0 +1,524 @@
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 the designers,
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 "brg_endian.h"
16
+ #include "KeccakF-1600-opt32-settings.h"
17
+ #include "KeccakF-1600-interface.h"
18
+
19
+ typedef unsigned char UINT8;
20
+ typedef unsigned short UINT16;
21
+ typedef unsigned int UINT32;
22
+ typedef unsigned long long int UINT64;
23
+
24
+ #ifdef UseInterleaveTables
25
+ int interleaveTablesBuilt = 0;
26
+ UINT16 interleaveTable[65536];
27
+ UINT16 deinterleaveTable[65536];
28
+
29
+ void buildInterleaveTables()
30
+ {
31
+ UINT32 i, j;
32
+ UINT16 x;
33
+
34
+ if (!interleaveTablesBuilt) {
35
+ for(i=0; i<65536; i++) {
36
+ x = 0;
37
+ for(j=0; j<16; j++) {
38
+ if (i & (1 << j))
39
+ x |= (1 << (j/2 + 8*(j%2)));
40
+ }
41
+ interleaveTable[i] = x;
42
+ deinterleaveTable[x] = (UINT16)i;
43
+ }
44
+ interleaveTablesBuilt = 1;
45
+ }
46
+ }
47
+
48
+ #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
49
+
50
+ #define xor2bytesIntoInterleavedWords(even, odd, source, j) \
51
+ i##j = interleaveTable[((const UINT16*)source)[j]]; \
52
+ ((UINT8*)even)[j] ^= i##j & 0xFF; \
53
+ ((UINT8*)odd)[j] ^= i##j >> 8;
54
+
55
+ #define setInterleavedWordsInto2bytes(dest, even, odd, j) \
56
+ d##j = deinterleaveTable[((even >> (j*8)) & 0xFF) ^ (((odd >> (j*8)) & 0xFF) << 8)]; \
57
+ ((UINT16*)dest)[j] = d##j;
58
+
59
+ #else // (PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN)
60
+
61
+ #define xor2bytesIntoInterleavedWords(even, odd, source, j) \
62
+ i##j = interleaveTable[source[2*j] ^ ((UINT16)source[2*j+1] << 8)]; \
63
+ *even ^= (i##j & 0xFF) << (j*8); \
64
+ *odd ^= ((i##j >> 8) & 0xFF) << (j*8);
65
+
66
+ #define setInterleavedWordsInto2bytes(dest, even, odd, j) \
67
+ d##j = deinterleaveTable[((even >> (j*8)) & 0xFF) ^ (((odd >> (j*8)) & 0xFF) << 8)]; \
68
+ dest[2*j] = d##j & 0xFF; \
69
+ dest[2*j+1] = d##j >> 8;
70
+
71
+ #endif // Endianness
72
+
73
+ void xor8bytesIntoInterleavedWords(UINT32 *even, UINT32 *odd, const UINT8* source)
74
+ {
75
+ UINT16 i0, i1, i2, i3;
76
+
77
+ xor2bytesIntoInterleavedWords(even, odd, source, 0)
78
+ xor2bytesIntoInterleavedWords(even, odd, source, 1)
79
+ xor2bytesIntoInterleavedWords(even, odd, source, 2)
80
+ xor2bytesIntoInterleavedWords(even, odd, source, 3)
81
+ }
82
+
83
+ #define xorLanesIntoState(laneCount, state, input) \
84
+ { \
85
+ int i; \
86
+ for(i=0; i<(laneCount); i++) \
87
+ xor8bytesIntoInterleavedWords(state+i*2, state+i*2+1, input+i*8); \
88
+ }
89
+
90
+ void setInterleavedWordsInto8bytes(UINT8* dest, UINT32 even, UINT32 odd)
91
+ {
92
+ UINT16 d0, d1, d2, d3;
93
+
94
+ setInterleavedWordsInto2bytes(dest, even, odd, 0)
95
+ setInterleavedWordsInto2bytes(dest, even, odd, 1)
96
+ setInterleavedWordsInto2bytes(dest, even, odd, 2)
97
+ setInterleavedWordsInto2bytes(dest, even, odd, 3)
98
+ }
99
+
100
+ #define extractLanes(laneCount, state, data) \
101
+ { \
102
+ int i; \
103
+ for(i=0; i<(laneCount); i++) \
104
+ setInterleavedWordsInto8bytes(data+i*8, ((UINT32*)state)[i*2], ((UINT32*)state)[i*2+1]); \
105
+ }
106
+
107
+ #else // No interleaving tables
108
+
109
+ #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
110
+
111
+ // Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002
112
+ #define xorInterleavedLE(rateInLanes, state, input) \
113
+ { \
114
+ const UINT32 * pI = (const UINT32 *)input; \
115
+ UINT32 * pS = state; \
116
+ UINT32 t, x0, x1; \
117
+ int i; \
118
+ for (i = (rateInLanes)-1; i >= 0; --i) \
119
+ { \
120
+ x0 = *(pI++); \
121
+ t = (x0 ^ (x0 >> 1)) & 0x22222222UL; x0 = x0 ^ t ^ (t << 1); \
122
+ t = (x0 ^ (x0 >> 2)) & 0x0C0C0C0CUL; x0 = x0 ^ t ^ (t << 2); \
123
+ t = (x0 ^ (x0 >> 4)) & 0x00F000F0UL; x0 = x0 ^ t ^ (t << 4); \
124
+ t = (x0 ^ (x0 >> 8)) & 0x0000FF00UL; x0 = x0 ^ t ^ (t << 8); \
125
+ x1 = *(pI++); \
126
+ t = (x1 ^ (x1 >> 1)) & 0x22222222UL; x1 = x1 ^ t ^ (t << 1); \
127
+ t = (x1 ^ (x1 >> 2)) & 0x0C0C0C0CUL; x1 = x1 ^ t ^ (t << 2); \
128
+ t = (x1 ^ (x1 >> 4)) & 0x00F000F0UL; x1 = x1 ^ t ^ (t << 4); \
129
+ t = (x1 ^ (x1 >> 8)) & 0x0000FF00UL; x1 = x1 ^ t ^ (t << 8); \
130
+ *(pS++) ^= (UINT16)x0 | (x1 << 16); \
131
+ *(pS++) ^= (x0 >> 16) | (x1 & 0xFFFF0000); \
132
+ } \
133
+ }
134
+
135
+ #define xorLanesIntoState(laneCount, state, input) \
136
+ xorInterleavedLE(laneCount, state, input)
137
+
138
+ #else // (PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN)
139
+
140
+ // Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002
141
+ UINT64 toInterleaving(UINT64 x)
142
+ {
143
+ UINT64 t;
144
+
145
+ t = (x ^ (x >> 1)) & 0x2222222222222222ULL; x = x ^ t ^ (t << 1);
146
+ t = (x ^ (x >> 2)) & 0x0C0C0C0C0C0C0C0CULL; x = x ^ t ^ (t << 2);
147
+ t = (x ^ (x >> 4)) & 0x00F000F000F000F0ULL; x = x ^ t ^ (t << 4);
148
+ t = (x ^ (x >> 8)) & 0x0000FF000000FF00ULL; x = x ^ t ^ (t << 8);
149
+ t = (x ^ (x >> 16)) & 0x00000000FFFF0000ULL; x = x ^ t ^ (t << 16);
150
+
151
+ return x;
152
+ }
153
+
154
+ void xor8bytesIntoInterleavedWords(UINT32* evenAndOdd, const UINT8* source)
155
+ {
156
+ // This can be optimized
157
+ UINT64 sourceWord =
158
+ (UINT64)source[0]
159
+ ^ (((UINT64)source[1]) << 8)
160
+ ^ (((UINT64)source[2]) << 16)
161
+ ^ (((UINT64)source[3]) << 24)
162
+ ^ (((UINT64)source[4]) << 32)
163
+ ^ (((UINT64)source[5]) << 40)
164
+ ^ (((UINT64)source[6]) << 48)
165
+ ^ (((UINT64)source[7]) << 56);
166
+ UINT64 evenAndOddWord = toInterleaving(sourceWord);
167
+ evenAndOdd[0] ^= (UINT32)evenAndOddWord;
168
+ evenAndOdd[1] ^= (UINT32)(evenAndOddWord >> 32);
169
+ }
170
+
171
+ #define xorLanesIntoState(laneCount, state, input) \
172
+ { \
173
+ int i; \
174
+ for(i=0; i<(laneCount); i++) \
175
+ xor8bytesIntoInterleavedWords(state+i*2, input+i*8); \
176
+ }
177
+
178
+ #endif // Endianness
179
+
180
+ // Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002
181
+ UINT64 fromInterleaving(UINT64 x)
182
+ {
183
+ UINT64 t;
184
+
185
+ t = (x ^ (x >> 16)) & 0x00000000FFFF0000ULL; x = x ^ t ^ (t << 16);
186
+ t = (x ^ (x >> 8)) & 0x0000FF000000FF00ULL; x = x ^ t ^ (t << 8);
187
+ t = (x ^ (x >> 4)) & 0x00F000F000F000F0ULL; x = x ^ t ^ (t << 4);
188
+ t = (x ^ (x >> 2)) & 0x0C0C0C0C0C0C0C0CULL; x = x ^ t ^ (t << 2);
189
+ t = (x ^ (x >> 1)) & 0x2222222222222222ULL; x = x ^ t ^ (t << 1);
190
+
191
+ return x;
192
+ }
193
+
194
+ void setInterleavedWordsInto8bytes(UINT8* dest, UINT32* evenAndOdd)
195
+ {
196
+ #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
197
+ ((UINT64*)dest)[0] = fromInterleaving(*(UINT64*)evenAndOdd);
198
+ #else // (PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN)
199
+ // This can be optimized
200
+ UINT64 evenAndOddWord = (UINT64)evenAndOdd[0] ^ ((UINT64)evenAndOdd[1] << 32);
201
+ UINT64 destWord = fromInterleaving(evenAndOddWord);
202
+ dest[0] = destWord & 0xFF;
203
+ dest[1] = (destWord >> 8) & 0xFF;
204
+ dest[2] = (destWord >> 16) & 0xFF;
205
+ dest[3] = (destWord >> 24) & 0xFF;
206
+ dest[4] = (destWord >> 32) & 0xFF;
207
+ dest[5] = (destWord >> 40) & 0xFF;
208
+ dest[6] = (destWord >> 48) & 0xFF;
209
+ dest[7] = (destWord >> 56) & 0xFF;
210
+ #endif // Endianness
211
+ }
212
+
213
+ #define extractLanes(laneCount, state, data) \
214
+ { \
215
+ int i; \
216
+ for(i=0; i<(laneCount); i++) \
217
+ setInterleavedWordsInto8bytes(data+i*8, (UINT32*)state+i*2); \
218
+ }
219
+
220
+ #endif // With or without interleaving tables
221
+
222
+ #if defined(_MSC_VER)
223
+ #define ROL32(a, offset) _rotl(a, offset)
224
+ #elif (defined (__arm__) && defined(__ARMCC_VERSION))
225
+ #define ROL32(a, offset) __ror(a, 32-(offset))
226
+ #else
227
+ #define ROL32(a, offset) ((((UINT32)a) << (offset)) ^ (((UINT32)a) >> (32-(offset))))
228
+ #endif
229
+
230
+ #include "KeccakF-1600-unrolling.macros"
231
+ #include "KeccakF-1600-32.macros"
232
+
233
+ #if (UseSchedule == 3)
234
+
235
+ #ifdef UseBebigokimisa
236
+ #error "No lane complementing with schedule 3."
237
+ #endif
238
+
239
+ #if (Unrolling != 2)
240
+ #error "Only unrolling 2 is supported by schedule 3."
241
+ #endif
242
+
243
+ void KeccakPermutationOnWords(UINT32 *state)
244
+ {
245
+ rounds
246
+ }
247
+
248
+ void KeccakPermutationOnWordsAfterXoring(UINT32 *state, const UINT8 *input, unsigned int laneCount)
249
+ {
250
+ xorLanesIntoState(laneCount, state, input)
251
+ rounds
252
+ }
253
+
254
+ #ifdef ProvideFast576
255
+ void KeccakPermutationOnWordsAfterXoring576bits(UINT32 *state, const UINT8 *input)
256
+ {
257
+ xorLanesIntoState(9, state, input)
258
+ rounds
259
+ }
260
+ #endif
261
+
262
+ #ifdef ProvideFast832
263
+ void KeccakPermutationOnWordsAfterXoring832bits(UINT32 *state, const UINT8 *input)
264
+ {
265
+ xorLanesIntoState(13, state, input)
266
+ rounds
267
+ }
268
+ #endif
269
+
270
+ #ifdef ProvideFast1024
271
+ void KeccakPermutationOnWordsAfterXoring1024bits(UINT32 *state, const UINT8 *input)
272
+ {
273
+ xorLanesIntoState(16, state, input)
274
+ rounds
275
+ }
276
+ #endif
277
+
278
+ #ifdef ProvideFast1088
279
+ void KeccakPermutationOnWordsAfterXoring1088bits(UINT32 *state, const UINT8 *input)
280
+ {
281
+ xorLanesIntoState(17, state, input)
282
+ rounds
283
+ }
284
+ #endif
285
+
286
+ #ifdef ProvideFast1152
287
+ void KeccakPermutationOnWordsAfterXoring1152bits(UINT32 *state, const UINT8 *input)
288
+ {
289
+ xorLanesIntoState(18, state, input)
290
+ rounds
291
+ }
292
+ #endif
293
+
294
+ #ifdef ProvideFast1344
295
+ void KeccakPermutationOnWordsAfterXoring1344bits(UINT32 *state, const UINT8 *input)
296
+ {
297
+ xorLanesIntoState(21, state, input)
298
+ rounds
299
+ }
300
+ #endif
301
+
302
+ #else // (Schedule != 3)
303
+
304
+ void KeccakPermutationOnWords(UINT32 *state)
305
+ {
306
+ declareABCDE
307
+ #if (Unrolling != 24)
308
+ unsigned int i;
309
+ #endif
310
+
311
+ copyFromState(A, state)
312
+ rounds
313
+ }
314
+
315
+ void KeccakPermutationOnWordsAfterXoring(UINT32 *state, const UINT8 *input, unsigned int laneCount)
316
+ {
317
+ declareABCDE
318
+ unsigned int i;
319
+
320
+ xorLanesIntoState(laneCount, state, input)
321
+ copyFromState(A, state)
322
+ rounds
323
+ }
324
+
325
+ #ifdef ProvideFast576
326
+ void KeccakPermutationOnWordsAfterXoring576bits(UINT32 *state, const UINT8 *input)
327
+ {
328
+ declareABCDE
329
+ unsigned int i;
330
+
331
+ xorLanesIntoState(9, state, input)
332
+ copyFromState(A, state)
333
+ rounds
334
+ }
335
+ #endif
336
+
337
+ #ifdef ProvideFast832
338
+ void KeccakPermutationOnWordsAfterXoring832bits(UINT32 *state, const UINT8 *input)
339
+ {
340
+ declareABCDE
341
+ unsigned int i;
342
+
343
+ xorLanesIntoState(13, state, input)
344
+ copyFromState(A, state)
345
+ rounds
346
+ }
347
+ #endif
348
+
349
+ #ifdef ProvideFast1024
350
+ void KeccakPermutationOnWordsAfterXoring1024bits(UINT32 *state, const UINT8 *input)
351
+ {
352
+ declareABCDE
353
+ unsigned int i;
354
+
355
+ xorLanesIntoState(16, state, input)
356
+ copyFromState(A, state)
357
+ rounds
358
+ }
359
+ #endif
360
+
361
+ #ifdef ProvideFast1088
362
+ void KeccakPermutationOnWordsAfterXoring1088bits(UINT32 *state, const UINT8 *input)
363
+ {
364
+ declareABCDE
365
+ unsigned int i;
366
+
367
+ xorLanesIntoState(17, state, input)
368
+ copyFromState(A, state)
369
+ rounds
370
+ }
371
+ #endif
372
+
373
+ #ifdef ProvideFast1152
374
+ void KeccakPermutationOnWordsAfterXoring1152bits(UINT32 *state, const UINT8 *input)
375
+ {
376
+ declareABCDE
377
+ unsigned int i;
378
+
379
+ xorLanesIntoState(18, state, input)
380
+ copyFromState(A, state)
381
+ rounds
382
+ }
383
+ #endif
384
+
385
+ #ifdef ProvideFast1344
386
+ void KeccakPermutationOnWordsAfterXoring1344bits(UINT32 *state, const UINT8 *input)
387
+ {
388
+ declareABCDE
389
+ unsigned int i;
390
+
391
+ xorLanesIntoState(21, state, input)
392
+ copyFromState(A, state)
393
+ rounds
394
+ }
395
+ #endif
396
+
397
+ #endif
398
+
399
+ void KeccakInitialize()
400
+ {
401
+ #ifdef UseInterleaveTables
402
+ buildInterleaveTables();
403
+ #endif
404
+ }
405
+
406
+ void KeccakInitializeState(unsigned char *state)
407
+ {
408
+ memset(state, 0, 200);
409
+ #ifdef UseBebigokimisa
410
+ ((UINT32*)state)[ 2] = ~(UINT32)0;
411
+ ((UINT32*)state)[ 3] = ~(UINT32)0;
412
+ ((UINT32*)state)[ 4] = ~(UINT32)0;
413
+ ((UINT32*)state)[ 5] = ~(UINT32)0;
414
+ ((UINT32*)state)[16] = ~(UINT32)0;
415
+ ((UINT32*)state)[17] = ~(UINT32)0;
416
+ ((UINT32*)state)[24] = ~(UINT32)0;
417
+ ((UINT32*)state)[25] = ~(UINT32)0;
418
+ ((UINT32*)state)[34] = ~(UINT32)0;
419
+ ((UINT32*)state)[35] = ~(UINT32)0;
420
+ ((UINT32*)state)[40] = ~(UINT32)0;
421
+ ((UINT32*)state)[41] = ~(UINT32)0;
422
+ #endif
423
+ }
424
+
425
+ void KeccakPermutation(unsigned char *state)
426
+ {
427
+ // We assume the state is always stored as interleaved 32-bit words
428
+ KeccakPermutationOnWords((UINT32*)state);
429
+ }
430
+
431
+ #ifdef ProvideFast576
432
+ void KeccakAbsorb576bits(unsigned char *state, const unsigned char *data)
433
+ {
434
+ KeccakPermutationOnWordsAfterXoring576bits((UINT32*)state, data);
435
+ }
436
+ #endif
437
+
438
+ #ifdef ProvideFast832
439
+ void KeccakAbsorb832bits(unsigned char *state, const unsigned char *data)
440
+ {
441
+ KeccakPermutationOnWordsAfterXoring832bits((UINT32*)state, data);
442
+ }
443
+ #endif
444
+
445
+ #ifdef ProvideFast1024
446
+ void KeccakAbsorb1024bits(unsigned char *state, const unsigned char *data)
447
+ {
448
+ KeccakPermutationOnWordsAfterXoring1024bits((UINT32*)state, data);
449
+ }
450
+ #endif
451
+
452
+ #ifdef ProvideFast1088
453
+ void KeccakAbsorb1088bits(unsigned char *state, const unsigned char *data)
454
+ {
455
+ KeccakPermutationOnWordsAfterXoring1088bits((UINT32*)state, data);
456
+ }
457
+ #endif
458
+
459
+ #ifdef ProvideFast1152
460
+ void KeccakAbsorb1152bits(unsigned char *state, const unsigned char *data)
461
+ {
462
+ KeccakPermutationOnWordsAfterXoring1152bits((UINT32*)state, data);
463
+ }
464
+ #endif
465
+
466
+ #ifdef ProvideFast1344
467
+ void KeccakAbsorb1344bits(unsigned char *state, const unsigned char *data)
468
+ {
469
+ KeccakPermutationOnWordsAfterXoring1344bits((UINT32*)state, data);
470
+ }
471
+ #endif
472
+
473
+ void KeccakAbsorb(unsigned char *state, const unsigned char *data, unsigned int laneCount)
474
+ {
475
+ KeccakPermutationOnWordsAfterXoring((UINT32*)state, data, laneCount);
476
+ }
477
+
478
+ #ifdef ProvideFast1024
479
+ void KeccakExtract1024bits(const unsigned char *state, unsigned char *data)
480
+ {
481
+ extractLanes(16, state, data)
482
+ #ifdef UseBebigokimisa
483
+ ((UINT32*)data)[ 2] = ~((UINT32*)data)[ 2];
484
+ ((UINT32*)data)[ 3] = ~((UINT32*)data)[ 3];
485
+ ((UINT32*)data)[ 4] = ~((UINT32*)data)[ 4];
486
+ ((UINT32*)data)[ 5] = ~((UINT32*)data)[ 5];
487
+ ((UINT32*)data)[16] = ~((UINT32*)data)[16];
488
+ ((UINT32*)data)[17] = ~((UINT32*)data)[17];
489
+ ((UINT32*)data)[24] = ~((UINT32*)data)[24];
490
+ ((UINT32*)data)[25] = ~((UINT32*)data)[25];
491
+ #endif
492
+ }
493
+ #endif
494
+
495
+ void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int laneCount)
496
+ {
497
+ extractLanes(laneCount, state, data)
498
+ #ifdef UseBebigokimisa
499
+ if (laneCount > 1) {
500
+ ((UINT32*)data)[ 2] = ~((UINT32*)data)[ 2];
501
+ ((UINT32*)data)[ 3] = ~((UINT32*)data)[ 3];
502
+ if (laneCount > 2) {
503
+ ((UINT32*)data)[ 4] = ~((UINT32*)data)[ 4];
504
+ ((UINT32*)data)[ 5] = ~((UINT32*)data)[ 5];
505
+ if (laneCount > 8) {
506
+ ((UINT32*)data)[16] = ~((UINT32*)data)[16];
507
+ ((UINT32*)data)[17] = ~((UINT32*)data)[17];
508
+ if (laneCount > 12) {
509
+ ((UINT32*)data)[24] = ~((UINT32*)data)[24];
510
+ ((UINT32*)data)[25] = ~((UINT32*)data)[25];
511
+ if (laneCount > 17) {
512
+ ((UINT32*)data)[34] = ~((UINT32*)data)[34];
513
+ ((UINT32*)data)[35] = ~((UINT32*)data)[35];
514
+ if (laneCount > 20) {
515
+ ((UINT32*)data)[40] = ~((UINT32*)data)[40];
516
+ ((UINT32*)data)[41] = ~((UINT32*)data)[41];
517
+ }
518
+ }
519
+ }
520
+ }
521
+ }
522
+ }
523
+ #endif
524
+ }