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,88 @@
1
+ /*
2
+ The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
3
+ Michaël Peeters and Gilles Van Assche. For more information, feedback or
4
+ questions, please refer to our website: http://keccak.noekeon.org/
5
+
6
+ Implementation by Ronny Van Keer,
7
+ hereby denoted as "the implementer".
8
+
9
+ To the extent possible under law, the implementer has waived all copyright
10
+ and related or neighboring rights to the source code in this file.
11
+ http://creativecommons.org/publicdomain/zero/1.0/
12
+ */
13
+
14
+ #include "KeccakF-1600-interface.h"
15
+ #include "KeccakNISTInterface.h"
16
+ #include "string.h"
17
+
18
+ typedef unsigned char UINT8;
19
+ typedef unsigned short UINT16;
20
+ typedef unsigned int UINT32;
21
+
22
+ int main()
23
+ {
24
+ UINT32 x = 0;
25
+ int i;
26
+ {
27
+ UINT32 state[50];
28
+ const UINT32 imageOfAllZero[50] = {
29
+ 0xD33D89FB, 0xC4B60CAD, 0x2FAD58B0, 0x88AE581B, 0xF4262C1A,
30
+ 0x8A53D3EF, 0x77B4B09B, 0xE0147822, 0x10A38DCF, 0xB6305181,
31
+ 0xF723F2BE, 0xF9C67B78, 0x4EB02ABA, 0x8FCCC118, 0x2DC2E52E,
32
+ 0xA3B29275, 0x342F5536, 0xE4DD320A, 0x45C7C3EA, 0x493D8BE4,
33
+ 0x9C1717E7, 0xF3E75194, 0x12A23D11, 0xEDD52441, 0x13E6DBFF,
34
+ 0x8C61BB03, 0x945B1B82, 0x1E4A11A5, 0x1C3453E7, 0x0D730C1B,
35
+ 0x3B9C1D29, 0x0C534AF4, 0xA6EC29CC, 0x4FFDAA4D, 0x96C7DAA5,
36
+ 0x45487850, 0x4ECFBC29, 0xE630383B, 0x26806B48, 0xA7EB2B5A,
37
+ 0x62D02426, 0x8265F750, 0x49D20B1A, 0x20E4D82C, 0x6F72B2B8,
38
+ 0x1C45D049, 0xFEA9F415, 0x4D0E74C7, 0x8DFDEA09, 0xFCF72ED2 };
39
+
40
+ // Test 1 (all-zero state through Keccak-f[1600])
41
+ memset(state, 0, 50*sizeof(UINT32));
42
+ KeccakPermutation((unsigned char*)state);
43
+ for(i=0; i<50; i++)
44
+ if (state[i] != imageOfAllZero[i])
45
+ for( ; ; ) {
46
+ // Kaccek (aka other algo)
47
+ x++;
48
+ }
49
+ // For benchmarking
50
+ {
51
+ #ifdef ProvideFast1024
52
+ KeccakAbsorb1024bits((unsigned char*)state, (unsigned char*)imageOfAllZero);
53
+ #else
54
+ KeccakAbsorb((unsigned char*)state, (unsigned char*)imageOfAllZero, 16);
55
+ #endif
56
+ }
57
+ }
58
+ {
59
+ hashState state;
60
+ const UINT8 Msg29[4] = { 0x53, 0x58, 0x7B, 0xC8 };
61
+ const UINT8 Msg29_out[160] = {
62
+ 0x2F, 0x07, 0xBF, 0x03, 0xB8, 0x24, 0x66, 0x46, 0x3A, 0xC4, 0xD3, 0xD2, 0xDA, 0x12, 0xEC, 0xD3,
63
+ 0x47, 0xFF, 0xCF, 0x41, 0x7D, 0xF6, 0x1C, 0x2F, 0x3A, 0x67, 0x82, 0xB7, 0x49, 0xE6, 0x4C, 0xEC,
64
+ 0x15, 0x94, 0x46, 0xBD, 0x20, 0x1D, 0xC8, 0x79, 0x71, 0x8C, 0xEF, 0x77, 0x5A, 0xE7, 0x20, 0xA1,
65
+ 0x83, 0x8B, 0xB9, 0x00, 0x66, 0x42, 0x21, 0xE0, 0x8A, 0x68, 0x9C, 0xC8, 0xB4, 0x70, 0x27, 0x61,
66
+ 0x8D, 0xD1, 0xBA, 0x16, 0x7D, 0xB0, 0x7C, 0x3E, 0x9F, 0xFD, 0x86, 0xF6, 0x88, 0xA5, 0x76, 0x2D,
67
+ 0xBC, 0x07, 0xD8, 0x7D, 0x7C, 0xC9, 0x3A, 0xA8, 0x5E, 0x33, 0xC6, 0x53, 0xF7, 0x84, 0xD3, 0xB8,
68
+ 0x99, 0x7F, 0x0B, 0x87, 0x10, 0xD2, 0xEF, 0xFB, 0xFE, 0x2E, 0x5E, 0x45, 0x4B, 0x83, 0x4E, 0x43,
69
+ 0xF2, 0x57, 0xFE, 0xB0, 0xE0, 0xB4, 0xCA, 0xAF, 0x94, 0xF8, 0x5D, 0x21, 0x24, 0xDD, 0x41, 0x53,
70
+ 0x02, 0x3F, 0x15, 0xF9, 0xD7, 0x40, 0x33, 0x99, 0x7B, 0x73, 0x05, 0x34, 0x00, 0xD2, 0x5C, 0x58,
71
+ 0x1F, 0x46, 0xC3, 0xA8, 0x41, 0x96, 0x2E, 0xBF, 0xDF, 0x3D, 0x75, 0x98, 0x50, 0xCA, 0xAA, 0x9D };
72
+ UINT8 output[160];
73
+
74
+ // Test 2 (message of length 29 from ShortMsgKAT_0.txt)
75
+ Init(&state, 0);
76
+ Update(&state, Msg29, 29);
77
+ Final(&state, 0);
78
+ Squeeze(&state, output, 160*8);
79
+ for(i=0; i<160; i++)
80
+ if (output[i] != Msg29_out[i])
81
+ for( ; ; ) {
82
+ // Kaccek (aka other algo)
83
+ x++;
84
+ }
85
+ }
86
+
87
+ for ( ; ; ) ;
88
+ }
@@ -0,0 +1,23 @@
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 "timing.h"
15
+
16
+ int genKAT_main();
17
+
18
+ int main()
19
+ {
20
+ doTiming();
21
+ return genKAT_main();
22
+ }
23
+
@@ -0,0 +1,381 @@
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 <malloc.h>
15
+ #include <stdio.h>
16
+ #include <stdlib.h>
17
+ #include <string.h>
18
+ #include "displayIntermediateValues.h"
19
+ #include "KeccakDuplex.h"
20
+ #include "KeccakNISTInterface.h"
21
+ #include "KeccakSponge.h"
22
+ #include "KeccakF-1600-interface.h"
23
+ #include "KeccakF-1600-reference.h"
24
+
25
+ int genKAT_main();
26
+
27
+ void displayPermutationIntermediateValues()
28
+ {
29
+ unsigned char state[KeccakPermutationSizeInBytes];
30
+ #ifdef KeccakReference32BI
31
+ const char *fileName = "KeccakPermutationIntermediateValues32BI.txt";
32
+ #else
33
+ const char *fileName = "KeccakPermutationIntermediateValues.txt";
34
+ #endif
35
+ FILE *f;
36
+
37
+ f = fopen(fileName, "w");
38
+ if (f == NULL)
39
+ printf("Could not open %s\n", fileName);
40
+ else {
41
+ KeccakInitialize();
42
+ fprintf(f, "+++ The round constants +++\n");
43
+ fprintf(f, "\n");
44
+ displayRoundConstants(f);
45
+
46
+ fprintf(f, "+++ The rho offsets +++\n");
47
+ fprintf(f, "\n");
48
+ displayRhoOffsets(f);
49
+
50
+ displaySetIntermediateValueFile(f);
51
+ displaySetLevel(3);
52
+
53
+ fprintf(f, "+++ Example with the all-zero input +++\n");
54
+ fprintf(f, "\n");
55
+ memset(state, 0, KeccakPermutationSizeInBytes);
56
+ KeccakPermutation(state);
57
+
58
+ fprintf(f, "+++ Example taking the previous output as input +++\n");
59
+ fprintf(f, "\n");
60
+ KeccakPermutation(state);
61
+
62
+ fclose(f);
63
+ displaySetIntermediateValueFile(0);
64
+ }
65
+ }
66
+
67
+ void alignLastByteOnLSB(const unsigned char *in, unsigned char *out, unsigned int length)
68
+ {
69
+ unsigned int lengthInBytes;
70
+
71
+ lengthInBytes = (length+7)/8;
72
+ memcpy(out, in, lengthInBytes);
73
+ if ((length % 8) != 0)
74
+ out[lengthInBytes-1] = out[lengthInBytes-1] >> (8-(length%8));
75
+ }
76
+
77
+ void displaySpongeIntermediateValuesOne(const unsigned char *message, unsigned int messageLength, unsigned int rate, unsigned int capacity)
78
+ {
79
+ spongeState state;
80
+ unsigned char output[512];
81
+ unsigned char *messageInternal;
82
+
83
+ messageInternal = malloc((messageLength+7)/8);
84
+ alignLastByteOnLSB(message, messageInternal, messageLength);
85
+
86
+ displayBytes(1, "Input message (last byte aligned on MSB)", message, (messageLength+7)/8);
87
+ displayBits(2, "Input message (in bits)", message, messageLength, 1);
88
+ displayBits(2, "Input message (in bits, after the formal bit reordering)", messageInternal, messageLength, 0);
89
+ displayBytes(2, "Input message (last byte aligned on LSB)", messageInternal, (messageLength+7)/8);
90
+
91
+ InitSponge(&state, rate, capacity);
92
+ displayStateAsBytes(1, "Initial state", state.state);
93
+ Absorb(&state, messageInternal, messageLength);
94
+ Squeeze(&state, output, sizeof(output)*8);
95
+
96
+ free(messageInternal);
97
+ }
98
+
99
+ void displaySpongeIntermediateValuesFew(FILE *f, unsigned int rate, unsigned int capacity)
100
+ {
101
+ const unsigned char *message1 = "\x53\x58\x7B\xC8";
102
+ unsigned int message1Length = 29;
103
+ const unsigned char *message2 =
104
+ "\x83\xAF\x34\x27\x9C\xCB\x54\x30\xFE\xBE\xC0\x7A\x81\x95\x0D\x30"
105
+ "\xF4\xB6\x6F\x48\x48\x26\xAF\xEE\x74\x56\xF0\x07\x1A\x51\xE1\xBB"
106
+ "\xC5\x55\x70\xB5\xCC\x7E\xC6\xF9\x30\x9C\x17\xBF\x5B\xEF\xDD\x7C"
107
+ "\x6B\xA6\xE9\x68\xCF\x21\x8A\x2B\x34\xBD\x5C\xF9\x27\xAB\x84\x6E"
108
+ "\x38\xA4\x0B\xBD\x81\x75\x9E\x9E\x33\x38\x10\x16\xA7\x55\xF6\x99"
109
+ "\xDF\x35\xD6\x60\x00\x7B\x5E\xAD\xF2\x92\xFE\xEF\xB7\x35\x20\x7E"
110
+ "\xBF\x70\xB5\xBD\x17\x83\x4F\x7B\xFA\x0E\x16\xCB\x21\x9A\xD4\xAF"
111
+ "\x52\x4A\xB1\xEA\x37\x33\x4A\xA6\x64\x35\xE5\xD3\x97\xFC\x0A\x06"
112
+ "\x5C\x41\x1E\xBB\xCE\x32\xC2\x40\xB9\x04\x76\xD3\x07\xCE\x80\x2E"
113
+ "\xC8\x2C\x1C\x49\xBC\x1B\xEC\x48\xC0\x67\x5E\xC2\xA6\xC6\xF3\xED"
114
+ "\x3E\x5B\x74\x1D\x13\x43\x70\x95\x70\x7C\x56\x5E\x10\xD8\xA2\x0B"
115
+ "\x8C\x20\x46\x8F\xF9\x51\x4F\xCF\x31\xB4\x24\x9C\xD8\x2D\xCE\xE5"
116
+ "\x8C\x0A\x2A\xF5\x38\xB2\x91\xA8\x7E\x33\x90\xD7\x37\x19\x1A\x07"
117
+ "\x48\x4A\x5D\x3F\x3F\xB8\xC8\xF1\x5C\xE0\x56\xE5\xE5\xF8\xFE\xBE"
118
+ "\x5E\x1F\xB5\x9D\x67\x40\x98\x0A\xA0\x6C\xA8\xA0\xC2\x0F\x57\x12"
119
+ "\xB4\xCD\xE5\xD0\x32\xE9\x2A\xB8\x9F\x0A\xE1";
120
+ unsigned int message2Length = 2008;
121
+
122
+ fprintf(f, "+++ Example with a small message +++\n");
123
+ fprintf(f, "\n");
124
+ fprintf(f, "This is the message of length 29 from ShortMsgKAT.txt.\n");
125
+ fprintf(f, "\n");
126
+ displaySpongeIntermediateValuesOne(message1, message1Length, rate, capacity);
127
+
128
+ fprintf(f, "+++ Example with a larger message +++\n");
129
+ fprintf(f, "\n");
130
+ fprintf(f, "This is the message of length 2008 from ShortMsgKAT.txt.\n");
131
+ fprintf(f, "\n");
132
+ displaySpongeIntermediateValuesOne(message2, message2Length, rate, capacity);
133
+ }
134
+
135
+ void displaySpongeIntermediateValues()
136
+ {
137
+ const unsigned int capacities[5] = {448, 512, 576, 768, 1024};
138
+ char fileName[256];
139
+ FILE *f;
140
+ unsigned int i;
141
+
142
+ for(i=0; i<5; i++) {
143
+ unsigned int capacity = capacities[i];
144
+ unsigned int rate = 1600-capacity;
145
+ sprintf(fileName, "KeccakSpongeIntermediateValues_r%dc%d.txt", rate, capacity);
146
+ f = fopen(fileName, "w");
147
+ if (f == NULL)
148
+ printf("Could not open %s\n", fileName);
149
+ else {
150
+ displaySetIntermediateValueFile(f);
151
+ displaySetLevel(2);
152
+
153
+ displaySpongeIntermediateValuesFew(f, rate, capacity);
154
+
155
+ fclose(f);
156
+ displaySetIntermediateValueFile(0);
157
+ }
158
+ }
159
+ }
160
+
161
+ void displayDuplexIntermediateValuesOne(FILE *f, unsigned int rate, unsigned int capacity)
162
+ {
163
+ duplexState state;
164
+ unsigned char input[512];
165
+ unsigned int inBitLen;
166
+ unsigned char output[512];
167
+ unsigned int outBitLen;
168
+ unsigned int i, j;
169
+ const unsigned int M = 239*251;
170
+ unsigned int x = 33;
171
+
172
+ InitDuplex(&state, rate, capacity);
173
+ displayStateAsBytes(1, "Initial state", state.state);
174
+
175
+ for(i=0; i<=rate+120; i+=123) {
176
+ inBitLen = i;
177
+ if (inBitLen > (rate-2)) inBitLen = rate-2;
178
+ memset(input, 0, 512);
179
+ for(j=0; j<inBitLen; j++) {
180
+ x = (x*x) % M;
181
+ if ((x % 2) != 0)
182
+ input[j/8] |= 1 << (j%8);
183
+ }
184
+ {
185
+ char text[100];
186
+ sprintf(text, "Input (%d bits)", inBitLen);
187
+ displayBytes(1, text, input, (inBitLen+7)/8);
188
+ }
189
+ outBitLen = rate;
190
+ Duplexing(&state, input, inBitLen, output, outBitLen);
191
+ {
192
+ char text[100];
193
+ sprintf(text, "Output (%d bits)", outBitLen);
194
+ displayBytes(1, text, output, (outBitLen+7)/8);
195
+ }
196
+ }
197
+ }
198
+
199
+ void displayDuplexIntermediateValues()
200
+ {
201
+ char fileName[256];
202
+ FILE *f;
203
+ unsigned int rate;
204
+
205
+ for(rate=1026; rate<=1027; rate++) {
206
+ unsigned int capacity = 1600-rate;
207
+ sprintf(fileName, "KeccakDuplexIntermediateValues_r%dc%d.txt", rate, capacity);
208
+ f = fopen(fileName, "w");
209
+ if (f == NULL)
210
+ printf("Could not open %s\n", fileName);
211
+ else {
212
+ displaySetIntermediateValueFile(f);
213
+ displaySetLevel(2);
214
+
215
+ displayDuplexIntermediateValuesOne(f, rate, capacity);
216
+
217
+ fclose(f);
218
+ displaySetIntermediateValueFile(0);
219
+ }
220
+ }
221
+ }
222
+
223
+ #define refLenMax 128
224
+
225
+ void displayTest2040(unsigned int rate, unsigned int capacity)
226
+ {
227
+ const char testVectorMessage[] =
228
+ "\x3A\x3A\x81\x9C\x48\xEF\xDE\x2A\xD9\x14\xFB\xF0\x0E\x18\xAB\x6B"
229
+ "\xC4\xF1\x45\x13\xAB\x27\xD0\xC1\x78\xA1\x88\xB6\x14\x31\xE7\xF5"
230
+ "\x62\x3C\xB6\x6B\x23\x34\x67\x75\xD3\x86\xB5\x0E\x98\x2C\x49\x3A"
231
+ "\xDB\xBF\xC5\x4B\x9A\x3C\xD3\x83\x38\x23\x36\xA1\xA0\xB2\x15\x0A"
232
+ "\x15\x35\x8F\x33\x6D\x03\xAE\x18\xF6\x66\xC7\x57\x3D\x55\xC4\xFD"
233
+ "\x18\x1C\x29\xE6\xCC\xFD\xE6\x3E\xA3\x5F\x0A\xDF\x58\x85\xCF\xC0"
234
+ "\xA3\xD8\x4A\x2B\x2E\x4D\xD2\x44\x96\xDB\x78\x9E\x66\x31\x70\xCE"
235
+ "\xF7\x47\x98\xAA\x1B\xBC\xD4\x57\x4E\xA0\xBB\xA4\x04\x89\xD7\x64"
236
+ "\xB2\xF8\x3A\xAD\xC6\x6B\x14\x8B\x4A\x0C\xD9\x52\x46\xC1\x27\xD5"
237
+ "\x87\x1C\x4F\x11\x41\x86\x90\xA5\xDD\xF0\x12\x46\xA0\xC8\x0A\x43"
238
+ "\xC7\x00\x88\xB6\x18\x36\x39\xDC\xFD\xA4\x12\x5B\xD1\x13\xA8\xF4"
239
+ "\x9E\xE2\x3E\xD3\x06\xFA\xAC\x57\x6C\x3F\xB0\xC1\xE2\x56\x67\x1D"
240
+ "\x81\x7F\xC2\x53\x4A\x52\xF5\xB4\x39\xF7\x2E\x42\x4D\xE3\x76\xF4"
241
+ "\xC5\x65\xCC\xA8\x23\x07\xDD\x9E\xF7\x6D\xA5\xB7\xC4\xEB\x7E\x08"
242
+ "\x51\x72\xE3\x28\x80\x7C\x02\xD0\x11\xFF\xBF\x33\x78\x53\x78\xD7"
243
+ "\x9D\xC2\x66\xF6\xA5\xBE\x6B\xB0\xE4\xA9\x2E\xCE\xEB\xAE\xB1";
244
+ const int refLen = refLenMax;
245
+ unsigned char output[refLenMax];
246
+ unsigned int offset;
247
+ spongeState state;
248
+
249
+ InitSponge( &state, rate, capacity );
250
+ Absorb( &state, testVectorMessage, 2040 );
251
+ Squeeze( &state, output, refLen*8 );
252
+ printf("Message of size 2040 bits with Keccak[r=%d, c=%d]\n", rate, capacity);
253
+ for(offset=0; offset<refLen; offset++)
254
+ printf("\\x%02X", output[offset]);
255
+ printf("\n\n");
256
+ }
257
+
258
+ void displayTests2040()
259
+ {
260
+ displayTest2040(1152, 448);
261
+ displayTest2040(1088, 512);
262
+ displayTest2040(1024, 576);
263
+ displayTest2040( 832, 768);
264
+ displayTest2040( 576, 1024);
265
+ }
266
+
267
+ void displayAllInOneTestBitQueue(unsigned int rate, unsigned int capacity)
268
+ {
269
+ #define refLenMax 128
270
+ #define refLen refLenMax
271
+ unsigned char input[512];
272
+ unsigned char output[refLenMax];
273
+ unsigned char ref[refLen];
274
+ unsigned int inlen, offset, size;
275
+ int result;
276
+ spongeState state;
277
+
278
+ // Acumulated test vector for crypto_hash()
279
+ memset( ref, 0x00, sizeof(ref) );
280
+
281
+ for ( inlen = 0; inlen <= 4096;
282
+ (inlen < 2*8) ? inlen++ : ((inlen < 32*8) ? (inlen += 8) : (inlen <<= 1)) ) {
283
+ unsigned int i;
284
+ unsigned int bytesize = (unsigned int)((inlen + 7) / 8);
285
+
286
+ for ( i = 0; i < bytesize; ++i )
287
+ input[i] = (unsigned char)(i - bytesize);
288
+
289
+ result = InitSponge( &state, rate, capacity );
290
+
291
+ for ( offset = 0; offset < inlen; offset += size ) {
292
+ // vary sizes for Update()
293
+ if ( (inlen %8) < 2 )
294
+ // byte per byte
295
+ size = 8;
296
+ else if ( (inlen %8) < 4 )
297
+ // incremental
298
+ size = offset + 8;
299
+ else
300
+ // random
301
+ size = ((rand() % ((inlen + 8) / 8)) + 1) * 8;
302
+
303
+ if ( size > (inlen - offset) )
304
+ size = inlen - offset;
305
+
306
+ result = Absorb( &state, input + offset / 8, size );
307
+ }
308
+ result = Squeeze( &state, output, refLen*8 );
309
+
310
+ for ( i = 0; i < (unsigned int)refLen; ++i )
311
+ ref[i] ^= output[i];
312
+ }
313
+ printf("All-in-one test (using the bit queue) for Keccak[r=%d, c=%d]\n", rate, capacity);
314
+ for(offset=0; offset<refLen; offset++)
315
+ printf("\\x%02X", ref[offset]);
316
+ printf("\n\n");
317
+ #undef refLenMax
318
+ #undef refLen
319
+ }
320
+
321
+ void displayAllInOneTestsBitQueue()
322
+ {
323
+ displayAllInOneTestBitQueue(1152, 448);
324
+ displayAllInOneTestBitQueue(1088, 512);
325
+ displayAllInOneTestBitQueue(1024, 576);
326
+ displayAllInOneTestBitQueue( 832, 768);
327
+ displayAllInOneTestBitQueue( 576, 1024);
328
+ }
329
+
330
+ void displayAllInOneTestBytes(unsigned int rate, unsigned int capacity)
331
+ {
332
+ #define refLenMax 128
333
+ #define refLen refLenMax
334
+ unsigned char input[512];
335
+ unsigned char output[refLenMax];
336
+ unsigned char ref[refLen];
337
+ unsigned int inlen, offset, size;
338
+ int result;
339
+ spongeState state;
340
+
341
+ // Acumulated test vector for crypto_hash()
342
+ memset( ref, 0x00, sizeof(ref) );
343
+
344
+ for ( inlen = 0; inlen <= 4096; inlen += 8) {
345
+ unsigned int i;
346
+ unsigned int bytesize = (unsigned int)((inlen + 7) / 8);
347
+
348
+ for ( i = 0; i < bytesize; ++i )
349
+ input[i] = (unsigned char)(i - bytesize);
350
+
351
+ result = InitSponge( &state, rate, capacity );
352
+ result = Absorb( &state, input, inlen );
353
+ result = Squeeze( &state, output, refLen*8 );
354
+
355
+ for ( i = 0; i < (unsigned int)refLen; ++i )
356
+ ref[i] ^= output[i];
357
+ }
358
+ printf("All-in-one test (from 0 to 512 bytes) for Keccak[r=%d, c=%d]\n", rate, capacity);
359
+ for(offset=0; offset<refLen; offset++)
360
+ printf("\\x%02X", ref[offset]);
361
+ printf("\n\n");
362
+ #undef refLenMax
363
+ #undef refLen
364
+ }
365
+
366
+ void displayAllInOneTestsBytes()
367
+ {
368
+ displayAllInOneTestBytes(1152, 448);
369
+ displayAllInOneTestBytes(1088, 512);
370
+ displayAllInOneTestBytes(1024, 576);
371
+ displayAllInOneTestBytes( 832, 768);
372
+ displayAllInOneTestBytes( 576, 1024);
373
+ }
374
+
375
+ int main()
376
+ {
377
+ displayPermutationIntermediateValues();
378
+ displaySpongeIntermediateValues();
379
+ displayDuplexIntermediateValues();
380
+ return genKAT_main();
381
+ }