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,38 @@
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 _DoublePermutation_h_
15
+ #define _DoublePermutation_h_
16
+
17
+ #include <x86intrin.h>
18
+ typedef __m128i V128;
19
+
20
+ void KeccakDoublePermutationOnWords(V128 *state);
21
+ void KeccakDoublePermutationOnWordsAfterXoring2x512bits(V128 *state, const V128 *input);
22
+ void KeccakDoublePermutationOnWordsAfterXoring2x1024bits(V128 *state, const V128 *input);
23
+ void KeccakDoublePermutationOnWordsAfterXoring2x1088bits(V128 *state, const V128 *input);
24
+ void KeccakDoublePermutationOnWordsAfterXoring2x1344bits(V128 *state, const V128 *input);
25
+ void KeccakInitializeDoubleState(V128 *state);
26
+
27
+ #define KeccakPermutationSize 1600
28
+ #define KeccakPermutationSizeInBytes (KeccakPermutationSize/8)
29
+
30
+ #if defined(__GNUC__)
31
+ #define ALIGN __attribute__ ((aligned(32)))
32
+ #elif defined(_MSC_VER)
33
+ #define ALIGN __declspec(align(32))
34
+ #else
35
+ #define ALIGN
36
+ #endif
37
+
38
+ #endif
@@ -0,0 +1,124 @@
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
+ #if (Unrolling == 24)
15
+ #define rounds \
16
+ prepareTheta \
17
+ thetaRhoPiChiIotaPrepareTheta( 0, A, E) \
18
+ thetaRhoPiChiIotaPrepareTheta( 1, E, A) \
19
+ thetaRhoPiChiIotaPrepareTheta( 2, A, E) \
20
+ thetaRhoPiChiIotaPrepareTheta( 3, E, A) \
21
+ thetaRhoPiChiIotaPrepareTheta( 4, A, E) \
22
+ thetaRhoPiChiIotaPrepareTheta( 5, E, A) \
23
+ thetaRhoPiChiIotaPrepareTheta( 6, A, E) \
24
+ thetaRhoPiChiIotaPrepareTheta( 7, E, A) \
25
+ thetaRhoPiChiIotaPrepareTheta( 8, A, E) \
26
+ thetaRhoPiChiIotaPrepareTheta( 9, E, A) \
27
+ thetaRhoPiChiIotaPrepareTheta(10, A, E) \
28
+ thetaRhoPiChiIotaPrepareTheta(11, E, A) \
29
+ thetaRhoPiChiIotaPrepareTheta(12, A, E) \
30
+ thetaRhoPiChiIotaPrepareTheta(13, E, A) \
31
+ thetaRhoPiChiIotaPrepareTheta(14, A, E) \
32
+ thetaRhoPiChiIotaPrepareTheta(15, E, A) \
33
+ thetaRhoPiChiIotaPrepareTheta(16, A, E) \
34
+ thetaRhoPiChiIotaPrepareTheta(17, E, A) \
35
+ thetaRhoPiChiIotaPrepareTheta(18, A, E) \
36
+ thetaRhoPiChiIotaPrepareTheta(19, E, A) \
37
+ thetaRhoPiChiIotaPrepareTheta(20, A, E) \
38
+ thetaRhoPiChiIotaPrepareTheta(21, E, A) \
39
+ thetaRhoPiChiIotaPrepareTheta(22, A, E) \
40
+ thetaRhoPiChiIota(23, E, A) \
41
+ copyToState(state, A)
42
+ #elif (Unrolling == 12)
43
+ #define rounds \
44
+ prepareTheta \
45
+ for(i=0; i<24; i+=12) { \
46
+ thetaRhoPiChiIotaPrepareTheta(i , A, E) \
47
+ thetaRhoPiChiIotaPrepareTheta(i+ 1, E, A) \
48
+ thetaRhoPiChiIotaPrepareTheta(i+ 2, A, E) \
49
+ thetaRhoPiChiIotaPrepareTheta(i+ 3, E, A) \
50
+ thetaRhoPiChiIotaPrepareTheta(i+ 4, A, E) \
51
+ thetaRhoPiChiIotaPrepareTheta(i+ 5, E, A) \
52
+ thetaRhoPiChiIotaPrepareTheta(i+ 6, A, E) \
53
+ thetaRhoPiChiIotaPrepareTheta(i+ 7, E, A) \
54
+ thetaRhoPiChiIotaPrepareTheta(i+ 8, A, E) \
55
+ thetaRhoPiChiIotaPrepareTheta(i+ 9, E, A) \
56
+ thetaRhoPiChiIotaPrepareTheta(i+10, A, E) \
57
+ thetaRhoPiChiIotaPrepareTheta(i+11, E, A) \
58
+ } \
59
+ copyToState(state, A)
60
+ #elif (Unrolling == 8)
61
+ #define rounds \
62
+ prepareTheta \
63
+ for(i=0; i<24; i+=8) { \
64
+ thetaRhoPiChiIotaPrepareTheta(i , A, E) \
65
+ thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
66
+ thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
67
+ thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \
68
+ thetaRhoPiChiIotaPrepareTheta(i+4, A, E) \
69
+ thetaRhoPiChiIotaPrepareTheta(i+5, E, A) \
70
+ thetaRhoPiChiIotaPrepareTheta(i+6, A, E) \
71
+ thetaRhoPiChiIotaPrepareTheta(i+7, E, A) \
72
+ } \
73
+ copyToState(state, A)
74
+ #elif (Unrolling == 6)
75
+ #define rounds \
76
+ prepareTheta \
77
+ for(i=0; i<24; i+=6) { \
78
+ thetaRhoPiChiIotaPrepareTheta(i , A, E) \
79
+ thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
80
+ thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
81
+ thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \
82
+ thetaRhoPiChiIotaPrepareTheta(i+4, A, E) \
83
+ thetaRhoPiChiIotaPrepareTheta(i+5, E, A) \
84
+ } \
85
+ copyToState(state, A)
86
+ #elif (Unrolling == 4)
87
+ #define rounds \
88
+ prepareTheta \
89
+ for(i=0; i<24; i+=4) { \
90
+ thetaRhoPiChiIotaPrepareTheta(i , A, E) \
91
+ thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
92
+ thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
93
+ thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \
94
+ } \
95
+ copyToState(state, A)
96
+ #elif (Unrolling == 3)
97
+ #define rounds \
98
+ prepareTheta \
99
+ for(i=0; i<24; i+=3) { \
100
+ thetaRhoPiChiIotaPrepareTheta(i , A, E) \
101
+ thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
102
+ thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
103
+ copyStateVariables(A, E) \
104
+ } \
105
+ copyToState(state, A)
106
+ #elif (Unrolling == 2)
107
+ #define rounds \
108
+ prepareTheta \
109
+ for(i=0; i<24; i+=2) { \
110
+ thetaRhoPiChiIotaPrepareTheta(i , A, E) \
111
+ thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
112
+ } \
113
+ copyToState(state, A)
114
+ #elif (Unrolling == 1)
115
+ #define rounds \
116
+ prepareTheta \
117
+ for(i=0; i<24; i++) { \
118
+ thetaRhoPiChiIotaPrepareTheta(i , A, E) \
119
+ copyStateVariables(A, E) \
120
+ } \
121
+ copyToState(state, A)
122
+ #else
123
+ #error "Unrolling is not correctly specified!"
124
+ #endif
@@ -0,0 +1,81 @@
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 "crypto_hash.h"
16
+ #include "DoublePermutation.h"
17
+ #include "Keccakc256TreeD2.h"
18
+
19
+ int crypto_hash(unsigned char *out, const unsigned char *in, unsigned long long inlen)
20
+ {
21
+ ALIGN unsigned char state[KeccakPermutationSizeInBytes*2];
22
+ ALIGN unsigned char buffer[rateInBytes*2];
23
+ ALIGN unsigned char finalNode[rateInBytes*2];
24
+ unsigned int padLeftBranch, padRightBranch;
25
+ unsigned int i;
26
+
27
+ KeccakInitializeDoubleState((V128*)state);
28
+
29
+ while(inlen >= rateInBytes*2) {
30
+ KeccakDoublePermutationOnWordsAfterXoring2x1344bits((V128*)state, (const V128*)in);
31
+ in += rateInBytes*2;
32
+ inlen -= rateInBytes*2;
33
+ }
34
+
35
+ memset(finalNode, 0, rateInBytes*2);
36
+ memset(buffer, 0, rateInBytes*2);
37
+ memcpy(buffer, in, inlen);
38
+ if (inlen % 16 < 8) {
39
+ padLeftBranch = inlen;
40
+ padRightBranch = (inlen/16)*16+8;
41
+ }
42
+ else {
43
+ padLeftBranch = ((inlen+15)/16)*16;
44
+ padRightBranch = inlen;
45
+ }
46
+ buffer[padRightBranch] = 0x02; //non-final bit and first bit of padding
47
+ buffer[rateInBytes*2-1] |= 0x80; // second bit of padding
48
+ if (padLeftBranch < rateInBytes*2) {
49
+ buffer[padLeftBranch] = 0x02; //non-final bit and first bit of padding
50
+ buffer[rateInBytes*2-8-1] |= 0x80; // second bit of padding
51
+ KeccakDoublePermutationOnWordsAfterXoring2x1344bits((V128*)state, (const V128*)buffer);
52
+ for(i=0; i<CinBytes/8; i++) {
53
+ memcpy(finalNode+i*16, state+i*16, 8);
54
+ memcpy(finalNode+CinBytes*2+i*16, state+i*16+8, 8);
55
+ }
56
+ }
57
+ else {
58
+ KeccakDoublePermutationOnWordsAfterXoring2x1344bits((V128*)state, (const V128*)buffer);
59
+ for(i=0; i<CinBytes/8; i++)
60
+ memcpy(finalNode+CinBytes*2+i*16, state+i*16+8, 8);
61
+ memset(buffer, 0, rateInBytes*2);
62
+ buffer[0] = 0x02; //non-final bit and first bit of padding
63
+ buffer[rateInBytes*2-8-1] |= 0x80; // second bit of padding
64
+ KeccakDoublePermutationOnWordsAfterXoring2x1344bits((V128*)state, (const V128*)buffer);
65
+ for(i=0; i<CinBytes/8; i++)
66
+ memcpy(finalNode+i*16, state+i*16, 8);
67
+ }
68
+ finalNode[CinBytes*4+0] = 0x40; // B=64 bits
69
+ finalNode[CinBytes*4+1] = 0x00; // B=64 bits
70
+ finalNode[CinBytes*4+2] = 0x00; // B=64 bits
71
+ finalNode[CinBytes*4+3] = 0x00; // B=64 bits
72
+ finalNode[CinBytes*4+4] = 0x00 | 0x20 | 0x40; // 5 bits set to zero (reserved for future use, for other layouts), plus final bit, plus first bit of padding
73
+ finalNode[rateInBytes*2-8-1] |= 0x80; // second bit of padding
74
+
75
+ KeccakInitializeDoubleState((V128*)state);
76
+ KeccakDoublePermutationOnWordsAfterXoring2x1344bits((V128*)state, (const V128*)finalNode);
77
+ for(i=0; i<rateInBytes/8; i++)
78
+ memcpy(out+i*8, state+i*16, 8);
79
+
80
+ return 0;
81
+ }
@@ -0,0 +1,18 @@
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
+ #define rate 1344
15
+ #define rateInBytes (rate/8)
16
+ #define C 256
17
+ #define CinBytes (C/8)
18
+
@@ -0,0 +1,81 @@
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 "crypto_hash.h"
16
+ #include "DoublePermutation.h"
17
+ #include "Keccakc512TreeD2.h"
18
+
19
+ int crypto_hash(unsigned char *out, const unsigned char *in, unsigned long long inlen)
20
+ {
21
+ ALIGN unsigned char state[KeccakPermutationSizeInBytes*2];
22
+ ALIGN unsigned char buffer[rateInBytes*2];
23
+ ALIGN unsigned char finalNode[rateInBytes*2];
24
+ unsigned int padLeftBranch, padRightBranch;
25
+ unsigned int i;
26
+
27
+ KeccakInitializeDoubleState((V128*)state);
28
+
29
+ while(inlen >= rateInBytes*2) {
30
+ KeccakDoublePermutationOnWordsAfterXoring2x1088bits((V128*)state, (const V128*)in);
31
+ in += rateInBytes*2;
32
+ inlen -= rateInBytes*2;
33
+ }
34
+
35
+ memset(finalNode, 0, rateInBytes*2);
36
+ memset(buffer, 0, rateInBytes*2);
37
+ memcpy(buffer, in, inlen);
38
+ if (inlen % 16 < 8) {
39
+ padLeftBranch = inlen;
40
+ padRightBranch = (inlen/16)*16+8;
41
+ }
42
+ else {
43
+ padLeftBranch = ((inlen+15)/16)*16;
44
+ padRightBranch = inlen;
45
+ }
46
+ buffer[padRightBranch] = 0x02; //non-final bit and first bit of padding
47
+ buffer[rateInBytes*2-1] |= 0x80; // second bit of padding
48
+ if (padLeftBranch < rateInBytes*2) {
49
+ buffer[padLeftBranch] = 0x02; //non-final bit and first bit of padding
50
+ buffer[rateInBytes*2-8-1] |= 0x80; // second bit of padding
51
+ KeccakDoublePermutationOnWordsAfterXoring2x1088bits((V128*)state, (const V128*)buffer);
52
+ for(i=0; i<CinBytes/8; i++) {
53
+ memcpy(finalNode+i*16, state+i*16, 8);
54
+ memcpy(finalNode+CinBytes*2+i*16, state+i*16+8, 8);
55
+ }
56
+ }
57
+ else {
58
+ KeccakDoublePermutationOnWordsAfterXoring2x1088bits((V128*)state, (const V128*)buffer);
59
+ for(i=0; i<CinBytes/8; i++)
60
+ memcpy(finalNode+CinBytes*2+i*16, state+i*16+8, 8);
61
+ memset(buffer, 0, rateInBytes*2);
62
+ buffer[0] = 0x02; //non-final bit and first bit of padding
63
+ buffer[rateInBytes*2-8-1] |= 0x80; // second bit of padding
64
+ KeccakDoublePermutationOnWordsAfterXoring2x1088bits((V128*)state, (const V128*)buffer);
65
+ for(i=0; i<CinBytes/8; i++)
66
+ memcpy(finalNode+i*16, state+i*16, 8);
67
+ }
68
+ finalNode[CinBytes*4+0] = 0x40; // B=64 bits
69
+ finalNode[CinBytes*4+1] = 0x00; // B=64 bits
70
+ finalNode[CinBytes*4+2] = 0x00; // B=64 bits
71
+ finalNode[CinBytes*4+3] = 0x00; // B=64 bits
72
+ finalNode[CinBytes*4+4] = 0x00 | 0x20 | 0x40; // 5 bits set to zero (reserved for future use, for other layouts), plus final bit, plus first bit of padding
73
+ finalNode[rateInBytes*2-8-1] |= 0x80; // second bit of padding
74
+
75
+ KeccakInitializeDoubleState((V128*)state);
76
+ KeccakDoublePermutationOnWordsAfterXoring2x1088bits((V128*)state, (const V128*)finalNode);
77
+ for(i=0; i<rateInBytes/8; i++)
78
+ memcpy(out+i*8, state+i*16, 8);
79
+
80
+ return 0;
81
+ }
@@ -0,0 +1,18 @@
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
+ #define rate 1088
15
+ #define rateInBytes (rate/8)
16
+ #define C 512
17
+ #define CinBytes (C/8)
18
+
@@ -0,0 +1,112 @@
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 <stdio.h>
15
+ #include <string.h>
16
+
17
+ #ifdef D2
18
+ #include "timing-Double.h"
19
+ #include "DoublePermutation.h"
20
+ #endif
21
+
22
+ #ifdef D4
23
+ #include "timing-Quad.h"
24
+ #include "QuadPermutation.h"
25
+ #endif
26
+
27
+ #if defined(c256) && defined(D2)
28
+ #include "Keccakc256TreeD2.h"
29
+ #endif
30
+ #if defined(c512) && defined(D2)
31
+ #include "Keccakc512TreeD2.h"
32
+ #endif
33
+
34
+
35
+ #ifdef D2
36
+ typedef unsigned long long int UINT64;
37
+
38
+ void printDoubleState(const UINT64* doubleState)
39
+ {
40
+ unsigned int i;
41
+ for(i=0; i<25; i++) {
42
+ printf("%08X", (doubleState[i*2] >> 32));
43
+ printf("%08X", (doubleState[i*2] & 0xFFFFFFFFULL));
44
+ if ((i%5) == 4)
45
+ printf("\n");
46
+ else
47
+ printf(" ");
48
+ }
49
+
50
+ printf("\n");
51
+
52
+ for(i=0; i<25; i++) {
53
+ printf("%08X", (doubleState[i*2+1] >> 32));
54
+ printf("%08X", (doubleState[i*2+1] & 0xFFFFFFFFULL));
55
+ if ((i%5) == 4)
56
+ printf("\n");
57
+ else
58
+ printf(" ");
59
+ }
60
+ }
61
+
62
+ void testDoublePermutation()
63
+ {
64
+ unsigned int i;
65
+ ALIGN UINT64 doubleState[25*2];
66
+ memset(doubleState, 0, sizeof(doubleState));
67
+ printf("Double state before:\n");
68
+ printDoubleState(doubleState);
69
+ KeccakDoublePermutationOnWords((V128*)doubleState);
70
+ printf("Double state after:\n");
71
+ printDoubleState(doubleState);
72
+
73
+ for(i=0; i<25; i++)
74
+ doubleState[i*2] = 0;
75
+
76
+ KeccakDoublePermutationOnWords((V128*)doubleState);
77
+ printf("Double state after after:\n");
78
+ printDoubleState(doubleState);
79
+ }
80
+ #endif
81
+
82
+ #ifdef rateInBytes
83
+ void testKeccakTree()
84
+ {
85
+ unsigned char message[1000];
86
+ unsigned char out[1000];
87
+ unsigned int len;
88
+ unsigned int i;
89
+
90
+ for(len=0; len<=1000; len++) {
91
+ for(i=0; i<len; i++)
92
+ message[i] = (unsigned char)(len-i);
93
+ crypto_hash(out, message, len);
94
+ printf("Message of length %d bits\n", len*8);
95
+ for(i=0; i<rateInBytes; i++)
96
+ printf("%02x ", out[i]);
97
+ printf("\n");
98
+ }
99
+ }
100
+ #endif
101
+
102
+ int main()
103
+ {
104
+ #ifdef D2
105
+ //testDoublePermutation();
106
+ #endif
107
+ #ifdef rateInBytes
108
+ testKeccakTree();
109
+ #endif
110
+ doTiming();
111
+ return 0;
112
+ }