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,849 @@
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 and 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
+ // WARNING: This implementation assumes a little-endian platform. Support for big-endinanness is not yet implemented.
15
+
16
+ #include <string.h>
17
+ #include "Keccak-inplace-settings.h"
18
+ #define cKeccakR_SizeInBytes (cKeccakR / 8)
19
+ #include "crypto_hash.h"
20
+ #ifndef crypto_hash_BYTES
21
+ #ifdef cKeccakFixedOutputLengthInBytes
22
+ #define crypto_hash_BYTES cKeccakFixedOutputLengthInBytes
23
+ #else
24
+ #define crypto_hash_BYTES cKeccakR_SizeInBytes
25
+ #endif
26
+ #endif
27
+ #if (crypto_hash_BYTES > cKeccakR_SizeInBytes)
28
+ #error "Full squeezing not yet implemented"
29
+ #endif
30
+
31
+ #if (cKeccakB == 1600)
32
+ typedef unsigned int UINT32;
33
+ // WARNING: on 8-bit and 16-bit platforms, this should be replaced by:
34
+ //typedef unsigned long UINT32;
35
+ #define cKeccakNumberOfRounds 24
36
+ #define cKeccakLaneSizeInBytes 8
37
+ #else
38
+ #error "Unsupported Keccak-f width"
39
+ #endif
40
+
41
+ #define cKeccakLaneSizeInBits (cKeccakLaneSizeInBytes * 8)
42
+
43
+ #define ROL32(a, offset) ((((UINT32)a) << (offset)) ^ (((UINT32)a) >> (32-(offset))))
44
+ void KeccakF( UINT32 * state, const UINT32 *in, int laneCount );
45
+ void extractFromState( unsigned char *out, const UINT32 *state, int laneCount );
46
+
47
+ int crypto_hash( unsigned char *out, const unsigned char *in, unsigned long long inlen )
48
+ {
49
+ UINT32 state[5 * 5 * 2];
50
+ #if (crypto_hash_BYTES >= cKeccakR_SizeInBytes)
51
+ #define temp out
52
+ #else
53
+ unsigned char temp[cKeccakR_SizeInBytes];
54
+ #endif
55
+
56
+ memset( state, 0, sizeof(state) );
57
+
58
+ for ( /* empty */; inlen >= cKeccakR_SizeInBytes; inlen -= cKeccakR_SizeInBytes, in += cKeccakR_SizeInBytes )
59
+ {
60
+ KeccakF( state, (const UINT32*)in, cKeccakR_SizeInBytes / cKeccakLaneSizeInBytes );
61
+ }
62
+
63
+ // padding
64
+ memcpy( temp, in, (size_t)inlen );
65
+ temp[inlen++] = 1;
66
+ memset( temp+inlen, 0, cKeccakR_SizeInBytes - (size_t)inlen );
67
+ temp[cKeccakR_SizeInBytes-1] |= 0x80;
68
+ KeccakF( state, (const UINT32*)temp, cKeccakR_SizeInBytes / cKeccakLaneSizeInBytes );
69
+
70
+ #if ((crypto_hash_BYTES % cKeccakLaneSizeInBytes) == 0)
71
+ extractFromState( out, state, crypto_hash_BYTES / cKeccakLaneSizeInBytes );
72
+ #else
73
+ #error "The output size must be a multiple of the lane size in this simple implementation."
74
+ #endif
75
+
76
+ #if (crypto_hash_BYTES >= cKeccakR_SizeInBytes)
77
+ #undef temp
78
+ #endif
79
+
80
+ return ( 0 );
81
+ }
82
+
83
+ void extractFromState( unsigned char *out, const UINT32 *state, int laneCount )
84
+ {
85
+ // Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002
86
+ UINT32 * pI = (UINT32 *)out;
87
+ const UINT32 * pS = state;
88
+ UINT32 t, x0, x1;
89
+ int i;
90
+ for (i = laneCount-1; i >= 0; --i)
91
+ {
92
+ x0 = *(pS++);
93
+ x1 = *(pS++);
94
+ t = (x0 & 0x0000FFFF) | (x1 << 16);
95
+ x1 = (x0 >> 16) | (x1 & 0xFFFF0000);
96
+ x0 = t;
97
+ t = (x0 ^ (x0 >> 8)) & 0x0000FF00UL; x0 = x0 ^ t ^ (t << 8);
98
+ t = (x0 ^ (x0 >> 4)) & 0x00F000F0UL; x0 = x0 ^ t ^ (t << 4);
99
+ t = (x0 ^ (x0 >> 2)) & 0x0C0C0C0CUL; x0 = x0 ^ t ^ (t << 2);
100
+ t = (x0 ^ (x0 >> 1)) & 0x22222222UL; x0 = x0 ^ t ^ (t << 1);
101
+ t = (x1 ^ (x1 >> 8)) & 0x0000FF00UL; x1 = x1 ^ t ^ (t << 8);
102
+ t = (x1 ^ (x1 >> 4)) & 0x00F000F0UL; x1 = x1 ^ t ^ (t << 4);
103
+ t = (x1 ^ (x1 >> 2)) & 0x0C0C0C0CUL; x1 = x1 ^ t ^ (t << 2);
104
+ t = (x1 ^ (x1 >> 1)) & 0x22222222UL; x1 = x1 ^ t ^ (t << 1);
105
+ *(pI++) = x0;
106
+ *(pI++) = x1;
107
+ }
108
+ }
109
+
110
+ static const UINT32 KeccakF1600RoundConstants_int2[2*24+1] =
111
+ {
112
+ 0x00000001UL, 0x00000000UL,
113
+ 0x00000000UL, 0x00000089UL,
114
+ 0x00000000UL, 0x8000008bUL,
115
+ 0x00000000UL, 0x80008080UL,
116
+ 0x00000001UL, 0x0000008bUL,
117
+ 0x00000001UL, 0x00008000UL,
118
+ 0x00000001UL, 0x80008088UL,
119
+ 0x00000001UL, 0x80000082UL,
120
+ 0x00000000UL, 0x0000000bUL,
121
+ 0x00000000UL, 0x0000000aUL,
122
+ 0x00000001UL, 0x00008082UL,
123
+ 0x00000000UL, 0x00008003UL,
124
+ 0x00000001UL, 0x0000808bUL,
125
+ 0x00000001UL, 0x8000000bUL,
126
+ 0x00000001UL, 0x8000008aUL,
127
+ 0x00000001UL, 0x80000081UL,
128
+ 0x00000000UL, 0x80000081UL,
129
+ 0x00000000UL, 0x80000008UL,
130
+ 0x00000000UL, 0x00000083UL,
131
+ 0x00000000UL, 0x80008003UL,
132
+ 0x00000001UL, 0x80008088UL,
133
+ 0x00000000UL, 0x80000088UL,
134
+ 0x00000001UL, 0x00008000UL,
135
+ 0x00000000UL, 0x80008082UL,
136
+ 0x000000FFUL
137
+ };
138
+
139
+ #define KeccakAtoD_round0() \
140
+ Cx = Abu0^Agu0^Aku0^Amu0^Asu0; \
141
+ Du1 = Abe1^Age1^Ake1^Ame1^Ase1; \
142
+ Da0 = Cx^ROL32(Du1, 1); \
143
+ Cz = Abu1^Agu1^Aku1^Amu1^Asu1; \
144
+ Du0 = Abe0^Age0^Ake0^Ame0^Ase0; \
145
+ Da1 = Cz^Du0; \
146
+ \
147
+ Cw = Abi0^Agi0^Aki0^Ami0^Asi0; \
148
+ Do0 = Cw^ROL32(Cz, 1); \
149
+ Cy = Abi1^Agi1^Aki1^Ami1^Asi1; \
150
+ Do1 = Cy^Cx; \
151
+ \
152
+ Cx = Aba0^Aga0^Aka0^Ama0^Asa0; \
153
+ De0 = Cx^ROL32(Cy, 1); \
154
+ Cz = Aba1^Aga1^Aka1^Ama1^Asa1; \
155
+ De1 = Cz^Cw; \
156
+ \
157
+ Cy = Abo1^Ago1^Ako1^Amo1^Aso1; \
158
+ Di0 = Du0^ROL32(Cy, 1); \
159
+ Cw = Abo0^Ago0^Ako0^Amo0^Aso0; \
160
+ Di1 = Du1^Cw; \
161
+ \
162
+ Du0 = Cw^ROL32(Cz, 1); \
163
+ Du1 = Cy^Cx; \
164
+
165
+ #define KeccakAtoD_round1() \
166
+ Cx = Asu0^Agu0^Amu0^Abu1^Aku1; \
167
+ Du1 = Age1^Ame0^Abe0^Ake1^Ase1; \
168
+ Da0 = Cx^ROL32(Du1, 1); \
169
+ Cz = Asu1^Agu1^Amu1^Abu0^Aku0; \
170
+ Du0 = Age0^Ame1^Abe1^Ake0^Ase0; \
171
+ Da1 = Cz^Du0; \
172
+ \
173
+ Cw = Aki1^Asi1^Agi0^Ami1^Abi0; \
174
+ Do0 = Cw^ROL32(Cz, 1); \
175
+ Cy = Aki0^Asi0^Agi1^Ami0^Abi1; \
176
+ Do1 = Cy^Cx; \
177
+ \
178
+ Cx = Aba0^Aka1^Asa0^Aga0^Ama1; \
179
+ De0 = Cx^ROL32(Cy, 1); \
180
+ Cz = Aba1^Aka0^Asa1^Aga1^Ama0; \
181
+ De1 = Cz^Cw; \
182
+ \
183
+ Cy = Amo0^Abo1^Ako0^Aso1^Ago0; \
184
+ Di0 = Du0^ROL32(Cy, 1); \
185
+ Cw = Amo1^Abo0^Ako1^Aso0^Ago1; \
186
+ Di1 = Du1^Cw; \
187
+ \
188
+ Du0 = Cw^ROL32(Cz, 1); \
189
+ Du1 = Cy^Cx; \
190
+
191
+ #define KeccakAtoD_round2() \
192
+ Cx = Aku1^Agu0^Abu1^Asu1^Amu1; \
193
+ Du1 = Ame0^Ake0^Age0^Abe0^Ase1; \
194
+ Da0 = Cx^ROL32(Du1, 1); \
195
+ Cz = Aku0^Agu1^Abu0^Asu0^Amu0; \
196
+ Du0 = Ame1^Ake1^Age1^Abe1^Ase0; \
197
+ Da1 = Cz^Du0; \
198
+ \
199
+ Cw = Agi1^Abi1^Asi1^Ami0^Aki1; \
200
+ Do0 = Cw^ROL32(Cz, 1); \
201
+ Cy = Agi0^Abi0^Asi0^Ami1^Aki0; \
202
+ Do1 = Cy^Cx; \
203
+ \
204
+ Cx = Aba0^Asa1^Ama1^Aka1^Aga1; \
205
+ De0 = Cx^ROL32(Cy, 1); \
206
+ Cz = Aba1^Asa0^Ama0^Aka0^Aga0; \
207
+ De1 = Cz^Cw; \
208
+ \
209
+ Cy = Aso0^Amo0^Ako1^Ago0^Abo0; \
210
+ Di0 = Du0^ROL32(Cy, 1); \
211
+ Cw = Aso1^Amo1^Ako0^Ago1^Abo1; \
212
+ Di1 = Du1^Cw; \
213
+ \
214
+ Du0 = Cw^ROL32(Cz, 1); \
215
+ Du1 = Cy^Cx; \
216
+
217
+ #define KeccakAtoD_round3() \
218
+ Cx = Amu1^Agu0^Asu1^Aku0^Abu0; \
219
+ Du1 = Ake0^Abe1^Ame1^Age0^Ase1; \
220
+ Da0 = Cx^ROL32(Du1, 1); \
221
+ Cz = Amu0^Agu1^Asu0^Aku1^Abu1; \
222
+ Du0 = Ake1^Abe0^Ame0^Age1^Ase0; \
223
+ Da1 = Cz^Du0; \
224
+ \
225
+ Cw = Asi0^Aki0^Abi1^Ami1^Agi1; \
226
+ Do0 = Cw^ROL32(Cz, 1); \
227
+ Cy = Asi1^Aki1^Abi0^Ami0^Agi0; \
228
+ Do1 = Cy^Cx; \
229
+ \
230
+ Cx = Aba0^Ama0^Aga1^Asa1^Aka0; \
231
+ De0 = Cx^ROL32(Cy, 1); \
232
+ Cz = Aba1^Ama1^Aga0^Asa0^Aka1; \
233
+ De1 = Cz^Cw; \
234
+ \
235
+ Cy = Ago1^Aso0^Ako0^Abo0^Amo1; \
236
+ Di0 = Du0^ROL32(Cy, 1); \
237
+ Cw = Ago0^Aso1^Ako1^Abo1^Amo0; \
238
+ Di1 = Du1^Cw; \
239
+ \
240
+ Du0 = Cw^ROL32(Cz, 1); \
241
+ Du1 = Cy^Cx; \
242
+
243
+ void KeccakF( UINT32 *state, const UINT32 *in, int laneCount )
244
+ {
245
+
246
+ // Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002
247
+ {
248
+ const UINT32 * pI = (const UINT32 *)in;
249
+ UINT32 * pS = state;
250
+ UINT32 t, x0, x1;
251
+ int i;
252
+ for (i = laneCount-1; i >= 0; --i)
253
+ {
254
+ x0 = *(pI++);
255
+ t = (x0 ^ (x0 >> 1)) & 0x22222222UL; x0 = x0 ^ t ^ (t << 1);
256
+ t = (x0 ^ (x0 >> 2)) & 0x0C0C0C0CUL; x0 = x0 ^ t ^ (t << 2);
257
+ t = (x0 ^ (x0 >> 4)) & 0x00F000F0UL; x0 = x0 ^ t ^ (t << 4);
258
+ t = (x0 ^ (x0 >> 8)) & 0x0000FF00UL; x0 = x0 ^ t ^ (t << 8);
259
+ x1 = *(pI++);
260
+ t = (x1 ^ (x1 >> 1)) & 0x22222222UL; x1 = x1 ^ t ^ (t << 1);
261
+ t = (x1 ^ (x1 >> 2)) & 0x0C0C0C0CUL; x1 = x1 ^ t ^ (t << 2);
262
+ t = (x1 ^ (x1 >> 4)) & 0x00F000F0UL; x1 = x1 ^ t ^ (t << 4);
263
+ t = (x1 ^ (x1 >> 8)) & 0x0000FF00UL; x1 = x1 ^ t ^ (t << 8);
264
+ *(pS++) ^= (x0 & 0x0000FFFF) | (x1 << 16);
265
+ *(pS++) ^= (x0 >> 16) | (x1 & 0xFFFF0000);
266
+ }
267
+ }
268
+
269
+ {
270
+ UINT32 Da0, De0, Di0, Do0, Du0;
271
+ UINT32 Da1, De1, Di1, Do1;
272
+ #define Du1 laneCount
273
+ UINT32 Ca0, Ce0, Ci0, Co0, Cu0;
274
+ UINT32 Cx, Cy, Cz, Cw;
275
+ #define Ba Ca0
276
+ #define Be Ce0
277
+ #define Bi Ci0
278
+ #define Bo Co0
279
+ #define Bu Cu0
280
+ #define pRoundConstants in
281
+
282
+
283
+ #define Aba0 state[ 0]
284
+ #define Aba1 state[ 1]
285
+ #define Abe0 state[ 2]
286
+ #define Abe1 state[ 3]
287
+ #define Abi0 state[ 4]
288
+ #define Abi1 state[ 5]
289
+ #define Abo0 state[ 6]
290
+ #define Abo1 state[ 7]
291
+ #define Abu0 state[ 8]
292
+ #define Abu1 state[ 9]
293
+ #define Aga0 state[10]
294
+ #define Aga1 state[11]
295
+ #define Age0 state[12]
296
+ #define Age1 state[13]
297
+ #define Agi0 state[14]
298
+ #define Agi1 state[15]
299
+ #define Ago0 state[16]
300
+ #define Ago1 state[17]
301
+ #define Agu0 state[18]
302
+ #define Agu1 state[19]
303
+ #define Aka0 state[20]
304
+ #define Aka1 state[21]
305
+ #define Ake0 state[22]
306
+ #define Ake1 state[23]
307
+ #define Aki0 state[24]
308
+ #define Aki1 state[25]
309
+ #define Ako0 state[26]
310
+ #define Ako1 state[27]
311
+ #define Aku0 state[28]
312
+ #define Aku1 state[29]
313
+ #define Ama0 state[30]
314
+ #define Ama1 state[31]
315
+ #define Ame0 state[32]
316
+ #define Ame1 state[33]
317
+ #define Ami0 state[34]
318
+ #define Ami1 state[35]
319
+ #define Amo0 state[36]
320
+ #define Amo1 state[37]
321
+ #define Amu0 state[38]
322
+ #define Amu1 state[39]
323
+ #define Asa0 state[40]
324
+ #define Asa1 state[41]
325
+ #define Ase0 state[42]
326
+ #define Ase1 state[43]
327
+ #define Asi0 state[44]
328
+ #define Asi1 state[45]
329
+ #define Aso0 state[46]
330
+ #define Aso1 state[47]
331
+ #define Asu0 state[48]
332
+ #define Asu1 state[49]
333
+
334
+ pRoundConstants = KeccakF1600RoundConstants_int2;
335
+ do
336
+ {
337
+ // --- Code for 4 rounds
338
+ // --- using factor 2 interleaving, 64-bit lanes mapped to 32-bit words
339
+ KeccakAtoD_round0();
340
+
341
+ Ba = (Aba0^Da0);
342
+ Be = ROL32((Age0^De0), 22);
343
+ Bi = ROL32((Aki1^Di1), 22);
344
+ Bo = ROL32((Amo1^Do1), 11);
345
+ Bu = ROL32((Asu0^Du0), 7);
346
+ Aba0 = Ba ^((~Be)& Bi );
347
+ Aba0 ^= *(pRoundConstants++);
348
+ Age0 = Be ^((~Bi)& Bo );
349
+ Aki1 = Bi ^((~Bo)& Bu );
350
+ Amo1 = Bo ^((~Bu)& Ba );
351
+ Asu0 = Bu ^((~Ba)& Be );
352
+
353
+ Ba = (Aba1^Da1);
354
+ Be = ROL32((Age1^De1), 22);
355
+ Bi = ROL32((Aki0^Di0), 21);
356
+ Bo = ROL32((Amo0^Do0), 10);
357
+ Bu = ROL32((Asu1^Du1), 7);
358
+ Aba1 = Ba ^((~Be)& Bi );
359
+ Aba1 ^= *(pRoundConstants++);
360
+ Age1 = Be ^((~Bi)& Bo );
361
+ Aki0 = Bi ^((~Bo)& Bu );
362
+ Amo0 = Bo ^((~Bu)& Ba );
363
+ Asu1 = Bu ^((~Ba)& Be );
364
+
365
+ Bi = ROL32((Aka1^Da1), 2);
366
+ Bo = ROL32((Ame1^De1), 23);
367
+ Bu = ROL32((Asi1^Di1), 31);
368
+ Ba = ROL32((Abo0^Do0), 14);
369
+ Be = ROL32((Agu0^Du0), 10);
370
+ Aka1 = Ba ^((~Be)& Bi );
371
+ Ame1 = Be ^((~Bi)& Bo );
372
+ Asi1 = Bi ^((~Bo)& Bu );
373
+ Abo0 = Bo ^((~Bu)& Ba );
374
+ Agu0 = Bu ^((~Ba)& Be );
375
+
376
+ Bi = ROL32((Aka0^Da0), 1);
377
+ Bo = ROL32((Ame0^De0), 22);
378
+ Bu = ROL32((Asi0^Di0), 30);
379
+ Ba = ROL32((Abo1^Do1), 14);
380
+ Be = ROL32((Agu1^Du1), 10);
381
+ Aka0 = Ba ^((~Be)& Bi );
382
+ Ame0 = Be ^((~Bi)& Bo );
383
+ Asi0 = Bi ^((~Bo)& Bu );
384
+ Abo1 = Bo ^((~Bu)& Ba );
385
+ Agu1 = Bu ^((~Ba)& Be );
386
+
387
+ Bu = ROL32((Asa0^Da0), 9);
388
+ Ba = ROL32((Abe1^De1), 1);
389
+ Be = ROL32((Agi0^Di0), 3);
390
+ Bi = ROL32((Ako1^Do1), 13);
391
+ Bo = ROL32((Amu0^Du0), 4);
392
+ Asa0 = Ba ^((~Be)& Bi );
393
+ Abe1 = Be ^((~Bi)& Bo );
394
+ Agi0 = Bi ^((~Bo)& Bu );
395
+ Ako1 = Bo ^((~Bu)& Ba );
396
+ Amu0 = Bu ^((~Ba)& Be );
397
+
398
+ Bu = ROL32((Asa1^Da1), 9);
399
+ Ba = (Abe0^De0);
400
+ Be = ROL32((Agi1^Di1), 3);
401
+ Bi = ROL32((Ako0^Do0), 12);
402
+ Bo = ROL32((Amu1^Du1), 4);
403
+ Asa1 = Ba ^((~Be)& Bi );
404
+ Abe0 = Be ^((~Bi)& Bo );
405
+ Agi1 = Bi ^((~Bo)& Bu );
406
+ Ako0 = Bo ^((~Bu)& Ba );
407
+ Amu1 = Bu ^((~Ba)& Be );
408
+
409
+ Be = ROL32((Aga0^Da0), 18);
410
+ Bi = ROL32((Ake0^De0), 5);
411
+ Bo = ROL32((Ami1^Di1), 8);
412
+ Bu = ROL32((Aso0^Do0), 28);
413
+ Ba = ROL32((Abu1^Du1), 14);
414
+ Aga0 = Ba ^((~Be)& Bi );
415
+ Ake0 = Be ^((~Bi)& Bo );
416
+ Ami1 = Bi ^((~Bo)& Bu );
417
+ Aso0 = Bo ^((~Bu)& Ba );
418
+ Abu1 = Bu ^((~Ba)& Be );
419
+
420
+ Be = ROL32((Aga1^Da1), 18);
421
+ Bi = ROL32((Ake1^De1), 5);
422
+ Bo = ROL32((Ami0^Di0), 7);
423
+ Bu = ROL32((Aso1^Do1), 28);
424
+ Ba = ROL32((Abu0^Du0), 13);
425
+ Aga1 = Ba ^((~Be)& Bi );
426
+ Ake1 = Be ^((~Bi)& Bo );
427
+ Ami0 = Bi ^((~Bo)& Bu );
428
+ Aso1 = Bo ^((~Bu)& Ba );
429
+ Abu0 = Bu ^((~Ba)& Be );
430
+
431
+ Bo = ROL32((Ama1^Da1), 21);
432
+ Bu = ROL32((Ase0^De0), 1);
433
+ Ba = ROL32((Abi0^Di0), 31);
434
+ Be = ROL32((Ago1^Do1), 28);
435
+ Bi = ROL32((Aku1^Du1), 20);
436
+ Ama1 = Ba ^((~Be)& Bi );
437
+ Ase0 = Be ^((~Bi)& Bo );
438
+ Abi0 = Bi ^((~Bo)& Bu );
439
+ Ago1 = Bo ^((~Bu)& Ba );
440
+ Aku1 = Bu ^((~Ba)& Be );
441
+
442
+ Bo = ROL32((Ama0^Da0), 20);
443
+ Bu = ROL32((Ase1^De1), 1);
444
+ Ba = ROL32((Abi1^Di1), 31);
445
+ Be = ROL32((Ago0^Do0), 27);
446
+ Bi = ROL32((Aku0^Du0), 19);
447
+ Ama0 = Ba ^((~Be)& Bi );
448
+ Ase1 = Be ^((~Bi)& Bo );
449
+ Abi1 = Bi ^((~Bo)& Bu );
450
+ Ago0 = Bo ^((~Bu)& Ba );
451
+ Aku0 = Bu ^((~Ba)& Be );
452
+
453
+ KeccakAtoD_round1();
454
+
455
+ Ba = (Aba0^Da0);
456
+ Be = ROL32((Ame1^De0), 22);
457
+ Bi = ROL32((Agi1^Di1), 22);
458
+ Bo = ROL32((Aso1^Do1), 11);
459
+ Bu = ROL32((Aku1^Du0), 7);
460
+ Aba0 = Ba ^((~Be)& Bi );
461
+ Aba0 ^= *(pRoundConstants++);
462
+ Ame1 = Be ^((~Bi)& Bo );
463
+ Agi1 = Bi ^((~Bo)& Bu );
464
+ Aso1 = Bo ^((~Bu)& Ba );
465
+ Aku1 = Bu ^((~Ba)& Be );
466
+
467
+ Ba = (Aba1^Da1);
468
+ Be = ROL32((Ame0^De1), 22);
469
+ Bi = ROL32((Agi0^Di0), 21);
470
+ Bo = ROL32((Aso0^Do0), 10);
471
+ Bu = ROL32((Aku0^Du1), 7);
472
+ Aba1 = Ba ^((~Be)& Bi );
473
+ Aba1 ^= *(pRoundConstants++);
474
+ Ame0 = Be ^((~Bi)& Bo );
475
+ Agi0 = Bi ^((~Bo)& Bu );
476
+ Aso0 = Bo ^((~Bu)& Ba );
477
+ Aku0 = Bu ^((~Ba)& Be );
478
+
479
+ Bi = ROL32((Asa1^Da1), 2);
480
+ Bo = ROL32((Ake1^De1), 23);
481
+ Bu = ROL32((Abi1^Di1), 31);
482
+ Ba = ROL32((Amo1^Do0), 14);
483
+ Be = ROL32((Agu0^Du0), 10);
484
+ Asa1 = Ba ^((~Be)& Bi );
485
+ Ake1 = Be ^((~Bi)& Bo );
486
+ Abi1 = Bi ^((~Bo)& Bu );
487
+ Amo1 = Bo ^((~Bu)& Ba );
488
+ Agu0 = Bu ^((~Ba)& Be );
489
+
490
+ Bi = ROL32((Asa0^Da0), 1);
491
+ Bo = ROL32((Ake0^De0), 22);
492
+ Bu = ROL32((Abi0^Di0), 30);
493
+ Ba = ROL32((Amo0^Do1), 14);
494
+ Be = ROL32((Agu1^Du1), 10);
495
+ Asa0 = Ba ^((~Be)& Bi );
496
+ Ake0 = Be ^((~Bi)& Bo );
497
+ Abi0 = Bi ^((~Bo)& Bu );
498
+ Amo0 = Bo ^((~Bu)& Ba );
499
+ Agu1 = Bu ^((~Ba)& Be );
500
+
501
+ Bu = ROL32((Ama1^Da0), 9);
502
+ Ba = ROL32((Age1^De1), 1);
503
+ Be = ROL32((Asi1^Di0), 3);
504
+ Bi = ROL32((Ako0^Do1), 13);
505
+ Bo = ROL32((Abu1^Du0), 4);
506
+ Ama1 = Ba ^((~Be)& Bi );
507
+ Age1 = Be ^((~Bi)& Bo );
508
+ Asi1 = Bi ^((~Bo)& Bu );
509
+ Ako0 = Bo ^((~Bu)& Ba );
510
+ Abu1 = Bu ^((~Ba)& Be );
511
+
512
+ Bu = ROL32((Ama0^Da1), 9);
513
+ Ba = (Age0^De0);
514
+ Be = ROL32((Asi0^Di1), 3);
515
+ Bi = ROL32((Ako1^Do0), 12);
516
+ Bo = ROL32((Abu0^Du1), 4);
517
+ Ama0 = Ba ^((~Be)& Bi );
518
+ Age0 = Be ^((~Bi)& Bo );
519
+ Asi0 = Bi ^((~Bo)& Bu );
520
+ Ako1 = Bo ^((~Bu)& Ba );
521
+ Abu0 = Bu ^((~Ba)& Be );
522
+
523
+ Be = ROL32((Aka1^Da0), 18);
524
+ Bi = ROL32((Abe1^De0), 5);
525
+ Bo = ROL32((Ami0^Di1), 8);
526
+ Bu = ROL32((Ago1^Do0), 28);
527
+ Ba = ROL32((Asu1^Du1), 14);
528
+ Aka1 = Ba ^((~Be)& Bi );
529
+ Abe1 = Be ^((~Bi)& Bo );
530
+ Ami0 = Bi ^((~Bo)& Bu );
531
+ Ago1 = Bo ^((~Bu)& Ba );
532
+ Asu1 = Bu ^((~Ba)& Be );
533
+
534
+ Be = ROL32((Aka0^Da1), 18);
535
+ Bi = ROL32((Abe0^De1), 5);
536
+ Bo = ROL32((Ami1^Di0), 7);
537
+ Bu = ROL32((Ago0^Do1), 28);
538
+ Ba = ROL32((Asu0^Du0), 13);
539
+ Aka0 = Ba ^((~Be)& Bi );
540
+ Abe0 = Be ^((~Bi)& Bo );
541
+ Ami1 = Bi ^((~Bo)& Bu );
542
+ Ago0 = Bo ^((~Bu)& Ba );
543
+ Asu0 = Bu ^((~Ba)& Be );
544
+
545
+ Bo = ROL32((Aga1^Da1), 21);
546
+ Bu = ROL32((Ase0^De0), 1);
547
+ Ba = ROL32((Aki1^Di0), 31);
548
+ Be = ROL32((Abo1^Do1), 28);
549
+ Bi = ROL32((Amu1^Du1), 20);
550
+ Aga1 = Ba ^((~Be)& Bi );
551
+ Ase0 = Be ^((~Bi)& Bo );
552
+ Aki1 = Bi ^((~Bo)& Bu );
553
+ Abo1 = Bo ^((~Bu)& Ba );
554
+ Amu1 = Bu ^((~Ba)& Be );
555
+
556
+ Bo = ROL32((Aga0^Da0), 20);
557
+ Bu = ROL32((Ase1^De1), 1);
558
+ Ba = ROL32((Aki0^Di1), 31);
559
+ Be = ROL32((Abo0^Do0), 27);
560
+ Bi = ROL32((Amu0^Du0), 19);
561
+ Aga0 = Ba ^((~Be)& Bi );
562
+ Ase1 = Be ^((~Bi)& Bo );
563
+ Aki0 = Bi ^((~Bo)& Bu );
564
+ Abo0 = Bo ^((~Bu)& Ba );
565
+ Amu0 = Bu ^((~Ba)& Be );
566
+
567
+ KeccakAtoD_round2();
568
+
569
+ Ba = (Aba0^Da0);
570
+ Be = ROL32((Ake1^De0), 22);
571
+ Bi = ROL32((Asi0^Di1), 22);
572
+ Bo = ROL32((Ago0^Do1), 11);
573
+ Bu = ROL32((Amu1^Du0), 7);
574
+ Aba0 = Ba ^((~Be)& Bi );
575
+ Aba0 ^= *(pRoundConstants++);
576
+ Ake1 = Be ^((~Bi)& Bo );
577
+ Asi0 = Bi ^((~Bo)& Bu );
578
+ Ago0 = Bo ^((~Bu)& Ba );
579
+ Amu1 = Bu ^((~Ba)& Be );
580
+
581
+ Ba = (Aba1^Da1);
582
+ Be = ROL32((Ake0^De1), 22);
583
+ Bi = ROL32((Asi1^Di0), 21);
584
+ Bo = ROL32((Ago1^Do0), 10);
585
+ Bu = ROL32((Amu0^Du1), 7);
586
+ Aba1 = Ba ^((~Be)& Bi );
587
+ Aba1 ^= *(pRoundConstants++);
588
+ Ake0 = Be ^((~Bi)& Bo );
589
+ Asi1 = Bi ^((~Bo)& Bu );
590
+ Ago1 = Bo ^((~Bu)& Ba );
591
+ Amu0 = Bu ^((~Ba)& Be );
592
+
593
+ Bi = ROL32((Ama0^Da1), 2);
594
+ Bo = ROL32((Abe0^De1), 23);
595
+ Bu = ROL32((Aki0^Di1), 31);
596
+ Ba = ROL32((Aso1^Do0), 14);
597
+ Be = ROL32((Agu0^Du0), 10);
598
+ Ama0 = Ba ^((~Be)& Bi );
599
+ Abe0 = Be ^((~Bi)& Bo );
600
+ Aki0 = Bi ^((~Bo)& Bu );
601
+ Aso1 = Bo ^((~Bu)& Ba );
602
+ Agu0 = Bu ^((~Ba)& Be );
603
+
604
+ Bi = ROL32((Ama1^Da0), 1);
605
+ Bo = ROL32((Abe1^De0), 22);
606
+ Bu = ROL32((Aki1^Di0), 30);
607
+ Ba = ROL32((Aso0^Do1), 14);
608
+ Be = ROL32((Agu1^Du1), 10);
609
+ Ama1 = Ba ^((~Be)& Bi );
610
+ Abe1 = Be ^((~Bi)& Bo );
611
+ Aki1 = Bi ^((~Bo)& Bu );
612
+ Aso0 = Bo ^((~Bu)& Ba );
613
+ Agu1 = Bu ^((~Ba)& Be );
614
+
615
+ Bu = ROL32((Aga1^Da0), 9);
616
+ Ba = ROL32((Ame0^De1), 1);
617
+ Be = ROL32((Abi1^Di0), 3);
618
+ Bi = ROL32((Ako1^Do1), 13);
619
+ Bo = ROL32((Asu1^Du0), 4);
620
+ Aga1 = Ba ^((~Be)& Bi );
621
+ Ame0 = Be ^((~Bi)& Bo );
622
+ Abi1 = Bi ^((~Bo)& Bu );
623
+ Ako1 = Bo ^((~Bu)& Ba );
624
+ Asu1 = Bu ^((~Ba)& Be );
625
+
626
+ Bu = ROL32((Aga0^Da1), 9);
627
+ Ba = (Ame1^De0);
628
+ Be = ROL32((Abi0^Di1), 3);
629
+ Bi = ROL32((Ako0^Do0), 12);
630
+ Bo = ROL32((Asu0^Du1), 4);
631
+ Aga0 = Ba ^((~Be)& Bi );
632
+ Ame1 = Be ^((~Bi)& Bo );
633
+ Abi0 = Bi ^((~Bo)& Bu );
634
+ Ako0 = Bo ^((~Bu)& Ba );
635
+ Asu0 = Bu ^((~Ba)& Be );
636
+
637
+ Be = ROL32((Asa1^Da0), 18);
638
+ Bi = ROL32((Age1^De0), 5);
639
+ Bo = ROL32((Ami1^Di1), 8);
640
+ Bu = ROL32((Abo1^Do0), 28);
641
+ Ba = ROL32((Aku0^Du1), 14);
642
+ Asa1 = Ba ^((~Be)& Bi );
643
+ Age1 = Be ^((~Bi)& Bo );
644
+ Ami1 = Bi ^((~Bo)& Bu );
645
+ Abo1 = Bo ^((~Bu)& Ba );
646
+ Aku0 = Bu ^((~Ba)& Be );
647
+
648
+ Be = ROL32((Asa0^Da1), 18);
649
+ Bi = ROL32((Age0^De1), 5);
650
+ Bo = ROL32((Ami0^Di0), 7);
651
+ Bu = ROL32((Abo0^Do1), 28);
652
+ Ba = ROL32((Aku1^Du0), 13);
653
+ Asa0 = Ba ^((~Be)& Bi );
654
+ Age0 = Be ^((~Bi)& Bo );
655
+ Ami0 = Bi ^((~Bo)& Bu );
656
+ Abo0 = Bo ^((~Bu)& Ba );
657
+ Aku1 = Bu ^((~Ba)& Be );
658
+
659
+ Bo = ROL32((Aka0^Da1), 21);
660
+ Bu = ROL32((Ase0^De0), 1);
661
+ Ba = ROL32((Agi1^Di0), 31);
662
+ Be = ROL32((Amo0^Do1), 28);
663
+ Bi = ROL32((Abu0^Du1), 20);
664
+ Aka0 = Ba ^((~Be)& Bi );
665
+ Ase0 = Be ^((~Bi)& Bo );
666
+ Agi1 = Bi ^((~Bo)& Bu );
667
+ Amo0 = Bo ^((~Bu)& Ba );
668
+ Abu0 = Bu ^((~Ba)& Be );
669
+
670
+ Bo = ROL32((Aka1^Da0), 20);
671
+ Bu = ROL32((Ase1^De1), 1);
672
+ Ba = ROL32((Agi0^Di1), 31);
673
+ Be = ROL32((Amo1^Do0), 27);
674
+ Bi = ROL32((Abu1^Du0), 19);
675
+ Aka1 = Ba ^((~Be)& Bi );
676
+ Ase1 = Be ^((~Bi)& Bo );
677
+ Agi0 = Bi ^((~Bo)& Bu );
678
+ Amo1 = Bo ^((~Bu)& Ba );
679
+ Abu1 = Bu ^((~Ba)& Be );
680
+
681
+ KeccakAtoD_round3();
682
+
683
+ Ba = (Aba0^Da0);
684
+ Be = ROL32((Abe0^De0), 22);
685
+ Bi = ROL32((Abi0^Di1), 22);
686
+ Bo = ROL32((Abo0^Do1), 11);
687
+ Bu = ROL32((Abu0^Du0), 7);
688
+ Aba0 = Ba ^((~Be)& Bi );
689
+ Aba0 ^= *(pRoundConstants++);
690
+ Abe0 = Be ^((~Bi)& Bo );
691
+ Abi0 = Bi ^((~Bo)& Bu );
692
+ Abo0 = Bo ^((~Bu)& Ba );
693
+ Abu0 = Bu ^((~Ba)& Be );
694
+
695
+ Ba = (Aba1^Da1);
696
+ Be = ROL32((Abe1^De1), 22);
697
+ Bi = ROL32((Abi1^Di0), 21);
698
+ Bo = ROL32((Abo1^Do0), 10);
699
+ Bu = ROL32((Abu1^Du1), 7);
700
+ Aba1 = Ba ^((~Be)& Bi );
701
+ Aba1 ^= *(pRoundConstants++);
702
+ Abe1 = Be ^((~Bi)& Bo );
703
+ Abi1 = Bi ^((~Bo)& Bu );
704
+ Abo1 = Bo ^((~Bu)& Ba );
705
+ Abu1 = Bu ^((~Ba)& Be );
706
+
707
+ Bi = ROL32((Aga0^Da1), 2);
708
+ Bo = ROL32((Age0^De1), 23);
709
+ Bu = ROL32((Agi0^Di1), 31);
710
+ Ba = ROL32((Ago0^Do0), 14);
711
+ Be = ROL32((Agu0^Du0), 10);
712
+ Aga0 = Ba ^((~Be)& Bi );
713
+ Age0 = Be ^((~Bi)& Bo );
714
+ Agi0 = Bi ^((~Bo)& Bu );
715
+ Ago0 = Bo ^((~Bu)& Ba );
716
+ Agu0 = Bu ^((~Ba)& Be );
717
+
718
+ Bi = ROL32((Aga1^Da0), 1);
719
+ Bo = ROL32((Age1^De0), 22);
720
+ Bu = ROL32((Agi1^Di0), 30);
721
+ Ba = ROL32((Ago1^Do1), 14);
722
+ Be = ROL32((Agu1^Du1), 10);
723
+ Aga1 = Ba ^((~Be)& Bi );
724
+ Age1 = Be ^((~Bi)& Bo );
725
+ Agi1 = Bi ^((~Bo)& Bu );
726
+ Ago1 = Bo ^((~Bu)& Ba );
727
+ Agu1 = Bu ^((~Ba)& Be );
728
+
729
+ Bu = ROL32((Aka0^Da0), 9);
730
+ Ba = ROL32((Ake0^De1), 1);
731
+ Be = ROL32((Aki0^Di0), 3);
732
+ Bi = ROL32((Ako0^Do1), 13);
733
+ Bo = ROL32((Aku0^Du0), 4);
734
+ Aka0 = Ba ^((~Be)& Bi );
735
+ Ake0 = Be ^((~Bi)& Bo );
736
+ Aki0 = Bi ^((~Bo)& Bu );
737
+ Ako0 = Bo ^((~Bu)& Ba );
738
+ Aku0 = Bu ^((~Ba)& Be );
739
+
740
+ Bu = ROL32((Aka1^Da1), 9);
741
+ Ba = (Ake1^De0);
742
+ Be = ROL32((Aki1^Di1), 3);
743
+ Bi = ROL32((Ako1^Do0), 12);
744
+ Bo = ROL32((Aku1^Du1), 4);
745
+ Aka1 = Ba ^((~Be)& Bi );
746
+ Ake1 = Be ^((~Bi)& Bo );
747
+ Aki1 = Bi ^((~Bo)& Bu );
748
+ Ako1 = Bo ^((~Bu)& Ba );
749
+ Aku1 = Bu ^((~Ba)& Be );
750
+
751
+ Be = ROL32((Ama0^Da0), 18);
752
+ Bi = ROL32((Ame0^De0), 5);
753
+ Bo = ROL32((Ami0^Di1), 8);
754
+ Bu = ROL32((Amo0^Do0), 28);
755
+ Ba = ROL32((Amu0^Du1), 14);
756
+ Ama0 = Ba ^((~Be)& Bi );
757
+ Ame0 = Be ^((~Bi)& Bo );
758
+ Ami0 = Bi ^((~Bo)& Bu );
759
+ Amo0 = Bo ^((~Bu)& Ba );
760
+ Amu0 = Bu ^((~Ba)& Be );
761
+
762
+ Be = ROL32((Ama1^Da1), 18);
763
+ Bi = ROL32((Ame1^De1), 5);
764
+ Bo = ROL32((Ami1^Di0), 7);
765
+ Bu = ROL32((Amo1^Do1), 28);
766
+ Ba = ROL32((Amu1^Du0), 13);
767
+ Ama1 = Ba ^((~Be)& Bi );
768
+ Ame1 = Be ^((~Bi)& Bo );
769
+ Ami1 = Bi ^((~Bo)& Bu );
770
+ Amo1 = Bo ^((~Bu)& Ba );
771
+ Amu1 = Bu ^((~Ba)& Be );
772
+
773
+ Bo = ROL32((Asa0^Da1), 21);
774
+ Bu = ROL32((Ase0^De0), 1);
775
+ Ba = ROL32((Asi0^Di0), 31);
776
+ Be = ROL32((Aso0^Do1), 28);
777
+ Bi = ROL32((Asu0^Du1), 20);
778
+ Asa0 = Ba ^((~Be)& Bi );
779
+ Ase0 = Be ^((~Bi)& Bo );
780
+ Asi0 = Bi ^((~Bo)& Bu );
781
+ Aso0 = Bo ^((~Bu)& Ba );
782
+ Asu0 = Bu ^((~Ba)& Be );
783
+
784
+ Bo = ROL32((Asa1^Da0), 20);
785
+ Bu = ROL32((Ase1^De1), 1);
786
+ Ba = ROL32((Asi1^Di1), 31);
787
+ Be = ROL32((Aso1^Do0), 27);
788
+ Bi = ROL32((Asu1^Du0), 19);
789
+ Asa1 = Ba ^((~Be)& Bi );
790
+ Ase1 = Be ^((~Bi)& Bo );
791
+ Asi1 = Bi ^((~Bo)& Bu );
792
+ Aso1 = Bo ^((~Bu)& Ba );
793
+ Asu1 = Bu ^((~Ba)& Be );
794
+ }
795
+ while ( *pRoundConstants != 0xFF );
796
+
797
+ #undef Aba0
798
+ #undef Aba1
799
+ #undef Abe0
800
+ #undef Abe1
801
+ #undef Abi0
802
+ #undef Abi1
803
+ #undef Abo0
804
+ #undef Abo1
805
+ #undef Abu0
806
+ #undef Abu1
807
+ #undef Aga0
808
+ #undef Aga1
809
+ #undef Age0
810
+ #undef Age1
811
+ #undef Agi0
812
+ #undef Agi1
813
+ #undef Ago0
814
+ #undef Ago1
815
+ #undef Agu0
816
+ #undef Agu1
817
+ #undef Aka0
818
+ #undef Aka1
819
+ #undef Ake0
820
+ #undef Ake1
821
+ #undef Aki0
822
+ #undef Aki1
823
+ #undef Ako0
824
+ #undef Ako1
825
+ #undef Aku0
826
+ #undef Aku1
827
+ #undef Ama0
828
+ #undef Ama1
829
+ #undef Ame0
830
+ #undef Ame1
831
+ #undef Ami0
832
+ #undef Ami1
833
+ #undef Amo0
834
+ #undef Amo1
835
+ #undef Amu0
836
+ #undef Amu1
837
+ #undef Asa0
838
+ #undef Asa1
839
+ #undef Ase0
840
+ #undef Ase1
841
+ #undef Asi0
842
+ #undef Asi1
843
+ #undef Aso0
844
+ #undef Aso1
845
+ #undef Asu0
846
+ #undef Asu1
847
+ }
848
+
849
+ }