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,7 @@
1
+ #define Unrolling 24
2
+ #define UseBebigokimisa
3
+ //#define UseSSE
4
+ //#define UseOnlySIMD64
5
+ //#define UseMMX
6
+ //#define UseSHLD
7
+ //#define UseXOP
@@ -0,0 +1,504 @@
1
+ /*
2
+ The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
3
+ Michaël Peeters and Gilles Van Assche. For more information, feedback or
4
+ questions, please refer to our website: http://keccak.noekeon.org/
5
+
6
+ Implementation by the designers,
7
+ hereby denoted as "the implementer".
8
+
9
+ To the extent possible under law, the implementer has waived all copyright
10
+ and related or neighboring rights to the source code in this file.
11
+ http://creativecommons.org/publicdomain/zero/1.0/
12
+ */
13
+
14
+ #include <string.h>
15
+ #include "brg_endian.h"
16
+ #include "KeccakF-1600-opt64-settings.h"
17
+ #include "KeccakF-1600-interface.h"
18
+
19
+ typedef unsigned char UINT8;
20
+ typedef unsigned long long int UINT64;
21
+
22
+ #if defined(__GNUC__)
23
+ #define ALIGN __attribute__ ((aligned(32)))
24
+ #elif defined(_MSC_VER)
25
+ #define ALIGN __declspec(align(32))
26
+ #else
27
+ #define ALIGN
28
+ #endif
29
+
30
+ #if defined(UseSSE)
31
+ #include <x86intrin.h>
32
+ typedef __m128i V64;
33
+ typedef __m128i V128;
34
+ typedef union {
35
+ V128 v128;
36
+ UINT64 v64[2];
37
+ } V6464;
38
+
39
+ #define ANDnu64(a, b) _mm_andnot_si128(a, b)
40
+ #define LOAD64(a) _mm_loadl_epi64((const V64 *)&(a))
41
+ #define CONST64(a) _mm_loadl_epi64((const V64 *)&(a))
42
+ #define ROL64(a, o) _mm_or_si128(_mm_slli_epi64(a, o), _mm_srli_epi64(a, 64-(o)))
43
+ #define STORE64(a, b) _mm_storel_epi64((V64 *)&(a), b)
44
+ #define XOR64(a, b) _mm_xor_si128(a, b)
45
+ #define XOReq64(a, b) a = _mm_xor_si128(a, b)
46
+ #define SHUFFLEBYTES128(a, b) _mm_shuffle_epi8(a, b)
47
+
48
+ #define ANDnu128(a, b) _mm_andnot_si128(a, b)
49
+ #define LOAD6464(a, b) _mm_set_epi64((__m64)(a), (__m64)(b))
50
+ #define CONST128(a) _mm_load_si128((const V128 *)&(a))
51
+ #define LOAD128(a) _mm_load_si128((const V128 *)&(a))
52
+ #define LOAD128u(a) _mm_loadu_si128((const V128 *)&(a))
53
+ #define ROL64in128(a, o) _mm_or_si128(_mm_slli_epi64(a, o), _mm_srli_epi64(a, 64-(o)))
54
+ #define STORE128(a, b) _mm_store_si128((V128 *)&(a), b)
55
+ #define XOR128(a, b) _mm_xor_si128(a, b)
56
+ #define XOReq128(a, b) a = _mm_xor_si128(a, b)
57
+ #define GET64LOLO(a, b) _mm_unpacklo_epi64(a, b)
58
+ #define GET64HIHI(a, b) _mm_unpackhi_epi64(a, b)
59
+ #define COPY64HI2LO(a) _mm_shuffle_epi32(a, 0xEE)
60
+ #define COPY64LO2HI(a) _mm_shuffle_epi32(a, 0x44)
61
+ #define ZERO128() _mm_setzero_si128()
62
+
63
+ #ifdef UseOnlySIMD64
64
+ #include "KeccakF-1600-simd64.macros"
65
+ #else
66
+ ALIGN const UINT64 rho8_56[2] = {0x0605040302010007, 0x080F0E0D0C0B0A09};
67
+ #include "KeccakF-1600-simd128.macros"
68
+ #endif
69
+
70
+ #ifdef UseBebigokimisa
71
+ #error "UseBebigokimisa cannot be used in combination with UseSSE"
72
+ #endif
73
+ #elif defined(UseXOP)
74
+ #include <x86intrin.h>
75
+ typedef __m128i V64;
76
+ typedef __m128i V128;
77
+
78
+ #define LOAD64(a) _mm_loadl_epi64((const V64 *)&(a))
79
+ #define CONST64(a) _mm_loadl_epi64((const V64 *)&(a))
80
+ #define STORE64(a, b) _mm_storel_epi64((V64 *)&(a), b)
81
+ #define XOR64(a, b) _mm_xor_si128(a, b)
82
+ #define XOReq64(a, b) a = _mm_xor_si128(a, b)
83
+
84
+ #define ANDnu128(a, b) _mm_andnot_si128(a, b)
85
+ #define LOAD6464(a, b) _mm_set_epi64((__m64)(a), (__m64)(b))
86
+ #define CONST128(a) _mm_load_si128((const V128 *)&(a))
87
+ #define LOAD128(a) _mm_load_si128((const V128 *)&(a))
88
+ #define LOAD128u(a) _mm_loadu_si128((const V128 *)&(a))
89
+ #define STORE128(a, b) _mm_store_si128((V128 *)&(a), b)
90
+ #define XOR128(a, b) _mm_xor_si128(a, b)
91
+ #define XOReq128(a, b) a = _mm_xor_si128(a, b)
92
+ #define ZERO128() _mm_setzero_si128()
93
+
94
+ #define SWAP64(a) _mm_shuffle_epi32(a, 0x4E)
95
+ #define GET64LOLO(a, b) _mm_unpacklo_epi64(a, b)
96
+ #define GET64HIHI(a, b) _mm_unpackhi_epi64(a, b)
97
+ #define GET64LOHI(a, b) ((__m128i)_mm_blend_pd((__m128d)a, (__m128d)b, 2))
98
+ #define GET64HILO(a, b) SWAP64(GET64LOHI(b, a))
99
+ #define COPY64HI2LO(a) _mm_shuffle_epi32(a, 0xEE)
100
+ #define COPY64LO2HI(a) _mm_shuffle_epi32(a, 0x44)
101
+
102
+ #define ROL6464same(a, o) _mm_roti_epi64(a, o)
103
+ #define ROL6464(a, r1, r2) _mm_rot_epi64(a, CONST128( rot_##r1##_##r2 ))
104
+ ALIGN const UINT64 rot_0_20[2] = { 0, 20};
105
+ ALIGN const UINT64 rot_44_3[2] = {44, 3};
106
+ ALIGN const UINT64 rot_43_45[2] = {43, 45};
107
+ ALIGN const UINT64 rot_21_61[2] = {21, 61};
108
+ ALIGN const UINT64 rot_14_28[2] = {14, 28};
109
+ ALIGN const UINT64 rot_1_36[2] = { 1, 36};
110
+ ALIGN const UINT64 rot_6_10[2] = { 6, 10};
111
+ ALIGN const UINT64 rot_25_15[2] = {25, 15};
112
+ ALIGN const UINT64 rot_8_56[2] = { 8, 56};
113
+ ALIGN const UINT64 rot_18_27[2] = {18, 27};
114
+ ALIGN const UINT64 rot_62_55[2] = {62, 55};
115
+ ALIGN const UINT64 rot_39_41[2] = {39, 41};
116
+
117
+ #if defined(UseSimulatedXOP)
118
+ // For debugging purposes, when XOP is not available
119
+ #undef ROL6464
120
+ #undef ROL6464same
121
+ #define ROL6464same(a, o) _mm_or_si128(_mm_slli_epi64(a, o), _mm_srli_epi64(a, 64-(o)))
122
+ V128 ROL6464(V128 a, int r0, int r1)
123
+ {
124
+ V128 a0 = ROL64(a, r0);
125
+ V128 a1 = COPY64HI2LO(ROL64(a, r1));
126
+ return GET64LOLO(a0, a1);
127
+ }
128
+ #endif
129
+
130
+ #include "KeccakF-1600-xop.macros"
131
+
132
+ #ifdef UseBebigokimisa
133
+ #error "UseBebigokimisa cannot be used in combination with UseXOP"
134
+ #endif
135
+ #elif defined(UseMMX)
136
+ #include <mmintrin.h>
137
+ typedef __m64 V64;
138
+ #define ANDnu64(a, b) _mm_andnot_si64(a, b)
139
+
140
+ #if (defined(_MSC_VER) || defined (__INTEL_COMPILER))
141
+ #define LOAD64(a) *(V64*)&(a)
142
+ #define CONST64(a) *(V64*)&(a)
143
+ #define STORE64(a, b) *(V64*)&(a) = b
144
+ #else
145
+ #define LOAD64(a) (V64)a
146
+ #define CONST64(a) (V64)a
147
+ #define STORE64(a, b) a = (UINT64)b
148
+ #endif
149
+ #define ROL64(a, o) _mm_or_si64(_mm_slli_si64(a, o), _mm_srli_si64(a, 64-(o)))
150
+ #define XOR64(a, b) _mm_xor_si64(a, b)
151
+ #define XOReq64(a, b) a = _mm_xor_si64(a, b)
152
+
153
+ #include "KeccakF-1600-simd64.macros"
154
+
155
+ #ifdef UseBebigokimisa
156
+ #error "UseBebigokimisa cannot be used in combination with UseMMX"
157
+ #endif
158
+ #else
159
+ #if defined(_MSC_VER)
160
+ #define ROL64(a, offset) _rotl64(a, offset)
161
+ #elif defined(UseSHLD)
162
+ #define ROL64(x,N) ({ \
163
+ register UINT64 __out; \
164
+ register UINT64 __in = x; \
165
+ __asm__ ("shld %2,%0,%0" : "=r"(__out) : "0"(__in), "i"(N)); \
166
+ __out; \
167
+ })
168
+ #else
169
+ #define ROL64(a, offset) ((((UINT64)a) << offset) ^ (((UINT64)a) >> (64-offset)))
170
+ #endif
171
+
172
+ #include "KeccakF-1600-64.macros"
173
+ #endif
174
+
175
+ #include "KeccakF-1600-unrolling.macros"
176
+
177
+ void KeccakPermutationOnWords(UINT64 *state)
178
+ {
179
+ declareABCDE
180
+ #if (Unrolling != 24)
181
+ unsigned int i;
182
+ #endif
183
+
184
+ copyFromState(A, state)
185
+ rounds
186
+ #if defined(UseMMX)
187
+ _mm_empty();
188
+ #endif
189
+ }
190
+
191
+ void KeccakPermutationOnWordsAfterXoring(UINT64 *state, const UINT64 *input, unsigned int laneCount)
192
+ {
193
+ declareABCDE
194
+ #if (Unrolling != 24)
195
+ unsigned int i;
196
+ #endif
197
+ unsigned int j;
198
+
199
+ for(j=0; j<laneCount; j++)
200
+ state[j] ^= input[j];
201
+ copyFromState(A, state)
202
+ rounds
203
+ #if defined(UseMMX)
204
+ _mm_empty();
205
+ #endif
206
+ }
207
+
208
+ #ifdef ProvideFast576
209
+ void KeccakPermutationOnWordsAfterXoring576bits(UINT64 *state, const UINT64 *input)
210
+ {
211
+ declareABCDE
212
+ #if (Unrolling != 24)
213
+ unsigned int i;
214
+ #endif
215
+
216
+ copyFromStateAndXor576bits(A, state, input)
217
+ rounds
218
+ #if defined(UseMMX)
219
+ _mm_empty();
220
+ #endif
221
+ }
222
+ #endif
223
+
224
+ #ifdef ProvideFast832
225
+ void KeccakPermutationOnWordsAfterXoring832bits(UINT64 *state, const UINT64 *input)
226
+ {
227
+ declareABCDE
228
+ #if (Unrolling != 24)
229
+ unsigned int i;
230
+ #endif
231
+
232
+ copyFromStateAndXor832bits(A, state, input)
233
+ rounds
234
+ #if defined(UseMMX)
235
+ _mm_empty();
236
+ #endif
237
+ }
238
+ #endif
239
+
240
+ #ifdef ProvideFast1024
241
+ void KeccakPermutationOnWordsAfterXoring1024bits(UINT64 *state, const UINT64 *input)
242
+ {
243
+ declareABCDE
244
+ #if (Unrolling != 24)
245
+ unsigned int i;
246
+ #endif
247
+
248
+ copyFromStateAndXor1024bits(A, state, input)
249
+ rounds
250
+ #if defined(UseMMX)
251
+ _mm_empty();
252
+ #endif
253
+ }
254
+ #endif
255
+
256
+ #ifdef ProvideFast1088
257
+ void KeccakPermutationOnWordsAfterXoring1088bits(UINT64 *state, const UINT64 *input)
258
+ {
259
+ declareABCDE
260
+ #if (Unrolling != 24)
261
+ unsigned int i;
262
+ #endif
263
+
264
+ copyFromStateAndXor1088bits(A, state, input)
265
+ rounds
266
+ #if defined(UseMMX)
267
+ _mm_empty();
268
+ #endif
269
+ }
270
+ #endif
271
+
272
+ #ifdef ProvideFast1152
273
+ void KeccakPermutationOnWordsAfterXoring1152bits(UINT64 *state, const UINT64 *input)
274
+ {
275
+ declareABCDE
276
+ #if (Unrolling != 24)
277
+ unsigned int i;
278
+ #endif
279
+
280
+ copyFromStateAndXor1152bits(A, state, input)
281
+ rounds
282
+ #if defined(UseMMX)
283
+ _mm_empty();
284
+ #endif
285
+ }
286
+ #endif
287
+
288
+ #ifdef ProvideFast1344
289
+ void KeccakPermutationOnWordsAfterXoring1344bits(UINT64 *state, const UINT64 *input)
290
+ {
291
+ declareABCDE
292
+ #if (Unrolling != 24)
293
+ unsigned int i;
294
+ #endif
295
+
296
+ copyFromStateAndXor1344bits(A, state, input)
297
+ rounds
298
+ #if defined(UseMMX)
299
+ _mm_empty();
300
+ #endif
301
+ }
302
+ #endif
303
+
304
+ void KeccakInitialize()
305
+ {
306
+ }
307
+
308
+ void KeccakInitializeState(unsigned char *state)
309
+ {
310
+ memset(state, 0, 200);
311
+ #ifdef UseBebigokimisa
312
+ ((UINT64*)state)[ 1] = ~(UINT64)0;
313
+ ((UINT64*)state)[ 2] = ~(UINT64)0;
314
+ ((UINT64*)state)[ 8] = ~(UINT64)0;
315
+ ((UINT64*)state)[12] = ~(UINT64)0;
316
+ ((UINT64*)state)[17] = ~(UINT64)0;
317
+ ((UINT64*)state)[20] = ~(UINT64)0;
318
+ #endif
319
+ }
320
+
321
+ void KeccakPermutation(unsigned char *state)
322
+ {
323
+ // We assume the state is always stored as words
324
+ KeccakPermutationOnWords((UINT64*)state);
325
+ }
326
+
327
+ void fromBytesToWord(UINT64 *word, const UINT8 *bytes)
328
+ {
329
+ unsigned int i;
330
+
331
+ *word = 0;
332
+ for(i=0; i<(64/8); i++)
333
+ *word |= (UINT64)(bytes[i]) << (8*i);
334
+ }
335
+
336
+ #ifdef ProvideFast576
337
+ void KeccakAbsorb576bits(unsigned char *state, const unsigned char *data)
338
+ {
339
+ #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
340
+ KeccakPermutationOnWordsAfterXoring576bits((UINT64*)state, (const UINT64*)data);
341
+ #else
342
+ UINT64 dataAsWords[9];
343
+ unsigned int i;
344
+
345
+ for(i=0; i<9; i++)
346
+ fromBytesToWord(dataAsWords+i, data+(i*8));
347
+ KeccakPermutationOnWordsAfterXoring576bits((UINT64*)state, dataAsWords);
348
+ #endif
349
+ }
350
+ #endif
351
+
352
+ #ifdef ProvideFast832
353
+ void KeccakAbsorb832bits(unsigned char *state, const unsigned char *data)
354
+ {
355
+ #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
356
+ KeccakPermutationOnWordsAfterXoring832bits((UINT64*)state, (const UINT64*)data);
357
+ #else
358
+ UINT64 dataAsWords[13];
359
+ unsigned int i;
360
+
361
+ for(i=0; i<13; i++)
362
+ fromBytesToWord(dataAsWords+i, data+(i*8));
363
+ KeccakPermutationOnWordsAfterXoring832bits((UINT64*)state, dataAsWords);
364
+ #endif
365
+ }
366
+ #endif
367
+
368
+ #ifdef ProvideFast1024
369
+ void KeccakAbsorb1024bits(unsigned char *state, const unsigned char *data)
370
+ {
371
+ #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
372
+ KeccakPermutationOnWordsAfterXoring1024bits((UINT64*)state, (const UINT64*)data);
373
+ #else
374
+ UINT64 dataAsWords[16];
375
+ unsigned int i;
376
+
377
+ for(i=0; i<16; i++)
378
+ fromBytesToWord(dataAsWords+i, data+(i*8));
379
+ KeccakPermutationOnWordsAfterXoring1024bits((UINT64*)state, dataAsWords);
380
+ #endif
381
+ }
382
+ #endif
383
+
384
+ #ifdef ProvideFast1088
385
+ void KeccakAbsorb1088bits(unsigned char *state, const unsigned char *data)
386
+ {
387
+ #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
388
+ KeccakPermutationOnWordsAfterXoring1088bits((UINT64*)state, (const UINT64*)data);
389
+ #else
390
+ UINT64 dataAsWords[17];
391
+ unsigned int i;
392
+
393
+ for(i=0; i<17; i++)
394
+ fromBytesToWord(dataAsWords+i, data+(i*8));
395
+ KeccakPermutationOnWordsAfterXoring1088bits((UINT64*)state, dataAsWords);
396
+ #endif
397
+ }
398
+ #endif
399
+
400
+ #ifdef ProvideFast1152
401
+ void KeccakAbsorb1152bits(unsigned char *state, const unsigned char *data)
402
+ {
403
+ #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
404
+ KeccakPermutationOnWordsAfterXoring1152bits((UINT64*)state, (const UINT64*)data);
405
+ #else
406
+ UINT64 dataAsWords[18];
407
+ unsigned int i;
408
+
409
+ for(i=0; i<18; i++)
410
+ fromBytesToWord(dataAsWords+i, data+(i*8));
411
+ KeccakPermutationOnWordsAfterXoring1152bits((UINT64*)state, dataAsWords);
412
+ #endif
413
+ }
414
+ #endif
415
+
416
+ #ifdef ProvideFast1344
417
+ void KeccakAbsorb1344bits(unsigned char *state, const unsigned char *data)
418
+ {
419
+ #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
420
+ KeccakPermutationOnWordsAfterXoring1344bits((UINT64*)state, (const UINT64*)data);
421
+ #else
422
+ UINT64 dataAsWords[21];
423
+ unsigned int i;
424
+
425
+ for(i=0; i<21; i++)
426
+ fromBytesToWord(dataAsWords+i, data+(i*8));
427
+ KeccakPermutationOnWordsAfterXoring1344bits((UINT64*)state, dataAsWords);
428
+ #endif
429
+ }
430
+ #endif
431
+
432
+ void KeccakAbsorb(unsigned char *state, const unsigned char *data, unsigned int laneCount)
433
+ {
434
+ #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
435
+ KeccakPermutationOnWordsAfterXoring((UINT64*)state, (const UINT64*)data, laneCount);
436
+ #else
437
+ UINT64 dataAsWords[25];
438
+ unsigned int i;
439
+
440
+ for(i=0; i<laneCount; i++)
441
+ fromBytesToWord(dataAsWords+i, data+(i*8));
442
+ KeccakPermutationOnWordsAfterXoring((UINT64*)state, dataAsWords, laneCount);
443
+ #endif
444
+ }
445
+
446
+ void fromWordToBytes(UINT8 *bytes, const UINT64 word)
447
+ {
448
+ unsigned int i;
449
+
450
+ for(i=0; i<(64/8); i++)
451
+ bytes[i] = (word >> (8*i)) & 0xFF;
452
+ }
453
+
454
+ #ifdef ProvideFast1024
455
+ void KeccakExtract1024bits(const unsigned char *state, unsigned char *data)
456
+ {
457
+ #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
458
+ memcpy(data, state, 128);
459
+ #else
460
+ unsigned int i;
461
+
462
+ for(i=0; i<16; i++)
463
+ fromWordToBytes(data+(i*8), ((const UINT64*)state)[i]);
464
+ #endif
465
+ #ifdef UseBebigokimisa
466
+ ((UINT64*)data)[ 1] = ~((UINT64*)data)[ 1];
467
+ ((UINT64*)data)[ 2] = ~((UINT64*)data)[ 2];
468
+ ((UINT64*)data)[ 8] = ~((UINT64*)data)[ 8];
469
+ ((UINT64*)data)[12] = ~((UINT64*)data)[12];
470
+ #endif
471
+ }
472
+ #endif
473
+
474
+ void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int laneCount)
475
+ {
476
+ #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
477
+ memcpy(data, state, laneCount*8);
478
+ #else
479
+ unsigned int i;
480
+
481
+ for(i=0; i<laneCount; i++)
482
+ fromWordToBytes(data+(i*8), ((const UINT64*)state)[i]);
483
+ #endif
484
+ #ifdef UseBebigokimisa
485
+ if (laneCount > 1) {
486
+ ((UINT64*)data)[ 1] = ~((UINT64*)data)[ 1];
487
+ if (laneCount > 2) {
488
+ ((UINT64*)data)[ 2] = ~((UINT64*)data)[ 2];
489
+ if (laneCount > 8) {
490
+ ((UINT64*)data)[ 8] = ~((UINT64*)data)[ 8];
491
+ if (laneCount > 12) {
492
+ ((UINT64*)data)[12] = ~((UINT64*)data)[12];
493
+ if (laneCount > 17) {
494
+ ((UINT64*)data)[17] = ~((UINT64*)data)[17];
495
+ if (laneCount > 20) {
496
+ ((UINT64*)data)[20] = ~((UINT64*)data)[20];
497
+ }
498
+ }
499
+ }
500
+ }
501
+ }
502
+ }
503
+ #endif
504
+ }