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,225 @@
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
+
16
+ /************** Timing routine (for performance measurements) ***********/
17
+ /* By Doug Whiting */
18
+ /* unfortunately, this is generally assembly code and not very portable */
19
+ #if defined(_M_IX86) || defined(__i386) || defined(_i386) || defined(__i386__) || defined(i386) || \
20
+ defined(_X86_) || defined(__x86_64__) || defined(_M_X64) || defined(__x86_64)
21
+ #define _Is_X86_ 1
22
+ #endif
23
+
24
+ #if defined(_Is_X86_) && (!defined(__STRICT_ANSI__)) && (defined(__GNUC__) || !defined(__STDC__)) && \
25
+ (defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW_H) || defined(__GNUC__))
26
+ #define HI_RES_CLK_OK 1 /* it's ok to use RDTSC opcode */
27
+
28
+ #if defined(_MSC_VER) // && defined(_M_X64)
29
+ #include <intrin.h>
30
+ #pragma intrinsic(__rdtsc) /* use MSVC rdtsc call where defined */
31
+ #endif
32
+
33
+ #endif
34
+
35
+ typedef unsigned int uint_32t;
36
+
37
+ uint_32t HiResTime(void) /* return the current value of time stamp counter */
38
+ {
39
+ #if defined(HI_RES_CLK_OK)
40
+ uint_32t x[2];
41
+ #if defined(__BORLANDC__)
42
+ #define COMPILER_ID "BCC"
43
+ __emit__(0x0F,0x31); /* RDTSC instruction */
44
+ _asm { mov x[0],eax };
45
+ #elif defined(_MSC_VER)
46
+ #define COMPILER_ID "MSC"
47
+ #if defined(_MSC_VER) // && defined(_M_X64)
48
+ x[0] = (uint_32t) __rdtsc();
49
+ #else
50
+ _asm { _emit 0fh }; _asm { _emit 031h };
51
+ _asm { mov x[0],eax };
52
+ #endif
53
+ #elif defined(__MINGW_H) || defined(__GNUC__)
54
+ #define COMPILER_ID "GCC"
55
+ asm volatile("rdtsc" : "=a"(x[0]), "=d"(x[1]));
56
+ #else
57
+ #error "HI_RES_CLK_OK -- but no assembler code for this platform (?)"
58
+ #endif
59
+ return x[0];
60
+ #else
61
+ /* avoid annoying MSVC 9.0 compiler warning #4720 in ANSI mode! */
62
+ #if (!defined(_MSC_VER)) || (!defined(__STDC__)) || (_MSC_VER < 1300)
63
+ FatalError("No support for RDTSC on this CPU platform\n");
64
+ #endif
65
+ return 0;
66
+ #endif /* defined(HI_RES_CLK_OK) */
67
+ }
68
+
69
+ #define TIMER_SAMPLE_CNT (10)
70
+
71
+ uint_32t calibrate()
72
+ {
73
+ uint_32t dtMin = 0xFFFFFFFF; /* big number to start */
74
+ uint_32t t0,t1,i;
75
+
76
+ for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
77
+ {
78
+ t0 = HiResTime();
79
+ t1 = HiResTime();
80
+ if (dtMin > t1-t0) /* keep only the minimum time */
81
+ dtMin = t1-t0;
82
+ }
83
+ return dtMin;
84
+ }
85
+
86
+ #include "DoublePermutation.h"
87
+
88
+ uint_32t measureDoubleKeccakAbsorb1344bits(uint_32t dtMin)
89
+ {
90
+ uint_32t tMin = 0xFFFFFFFF; /* big number to start */
91
+ uint_32t t0,t1,i;
92
+ ALIGN unsigned char state[KeccakPermutationSizeInBytes*2];
93
+ ALIGN unsigned char input[168*2];
94
+
95
+ for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
96
+ {
97
+ t0 = HiResTime();
98
+ KeccakDoublePermutationOnWordsAfterXoring2x1344bits((V128*)state, (V128*)input);
99
+ t1 = HiResTime();
100
+ if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
101
+ tMin = t1-t0 - dtMin;
102
+ }
103
+
104
+ /* now tMin = # clocks required for running RoutineToBeTimed() */
105
+
106
+ return tMin;
107
+ }
108
+
109
+ uint_32t measureDoubleKeccakAbsorb1088bits(uint_32t dtMin)
110
+ {
111
+ uint_32t tMin = 0xFFFFFFFF; /* big number to start */
112
+ uint_32t t0,t1,i;
113
+ ALIGN unsigned char state[KeccakPermutationSizeInBytes*2];
114
+ ALIGN unsigned char input[136*2];
115
+
116
+ for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
117
+ {
118
+ t0 = HiResTime();
119
+ KeccakDoublePermutationOnWordsAfterXoring2x1088bits((V128*)state, (V128*)input);
120
+ t1 = HiResTime();
121
+ if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
122
+ tMin = t1-t0 - dtMin;
123
+ }
124
+
125
+ /* now tMin = # clocks required for running RoutineToBeTimed() */
126
+
127
+ return tMin;
128
+ }
129
+
130
+ uint_32t measureDoubleKeccakAbsorb1024bits(uint_32t dtMin)
131
+ {
132
+ uint_32t tMin = 0xFFFFFFFF; /* big number to start */
133
+ uint_32t t0,t1,i;
134
+ ALIGN unsigned char state[KeccakPermutationSizeInBytes*2];
135
+ ALIGN unsigned char input[128*2];
136
+
137
+ for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
138
+ {
139
+ t0 = HiResTime();
140
+ KeccakDoublePermutationOnWordsAfterXoring2x1024bits((V128*)state, (V128*)input);
141
+ t1 = HiResTime();
142
+ if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
143
+ tMin = t1-t0 - dtMin;
144
+ }
145
+
146
+ /* now tMin = # clocks required for running RoutineToBeTimed() */
147
+
148
+ return tMin;
149
+ }
150
+
151
+ uint_32t measureDoubleKeccakAbsorb512bits(uint_32t dtMin)
152
+ {
153
+ uint_32t tMin = 0xFFFFFFFF; /* big number to start */
154
+ uint_32t t0,t1,i;
155
+ ALIGN unsigned char state[KeccakPermutationSizeInBytes*2];
156
+ ALIGN unsigned char input[64*2];
157
+
158
+ for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
159
+ {
160
+ t0 = HiResTime();
161
+ KeccakDoublePermutationOnWordsAfterXoring2x512bits((V128*)state, (V128*)input);
162
+ t1 = HiResTime();
163
+ if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
164
+ tMin = t1-t0 - dtMin;
165
+ }
166
+
167
+ /* now tMin = # clocks required for running RoutineToBeTimed() */
168
+
169
+ return tMin;
170
+ }
171
+
172
+ uint_32t measureDoubleKeccakPermutation(uint_32t dtMin)
173
+ {
174
+ uint_32t tMin = 0xFFFFFFFF; /* big number to start */
175
+ uint_32t t0,t1,i;
176
+ ALIGN unsigned char state[KeccakPermutationSizeInBytes*2];
177
+
178
+ for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
179
+ {
180
+ t0 = HiResTime();
181
+ KeccakDoublePermutationOnWords((V128*)state);
182
+ t1 = HiResTime();
183
+ if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
184
+ tMin = t1-t0 - dtMin;
185
+ }
186
+
187
+ /* now tMin = # clocks required for running RoutineToBeTimed() */
188
+
189
+ return tMin;
190
+ }
191
+
192
+
193
+
194
+ void doTiming()
195
+ {
196
+ uint_32t calibration;
197
+ uint_32t measurementDoubleKeccakPermutation;
198
+ uint_32t measurementDoubleKeccakAbsorb1344bits;
199
+ uint_32t measurementDoubleKeccakAbsorb1088bits;
200
+ uint_32t measurementDoubleKeccakAbsorb1024bits;
201
+
202
+ calibration = calibrate();
203
+
204
+ measurementDoubleKeccakPermutation = measureDoubleKeccakPermutation(calibration);
205
+ printf("Cycles for DoubleKeccakPermutation(state): %d\n", measurementDoubleKeccakPermutation);
206
+ printf("Cycles per byte for rate 1024: %f\n", measurementDoubleKeccakPermutation/128.0/2.0);
207
+ printf("Cycles per byte for rate 1088: %f\n", measurementDoubleKeccakPermutation/136.0/2.0);
208
+ printf("Cycles per byte for rate 1344: %f\n", measurementDoubleKeccakPermutation/168.0/2.0);
209
+ printf("\n");
210
+
211
+ measurementDoubleKeccakAbsorb1344bits = measureDoubleKeccakAbsorb1344bits(calibration);
212
+ printf("Cycles for DoubleKeccakAbsorb1344bits(state, input): %d\n", measurementDoubleKeccakAbsorb1344bits);
213
+ printf("Cycles per byte for rate 1344: %f\n", measurementDoubleKeccakAbsorb1344bits/168.0/2.0);
214
+ printf("\n");
215
+
216
+ measurementDoubleKeccakAbsorb1088bits = measureDoubleKeccakAbsorb1088bits(calibration);
217
+ printf("Cycles for DoubleKeccakAbsorb1088bits(state, input): %d\n", measurementDoubleKeccakAbsorb1088bits);
218
+ printf("Cycles per byte for rate 1088: %f\n", measurementDoubleKeccakAbsorb1088bits/136.0/2.0);
219
+ printf("\n");
220
+
221
+ measurementDoubleKeccakAbsorb1024bits = measureDoubleKeccakAbsorb1024bits(calibration);
222
+ printf("Cycles for DoubleKeccakAbsorb1024bits(state, input): %d\n", measurementDoubleKeccakAbsorb1024bits);
223
+ printf("Cycles per byte for rate 1024: %f\n", measurementDoubleKeccakAbsorb1024bits/128.0/2.0);
224
+ printf("\n");
225
+ }
@@ -0,0 +1,20 @@
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 _timing_h_
15
+ #define _timing_h_
16
+
17
+ void doTiming();
18
+
19
+ #endif
20
+
@@ -0,0 +1,68 @@
1
+ all: Keccakc256TreeD2 Keccakc512TreeD2
2
+
3
+ SOURCES_D2 = \
4
+ Sources/mainOptimized.c \
5
+ Sources/timing-Double.c \
6
+ Sources/DoublePermutation.c
7
+
8
+ HEADERS_D2 = \
9
+ Sources/timing-Double.h \
10
+ Sources/KeccakF-1600-unrolling.macros \
11
+ Sources/DoublePermutation.h
12
+
13
+ SOURCES_c256D2 = $(SOURCES_D2) \
14
+ Sources/Keccakc256TreeD2.c
15
+
16
+ SOURCES_c512D2 = $(SOURCES_D2) \
17
+ Sources/Keccakc512TreeD2.c
18
+
19
+ HEADERS_c256D2 = $(HEADERS_D2) \
20
+ Sources/Keccakc256TreeD2.h
21
+
22
+ HEADERS_c512D2 = $(HEADERS_D2) \
23
+ Sources/Keccakc512TreeD2.h
24
+
25
+ BINDIR_c256D2 = bin/c256D2
26
+
27
+ $(BINDIR_c256D2):
28
+ mkdir -p $(BINDIR_c256D2)
29
+
30
+ OBJECTS_c256D2 = $(addprefix $(BINDIR_c256D2)/, $(notdir $(patsubst %.c,%.o,$(SOURCES_c256D2))))
31
+
32
+ CFLAGS_c256D2 = -Dc256 -DD2 -fomit-frame-pointer -O3 -g0 -march=native -mtune=native
33
+
34
+ BINDIR_c512D2 = bin/c512D2
35
+
36
+ $(BINDIR_c512D2):
37
+ mkdir -p $(BINDIR_c512D2)
38
+
39
+ OBJECTS_c512D2 = $(addprefix $(BINDIR_c512D2)/, $(notdir $(patsubst %.c,%.o,$(SOURCES_c512D2))))
40
+
41
+ CFLAGS_c512D2 = -Dc512 -DD2 -fomit-frame-pointer -O3 -g0 -march=native -mtune=native
42
+
43
+ VPATH = Sources
44
+
45
+ INCLUDES = -ISources
46
+
47
+ $(BINDIR_c256D2)/%.o:%.c $(HEADERS_c256D2)
48
+ $(CC) $(INCLUDES) $(CFLAGS_c256D2) -c $< -o $@
49
+
50
+ $(BINDIR_c512D2)/%.o:%.c $(HEADERS_c512D2)
51
+ $(CC) $(INCLUDES) $(CFLAGS_c512D2) -c $< -o $@
52
+
53
+ .PHONY: Keccakc256TreeD2 Keccakc512TreeD2
54
+
55
+ Keccakc256TreeD2: bin/Keccakc256TreeD2
56
+
57
+ bin/Keccakc256TreeD2: $(BINDIR_c256D2) $(OBJECTS_c256D2) $(HEADERS_c256D2)
58
+ $(CC) $(CFLAGS_c256D2) -o $@ $(OBJECTS_c256D2)
59
+
60
+ Keccakc512TreeD2: bin/Keccakc512TreeD2
61
+
62
+ bin/Keccakc512TreeD2: $(BINDIR_c512D2) $(OBJECTS_c512D2) $(HEADERS_c512D2)
63
+ $(CC) $(CFLAGS_c512D2) -o $@ $(OBJECTS_c512D2)
64
+
65
+ .PHONY: clean
66
+
67
+ clean:
68
+ rm -rf bin/
@@ -0,0 +1 @@
1
+ cl.exe Sources\mainOptimized.c Sources\genKAT.c Sources\KeccakDuplex.c Sources\KeccakF-1600-opt64.c Sources\KeccakNISTInterface.c Sources\KeccakSponge.c Sources\timing.c /O2 /Ot /favor:INTEL64
@@ -0,0 +1 @@
1
+ b81e02441c494c66e2a45cd1cd6ce40721eae5126523b1c4586cab9be9e0ccf23c3eac48edcce8ce7c587762817e213a44c6d85bf14b259fda5107cb96b298f175765f5684a86933d775d13ea2665940082740ad94d5cd006878e44ff0801c35e65e5a80b5ebb9ff6b4c44177667d2a3c68c73e7777eeba14738bb1d9ba673d4
@@ -0,0 +1 @@
1
+ 9b820a6ad49da5a2359566919b6d987d58eca84888c2123363ee57a932326449c8ca6bb9c3fb9f3be8364bf6ef3c2522140d92d636df0f580beeb381bc46491c
@@ -0,0 +1 @@
1
+ 58f992ee3a30041c7b5987ce169be4e18a8096bbb00c8794f377dff6bfedc76f4b11bc516d906b34062bf253a25e295d1f70addd94469bdf56268c19210639949c4821d83b78679168f582d31d7e942ebb297139f04595f1381942d03453779f477083075c6679819786e920069803af1359dfb78a1723638dcbea18ac80d3f1e1cd22b2e60accb25cc78f67e203372fb8fb2d3929cb95812622db2822ae8db951b675480a93273a
@@ -0,0 +1 @@
1
+ fe523291a13a5d4a395b11b922f5f0b99ec186097a9cbc2bfbef7b0aa03551adaaf1cd4651c7a675b9d3f9fd4e844572c716e50fed42feaede27b744b08950e5010700589513523a87a283c6c124032f77e1f18abfca2a046ae3c5aca543f9491037bab12ab1d58ab3d735680c543bb55d5759a949ca71b407ff27a2ce79de7853429b5264aa351397175fbe1e9ec784414ae4af270b88b8b011a54cea61ad3308cec8ef5ad96cc7
@@ -0,0 +1 @@
1
+ f96de427ccfc25f1ec48311b7bbbf00d8c5dbd25be1e91c1bd170562
@@ -0,0 +1 @@
1
+ ef4c3a6ae3c066643e3132da983f4e6ae4e15d222225d06c9fd5a2c4c794501c
@@ -0,0 +1 @@
1
+ 689ae4bd325cb0744ebc4a18ae565608fe6d3cf716196ab951afed2fe4fadbc1e204c73a869ebecf7ba9482401a2be0815ea7d728fec4a06961e35dcdbab4332fd6a0efcded7103e906cf3faa4b0a15bb6aa6172dccd01a566ddcda2f54ed78826400429fa20673002edbe0d5ee1e2d1741915e695b93778e6914d1d1065a1a1817af7d599bfd73d
@@ -0,0 +1 @@
1
+ 1dcf9ddf8ca2d0df093c215224bff74fe6e41e1fbda16a5aa076f4efdfa27aa43aca5001b79a69083449d39b22c593e5
@@ -0,0 +1,11 @@
1
+ #include "crypto_hash.h"
2
+ #include "KeccakSponge.h"
3
+
4
+ int crypto_hash(unsigned char *out, const unsigned char *in, unsigned long long inlen)
5
+ {
6
+ spongeState state;
7
+ InitSponge(&state, 1024, 576);
8
+ Absorb(&state, in, inlen*8);
9
+ Squeeze(&state, out, crypto_hash_BYTES*8);
10
+ return 0;
11
+ }