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,231 @@
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 "Keccak-inplace-settings.h"
15
+ #include "string.h"
16
+
17
+ #define MIN(a,b) (((a) < (b)) ? (a) : (b))
18
+
19
+ #define MAX_INPUT_LEN (4096/8)
20
+
21
+
22
+ typedef unsigned char UINT8;
23
+ typedef unsigned short UINT16;
24
+ typedef unsigned int UINT32;
25
+ typedef unsigned long long int UINT64;
26
+
27
+ int crypto_hash( unsigned char *out, const unsigned char *in, unsigned long long inlen );
28
+ void check_result( UINT8 * result, const UINT8 * reference, UINT32 nbBytes );
29
+
30
+ #if (cKeccakR == 1024)
31
+
32
+ // Some crypto_hash test vectors
33
+
34
+ const UINT8 outputSize0[128] = {
35
+ 0x67, 0x53, 0xE3, 0x38, 0x0C, 0x09, 0xE3, 0x85, 0xD0, 0x33, 0x9E, 0xB6, 0xB0, 0x50, 0xA6, 0x8F,
36
+ 0x66, 0xCF, 0xD6, 0x0A, 0x73, 0x47, 0x6E, 0x6F, 0xD6, 0xAD, 0xEB, 0x72, 0xF5, 0xED, 0xD7, 0xC6,
37
+ 0xF0, 0x4A, 0x5D, 0x01, 0x7A, 0x19, 0xCB, 0xE2, 0x91, 0x93, 0x58, 0x55, 0xB4, 0x86, 0x0F, 0x69,
38
+ 0xDF, 0x04, 0xC9, 0x8A, 0xA7, 0x8B, 0x40, 0x7A, 0x9B, 0xA9, 0x82, 0x6F, 0x72, 0x66, 0xEF, 0x14,
39
+ 0xBA, 0x6D, 0x3F, 0x90, 0xC4, 0xFE, 0x15, 0x4D, 0x27, 0xC2, 0x85, 0x8E, 0xA6, 0xDB, 0x8C, 0x11,
40
+ 0x74, 0x11, 0xA1, 0xBC, 0x5C, 0x49, 0x94, 0x10, 0xC3, 0x91, 0xB2, 0x98, 0xF3, 0x7B, 0xF6, 0x36,
41
+ 0xB0, 0xF5, 0xC3, 0x1D, 0xBD, 0x64, 0x87, 0xA7, 0xD3, 0xD8, 0xCF, 0x2A, 0x97, 0xB6, 0x19, 0x69,
42
+ 0x7E, 0x66, 0xD8, 0x94, 0x29, 0x9B, 0x8B, 0x4D, 0x80, 0xE0, 0x49, 0x85, 0x38, 0xE1, 0x85, 0x44
43
+ };
44
+
45
+ const UINT8 inputSize1[1] = { 0xCC };
46
+
47
+ const UINT8 outputSize1[128] = {
48
+ 0x56, 0xB9, 0x70, 0x29, 0xB4, 0x79, 0xFF, 0x5D, 0xD1, 0x5F, 0x17, 0xD1, 0x29, 0x83, 0xE3, 0xB8,
49
+ 0x35, 0xBB, 0x05, 0x31, 0xD9, 0xB8, 0xD4, 0x9B, 0x10, 0x3B, 0x02, 0x5C, 0xA5, 0x3F, 0x99, 0x17,
50
+ 0x41, 0x29, 0x8E, 0x96, 0x1D, 0x1F, 0xAD, 0x00, 0xFC, 0x36, 0x5C, 0x77, 0x61, 0xBF, 0xB2, 0x78,
51
+ 0xAE, 0x47, 0x39, 0x80, 0xD6, 0x12, 0xC1, 0x62, 0x9E, 0x07, 0x5A, 0x3F, 0xDB, 0xAE, 0x7F, 0x82,
52
+ 0xB0, 0xF0, 0xAF, 0x54, 0xDF, 0x18, 0x7F, 0x35, 0x88, 0x52, 0xE1, 0x9E, 0xA4, 0x34, 0x7C, 0xF5,
53
+ 0xCE, 0xEA, 0x67, 0x6A, 0x1D, 0xCE, 0x3A, 0x47, 0x44, 0x7E, 0x23, 0x7F, 0xD7, 0x42, 0x04, 0xF9,
54
+ 0xA4, 0xB7, 0xF7, 0xC9, 0xCC, 0x7C, 0xC8, 0xB8, 0x65, 0xB1, 0xD5, 0x54, 0xE2, 0xF5, 0xF4, 0xA8,
55
+ 0xEE, 0x17, 0xDB, 0xDD, 0xE7, 0x26, 0x78, 0x94, 0x55, 0x8A, 0x20, 0x97, 0x2C, 0x9E, 0xB6, 0xCF
56
+ };
57
+
58
+
59
+ const UINT8 inputSize128[] = {
60
+ 0x2B, 0x6D, 0xB7, 0xCE, 0xD8, 0x66, 0x5E, 0xBE, 0x9D, 0xEB, 0x08, 0x02, 0x95, 0x21, 0x84, 0x26,
61
+ 0xBD, 0xAA, 0x7C, 0x6D, 0xA9, 0xAD, 0xD2, 0x08, 0x89, 0x32, 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 0xD4, 0xA2, 0x35, 0x93, 0x00, 0xDB, 0x89, 0x2B, 0x80, 0x93, 0xDF, 0xFA, 0x94, 0x42, 0xBB,
103
+ 0x5C, 0x08, 0xF2, 0x42, 0xF2, 0xFC, 0x2C, 0xB5, 0xF8, 0x38, 0x80, 0x32, 0x29, 0x9F, 0x1D, 0xF4,
104
+ 0x7A, 0x57, 0x48, 0x9A, 0x4F, 0xC0, 0xD6, 0x6D, 0x88, 0xE4, 0x83, 0x09, 0x23, 0x20, 0xA4, 0x71,
105
+ 0x89, 0x7F, 0xB6, 0xAD, 0xE6, 0x78, 0x97, 0xE5, 0x13, 0x8C, 0x45, 0xF1, 0x91, 0x74, 0xA4, 0xB1,
106
+ 0xAE, 0x0E, 0x51, 0x0F, 0xA3, 0x90, 0x82, 0x5D, 0x17, 0x56, 0x89, 0x89, 0xC3, 0x65, 0x9F, 0xC5,
107
+ 0x7B, 0x93, 0x45, 0xD7, 0xD9, 0x3E, 0xE5, 0x88, 0xCB, 0x26, 0x29, 0xC5, 0x77, 0x08, 0x08, 0x19,
108
+ 0x52, 0x57, 0xBB, 0xF4, 0x2B, 0x06, 0x95, 0x76, 0xD9, 0x40, 0x11, 0x98, 0x9D, 0xC6, 0xEB, 0xC4
109
+ };
110
+
111
+ #endif
112
+
113
+ #if (cKeccakR == 1152)
114
+
115
+ //All-in-one test for Keccak[r=1152, c=448]
116
+ const UINT8 testVectorAccumulated[128] =
117
+ "\x02\x57\x78\x6E\xA6\xA0\x75\xC2\xD1\x16\x7E\x19\x8B\xD6\x60\x3D\xC9\x2D\x31\xD9\xF2\x24\x94\x3E\x10\xBE\x2D\x77\x2F\xFC\xB6\xCE\xAE\x69\xB0\x30\xA0\xC2\xE2\x40\xB4\xAA\x7E\x42\x64\x8D\x88\x1E\x98\x0B\xC5\x2D\x9B\x64\x9B\x03\x10\x08\xF8\x0C\x71\x11\x69\x2B\xB9\x2A\xB8\x6E\x14\x93\xAC\xFE\xEB\xF8\x73\x9B\x59\x65\x47\xE5\xDC\xE0\x29\x21\xD7\xF4\x84\x93\xC9\xBD\xB8\x97\x98\xD5\x69\x15\x38\x1A\x8F\x86\xB2\xAD\xC7\xD2\x63\x43\x69\xDD\x9E\x8A\x27\x58\xEE\xF9\x7B\xA1\x6D\xCC\xFE\x98\x2A\x64\xC5\x1D\x83\xDF\x68\x55";
118
+
119
+ #elif (cKeccakR == 1088)
120
+
121
+ //All-in-one test for Keccak[r=1088, c=512]
122
+ const UINT8 testVectorAccumulated[128] =
123
+ "\xD2\x53\x12\x20\x01\x89\x0C\x19\xCE\x06\x9D\x1A\xBE\x36\x7E\xBA\x43\x80\x14\xA1\xCA\xA4\xB3\x99\xAD\xBB\x9B\x1A\xD3\xDE\xA8\xE6\xE3\x44\xDC\xBA\x44\xB1\x5C\x52\x47\x32\xE0\x0F\xDF\x55\x15\x7B\xD3\x49\x0B\xD2\x58\x7D\xC0\x1E\x93\x1E\x8F\xFF\x28\xDC\x7F\x00\xE6\xDF\xD3\xBB\xDC\x94\x05\x5A\xA1\x5B\xB3\x29\x86\x25\x26\x3D\xC6\xB1\xEF\x3B\x89\x18\x20\x71\x92\xFA\xA7\x58\xA4\x8A\xF9\xFF\x19\x61\x96\xC4\x73\x91\x85\xF3\x19\x73\xE3\x52\x6D\xBD\x0A\xD9\xF8\x95\x68\x43\x31\x50\x90\xD7\x68\x5F\x75\xA1\x61\x1E\x08\x2D";
124
+
125
+ #elif (cKeccakR == 1024)
126
+
127
+ //All-in-one test for Keccak[r=1024, c=576]
128
+ const UINT8 testVectorAccumulated[128] =
129
+ "\x74\x00\x1E\xA7\xD2\xBE\x68\x0D\x36\x0C\x80\x0D\x6D\xDB\x4D\x07\x01\x10\xE5\x19\x99\x8C\x0C\x1C\x63\xCD\x5C\xC0\x2D\xC3\x12\x4C\x9C\xD1\xC1\x5A\x8E\xC9\x06\xA8\x1E\xE6\x02\x77\x14\x40\x38\xD5\x09\x89\xE2\x2D\xF2\x66\x37\x4A\x48\xBC\xB9\xE2\x7D\x53\x86\xAC\x1F\x3D\x4C\xEF\x4E\x90\x97\xFB\x9C\x45\x40\xED\xAB\x16\x29\x05\x87\x17\x26\xE8\xBD\xFA\x82\x72\x5F\x77\xFF\xFA\x26\xE6\x50\x0B\x1D\x40\x25\x62\xC7\xEE\xCA\xAA\x38\x78\x52\xE6\x15\x7B\xC7\x3E\x16\xB2\xFE\x05\xB8\x8D\x68\x0C\x18\xC1\x48\x0B\x50\x97\xD9\xC7";
130
+
131
+ #elif (cKeccakR == 832)
132
+
133
+ //All-in-one test for Keccak[r=832, c=768]
134
+ const UINT8 testVectorAccumulated[128] =
135
+ "\x6C\x07\xDB\x71\x61\x77\xCC\x99\xFF\xB4\x79\xA1\x54\xDC\xA7\xDA\x42\x6D\x5C\x04\x26\xBF\x01\xA2\x93\x9A\x35\xB1\xCC\x2E\x6C\x5D\xBA\x5E\x43\xAD\xD1\x7C\xA8\x45\xF5\x49\xA7\x02\xA3\x84\x4B\x7A\x15\x2B\x23\x9E\x41\xA7\x4C\x83\x09\x04\xF1\xBB\x40\x17\x7A\x67\x72\x3C\xF4\x28\x4B\xAB\x94\xC2\x02\xF4\x7B\x28\xB4\x5D\x57\xCA\x7E\x3F\x27\x0D\x2C\x09\x4F\x68\x54\xA3\xE6\x38\xF3\x82\x25\x0B\xC3\x16\x52\x2B\x8A\xDE\x93\x4F\x10\xC5\x21\x57\x4B\x21\xE7\xC6\xF6\xBB\x84\xF1\x7A\x78\x8E\xD3\x9E\xE2\xC7\x2F\xE3\x0F\xBB\x60";
136
+
137
+ #elif (cKeccakR == 576)
138
+
139
+ //All-in-one test for Keccak[r=576, c=1024]
140
+ const UINT8 testVectorAccumulated[128] =
141
+ "\xFB\x00\xFB\x55\x4B\xDA\x9D\x59\xD7\xD4\x42\x9A\xAB\xA5\x19\xA4\x14\x8D\x48\x67\xF6\xF0\xC8\x54\x1A\x48\xA4\x33\x4E\x68\xB7\xF0\x59\x13\x07\xED\xE3\x93\xE1\xA3\xA4\x79\x9E\x94\xDE\x9C\x32\x8A\xBB\x4F\xF2\x75\x47\xB0\x5E\x41\x7D\x78\xF6\x22\x0D\x83\x22\xC6\xB0\x7D\xBD\x2F\xB8\x5F\x4D\x99\x50\x86\xA5\x9B\x03\x51\x56\x35\x94\xB6\xFE\x72\x2B\x63\x7B\x4A\xDC\xDD\xA1\x83\xCF\xB7\xE7\xB2\x9D\x3A\x0D\x29\xBD\x30\xD4\xC5\x9F\x30\xBB\x60\x5A\x52\xC3\x83\x4B\xCA\xF4\x7D\x67\x37\x99\xBA\x28\x2E\xBC\x37\x76\xB3\x53\x56";
142
+
143
+ #endif
144
+
145
+ typedef struct
146
+ {
147
+ UINT8 input[17 * 8];
148
+ UINT32 stateTest[50];
149
+ } tSimple;
150
+
151
+ typedef struct
152
+ {
153
+ UINT8 input[MAX_INPUT_LEN];
154
+ UINT8 output[cKeccakR/8];
155
+ UINT8 accu[MIN(cKeccakR/8, 128)];
156
+ } tAccumlated;
157
+
158
+ union
159
+ {
160
+ tAccumlated a;
161
+ tSimple s;
162
+ } u;
163
+
164
+
165
+ int main()
166
+ {
167
+ int size;
168
+ int i;
169
+ UINT32 * pStack;
170
+
171
+ #if (cKeccakR == 1024)
172
+
173
+ // test size 0
174
+ crypto_hash( (UINT8*)u.s.stateTest, 0, 0 );
175
+ check_result( (UINT8*)u.s.stateTest, outputSize0, 128 );
176
+
177
+ // test size 1 byte
178
+ crypto_hash( (UINT8*)u.s.stateTest, inputSize1, 1 );
179
+ check_result( (UINT8*)u.s.stateTest, outputSize1, 128 );
180
+
181
+ // test size 128 bytes
182
+ crypto_hash( (UINT8*)u.s.stateTest, inputSize128, 128 );
183
+ check_result( (UINT8*)u.s.stateTest, outputSize128, 128 );
184
+
185
+ // test size 255 bytes
186
+ crypto_hash( (UINT8*)u.s.stateTest, inputSize255, 255 );
187
+ check_result( (UINT8*)u.s.stateTest, outputSize255, 128 );
188
+
189
+ #endif
190
+
191
+ // Acumulated test vector for crypto_hash()
192
+ memset( u.a.accu, 0x00, sizeof(u.a.accu) );
193
+
194
+ for ( size = 0; size <= sizeof(u.a.input); ++size )
195
+ {
196
+
197
+ for ( i = 0; i < size; ++i )
198
+ {
199
+ u.a.input[i] = (UINT8)(i - size);
200
+ }
201
+
202
+ crypto_hash( u.a.output, u.a.input, size );
203
+
204
+ for ( i = 0; i < MIN(cKeccakR/8, 128); ++i )
205
+ {
206
+ u.a.accu[i] ^= u.a.output[i];
207
+ }
208
+ }
209
+ check_result( u.a.accu, testVectorAccumulated, MIN(cKeccakR/8, 128) );
210
+
211
+ return 0;
212
+ for ( ; ; ) ; // Everything ok
213
+ }
214
+
215
+ void check_result( UINT8 * result, const UINT8 * reference, UINT32 nBytes )
216
+ {
217
+ static UINT64 x = 0;
218
+ int i;
219
+
220
+ for( i = 0; i < nBytes; ++i )
221
+ {
222
+ if ( result[i] != reference[i] )
223
+ {
224
+ for( ; ; )
225
+ {
226
+ // Kaccek (aka other algo)
227
+ x++;
228
+ }
229
+ }
230
+ }
231
+ }
@@ -0,0 +1,3 @@
1
+ #define cKeccakB 1600
2
+ #define cKeccakR 1024
3
+ //#define cKeccakFixedOutputLengthInBytes 64
@@ -0,0 +1,221 @@
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 "Keccak-inplace-settings.h"
15
+ #define cKeccakR_SizeInBytes (cKeccakR / 8)
16
+ #include <string.h>
17
+ #include <stdio.h>
18
+ #include <ctype.h>
19
+
20
+ #if defined(__GNUC__)
21
+ #define ALIGN __attribute__ ((aligned(32)))
22
+ #elif defined(_MSC_VER)
23
+ #define ALIGN __declspec(align(32))
24
+ #else
25
+ #define ALIGN
26
+ #endif
27
+
28
+ #if (cKeccakB == 1600) && (cKeccakR == 1024)
29
+ const char * testVectorFile = "ShortMsgKAT_0.txt";
30
+ #elif (cKeccakB == 1600) && (cKeccakR == 1152) && (cKeccakFixedOutputLengthInBytes == 28)
31
+ const char * testVectorFile = "ShortMsgKAT_224.txt";
32
+ #elif (cKeccakB == 1600) && (cKeccakR == 1088) && (cKeccakFixedOutputLengthInBytes == 32)
33
+ const char * testVectorFile = "ShortMsgKAT_256.txt";
34
+ #elif (cKeccakB == 1600) && (cKeccakR == 832) && (cKeccakFixedOutputLengthInBytes == 48)
35
+ const char * testVectorFile = "ShortMsgKAT_384.txt";
36
+ #elif (cKeccakB == 1600) && (cKeccakR == 576) && (cKeccakFixedOutputLengthInBytes == 64)
37
+ const char * testVectorFile = "ShortMsgKAT_512.txt";
38
+ #elif (cKeccakB == 1600) && (cKeccakR == 1344)
39
+ const char * testVectorFile = "ShortMsgKAT_r1344c256.txt";
40
+ #elif (cKeccakB == 800) && (cKeccakR == 544)
41
+ const char * testVectorFile = "ShortMsgKAT_r544c256.txt";
42
+ #elif (cKeccakB == 800) && (cKeccakR == 512)
43
+ const char * testVectorFile = "ShortMsgKAT_r512c288.txt";
44
+ #elif (cKeccakB == 800) && (cKeccakR == 256)
45
+ const char * testVectorFile = "ShortMsgKAT_r256c544.txt";
46
+ #elif (cKeccakB == 400) && (cKeccakR == 144)
47
+ const char * testVectorFile = "ShortMsgKAT_r144c256.txt";
48
+ #elif (cKeccakB == 400) && (cKeccakR == 128)
49
+ const char * testVectorFile = "ShortMsgKAT_r128c272.txt";
50
+ #elif (cKeccakB == 200) && (cKeccakR == 40)
51
+ const char * testVectorFile = "ShortMsgKAT_r40c160.txt";
52
+ #else
53
+ #error "Please set the vector file name here."
54
+ #endif
55
+
56
+ #define cKeccakMaxMessageSizeInBytes (2047/8)
57
+
58
+ ALIGN unsigned char input[cKeccakMaxMessageSizeInBytes];
59
+ ALIGN unsigned char output[cKeccakR_SizeInBytes];
60
+
61
+ //
62
+ // ALLOW TO READ HEXADECIMAL ENTRY (KEYS, DATA, TEXT, etc.)
63
+ //
64
+ #define MAX_MARKER_LEN 50
65
+
66
+ typedef unsigned char BitSequence;
67
+
68
+ int FindMarker(FILE *infile, const char *marker);
69
+ int FindMarker(FILE *infile, const char *marker)
70
+ {
71
+ char line[MAX_MARKER_LEN];
72
+ int i, len;
73
+
74
+ len = (int)strlen(marker);
75
+ if ( len > MAX_MARKER_LEN-1 )
76
+ len = MAX_MARKER_LEN-1;
77
+
78
+ for ( i=0; i<len; i++ )
79
+ if ( (line[i] = fgetc(infile)) == EOF )
80
+ return 0;
81
+ line[len] = '\0';
82
+
83
+ while ( 1 ) {
84
+ if ( !strncmp(line, marker, len) )
85
+ return 1;
86
+
87
+ for ( i=0; i<len-1; i++ )
88
+ line[i] = line[i+1];
89
+ if ( (line[len-1] = fgetc(infile)) == EOF )
90
+ return 0;
91
+ line[len] = '\0';
92
+ }
93
+
94
+ // shouldn't get here
95
+ return 0;
96
+ }
97
+
98
+ //
99
+ // ALLOW TO READ HEXADECIMAL ENTRY (KEYS, DATA, TEXT, etc.)
100
+ //
101
+ int ReadHex(FILE *infile, BitSequence *A, int Length, char *str);
102
+ int ReadHex(FILE *infile, BitSequence *A, int Length, char *str)
103
+ {
104
+ int i, ch, started;
105
+ BitSequence ich;
106
+
107
+ if ( Length == 0 ) {
108
+ A[0] = 0x00;
109
+ return 1;
110
+ }
111
+ memset(A, 0x00, Length);
112
+ started = 0;
113
+ i = 0;
114
+ if ( FindMarker(infile, str) )
115
+ while ( (ch = fgetc(infile)) != EOF )
116
+ {
117
+ if ( !isxdigit(ch) ) {
118
+ if ( !started ) {
119
+ if ( ch == '\n' )
120
+ break;
121
+ else
122
+ continue;
123
+ }
124
+ else
125
+ break;
126
+ }
127
+ started = 1;
128
+ if ( (ch >= '0') && (ch <= '9') )
129
+ ich = ch - '0';
130
+ else if ( (ch >= 'A') && (ch <= 'F') )
131
+ ich = ch - 'A' + 10;
132
+ else if ( (ch >= 'a') && (ch <= 'f') )
133
+ ich = ch - 'a' + 10;
134
+
135
+ A[i / 2] = (A[i / 2] << 4) | ich;
136
+ if ( (++i / 2) == Length )
137
+ break;
138
+ }
139
+ else
140
+ return 0;
141
+
142
+ return 1;
143
+ }
144
+
145
+ int main( void )
146
+ {
147
+ unsigned long long inlen;
148
+ int result = 0;
149
+ FILE *fp_in;
150
+ char marker[20];
151
+ int refLen;
152
+
153
+ #ifdef cKeccakFixedOutputLengthInBytes
154
+ refLen = cKeccakFixedOutputLengthInBytes;
155
+ #else
156
+ refLen = cKeccakR_SizeInBytes;
157
+ #endif
158
+
159
+ printf( "Testing Keccak[r=%u, c=%u] against %s over %d squeezed bytes\n", cKeccakR, cKeccakB - cKeccakR, testVectorFile, refLen );
160
+ if ( (fp_in = fopen(testVectorFile, "r")) == NULL )
161
+ {
162
+ printf("Couldn't open <%s> for read\n", testVectorFile);
163
+ return 1;
164
+ }
165
+
166
+ for ( inlen = 0; inlen <= cKeccakMaxMessageSizeInBytes; ++inlen )
167
+ {
168
+ sprintf( marker, "Len = %u", inlen * 8 );
169
+ if ( !FindMarker(fp_in, marker) )
170
+ {
171
+ printf("ERROR: no test vector found (%u bytes)\n", inlen );
172
+ result = 1;
173
+ break;
174
+ }
175
+ if ( !ReadHex(fp_in, input, (int)inlen, "Msg = ") )
176
+ {
177
+ printf("ERROR: unable to read 'Msg' (%u bytes)\n", inlen );
178
+ result = 1;
179
+ break;
180
+ }
181
+
182
+ result = crypto_hash( output, input, inlen );
183
+ if ( result != 0 )
184
+ {
185
+ printf("ERROR: crypto_hash() (%u bytes)\n", inlen);
186
+ result = 1;
187
+ break;
188
+ }
189
+
190
+ #ifdef cKeccakFixedOutputLengthInBytes
191
+ if ( !ReadHex(fp_in, input, refLen, "MD = ") )
192
+ #else
193
+ if ( !ReadHex(fp_in, input, refLen, "Squeezed = ") )
194
+ #endif
195
+ {
196
+ printf("ERROR: unable to read 'Squeezed/MD' (%u bytes)\n", inlen );
197
+ result = 1;
198
+ break;
199
+ }
200
+ if ( memcmp( output, input, refLen ) != 0)
201
+ {
202
+ printf("ERROR: hash verification (%u bytes)\n", inlen );
203
+ for(result=0; result<refLen; result++)
204
+ printf("%02X ", output[result]);
205
+ printf("\n");
206
+ result = 1;
207
+ break;
208
+ }
209
+ }
210
+
211
+ fclose( fp_in );
212
+ if ( !result )
213
+ printf( "\nSuccess!\n");
214
+
215
+ //printf( "\nPress a key ...");
216
+ //getchar();
217
+ //printf( "\n");
218
+ return ( result );
219
+ }
220
+
221
+