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,673 @@
1
+ /*
2
+ The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
3
+ Michaël Peeters and Gilles Van Assche. For more information, feedback or
4
+ questions, please refer to our website: http://keccak.noekeon.org/
5
+
6
+ Implementation by Ronny Van Keer,
7
+ hereby denoted as "the implementer".
8
+
9
+ To the extent possible under law, the implementer has waived all copyright
10
+ and related or neighboring rights to the source code in this file.
11
+ http://creativecommons.org/publicdomain/zero/1.0/
12
+ */
13
+
14
+ // WARNING: This implementation assumes a little-endian platform. Support for big-endinanness is not yet implemented.
15
+
16
+ #include <string.h>
17
+ #include "Keccak-simple-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] =
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
+ };
137
+
138
+ void KeccakF( UINT32 *state, const UINT32 *in, int laneCount )
139
+ {
140
+
141
+ // Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002
142
+ {
143
+ const UINT32 * pI = (const UINT32 *)in;
144
+ UINT32 * pS = state;
145
+ UINT32 t, x0, x1;
146
+ int i;
147
+ for (i = laneCount-1; i >= 0; --i)
148
+ {
149
+ x0 = *(pI++);
150
+ t = (x0 ^ (x0 >> 1)) & 0x22222222UL; x0 = x0 ^ t ^ (t << 1);
151
+ t = (x0 ^ (x0 >> 2)) & 0x0C0C0C0CUL; x0 = x0 ^ t ^ (t << 2);
152
+ t = (x0 ^ (x0 >> 4)) & 0x00F000F0UL; x0 = x0 ^ t ^ (t << 4);
153
+ t = (x0 ^ (x0 >> 8)) & 0x0000FF00UL; x0 = x0 ^ t ^ (t << 8);
154
+ x1 = *(pI++);
155
+ t = (x1 ^ (x1 >> 1)) & 0x22222222UL; x1 = x1 ^ t ^ (t << 1);
156
+ t = (x1 ^ (x1 >> 2)) & 0x0C0C0C0CUL; x1 = x1 ^ t ^ (t << 2);
157
+ t = (x1 ^ (x1 >> 4)) & 0x00F000F0UL; x1 = x1 ^ t ^ (t << 4);
158
+ t = (x1 ^ (x1 >> 8)) & 0x0000FF00UL; x1 = x1 ^ t ^ (t << 8);
159
+ *(pS++) ^= (x0 & 0x0000FFFF) | (x1 << 16);
160
+ *(pS++) ^= (x0 >> 16) | (x1 & 0xFFFF0000);
161
+ }
162
+ }
163
+
164
+ {
165
+ UINT32 Aba0, Abe0, Abi0, Abo0, Abu0;
166
+ UINT32 Aba1, Abe1, Abi1, Abo1, Abu1;
167
+ UINT32 Aga0, Age0, Agi0, Ago0, Agu0;
168
+ UINT32 Aga1, Age1, Agi1, Ago1, Agu1;
169
+ UINT32 Aka0, Ake0, Aki0, Ako0, Aku0;
170
+ UINT32 Aka1, Ake1, Aki1, Ako1, Aku1;
171
+ UINT32 Ama0, Ame0, Ami0, Amo0, Amu0;
172
+ UINT32 Ama1, Ame1, Ami1, Amo1, Amu1;
173
+ UINT32 Asa0, Ase0, Asi0, Aso0, Asu0;
174
+ UINT32 Asa1, Ase1, Asi1, Aso1, Asu1;
175
+ UINT32 BCa0, BCe0, BCi0, BCo0, BCu0;
176
+ UINT32 BCa1, BCe1, BCi1, BCo1, BCu1;
177
+ UINT32 Da0, De0, Di0, Do0, Du0;
178
+ UINT32 Da1, De1, Di1, Do1, Du1;
179
+ UINT32 Eba0, Ebe0, Ebi0, Ebo0, Ebu0;
180
+ UINT32 Eba1, Ebe1, Ebi1, Ebo1, Ebu1;
181
+ UINT32 Ega0, Ege0, Egi0, Ego0, Egu0;
182
+ UINT32 Ega1, Ege1, Egi1, Ego1, Egu1;
183
+ UINT32 Eka0, Eke0, Eki0, Eko0, Eku0;
184
+ UINT32 Eka1, Eke1, Eki1, Eko1, Eku1;
185
+ UINT32 Ema0, Eme0, Emi0, Emo0, Emu0;
186
+ UINT32 Ema1, Eme1, Emi1, Emo1, Emu1;
187
+ UINT32 Esa0, Ese0, Esi0, Eso0, Esu0;
188
+ UINT32 Esa1, Ese1, Esi1, Eso1, Esu1;
189
+ #define round laneCount
190
+
191
+ //copyFromState(A, state)
192
+ Aba0 = state[ 0];
193
+ Aba1 = state[ 1];
194
+ Abe0 = state[ 2];
195
+ Abe1 = state[ 3];
196
+ Abi0 = state[ 4];
197
+ Abi1 = state[ 5];
198
+ Abo0 = state[ 6];
199
+ Abo1 = state[ 7];
200
+ Abu0 = state[ 8];
201
+ Abu1 = state[ 9];
202
+ Aga0 = state[10];
203
+ Aga1 = state[11];
204
+ Age0 = state[12];
205
+ Age1 = state[13];
206
+ Agi0 = state[14];
207
+ Agi1 = state[15];
208
+ Ago0 = state[16];
209
+ Ago1 = state[17];
210
+ Agu0 = state[18];
211
+ Agu1 = state[19];
212
+ Aka0 = state[20];
213
+ Aka1 = state[21];
214
+ Ake0 = state[22];
215
+ Ake1 = state[23];
216
+ Aki0 = state[24];
217
+ Aki1 = state[25];
218
+ Ako0 = state[26];
219
+ Ako1 = state[27];
220
+ Aku0 = state[28];
221
+ Aku1 = state[29];
222
+ Ama0 = state[30];
223
+ Ama1 = state[31];
224
+ Ame0 = state[32];
225
+ Ame1 = state[33];
226
+ Ami0 = state[34];
227
+ Ami1 = state[35];
228
+ Amo0 = state[36];
229
+ Amo1 = state[37];
230
+ Amu0 = state[38];
231
+ Amu1 = state[39];
232
+ Asa0 = state[40];
233
+ Asa1 = state[41];
234
+ Ase0 = state[42];
235
+ Ase1 = state[43];
236
+ Asi0 = state[44];
237
+ Asi1 = state[45];
238
+ Aso0 = state[46];
239
+ Aso1 = state[47];
240
+ Asu0 = state[48];
241
+ Asu1 = state[49];
242
+
243
+ for( round = 0; round < cKeccakNumberOfRounds; round += 2 )
244
+ {
245
+ // prepareTheta
246
+ BCa0 = Aba0^Aga0^Aka0^Ama0^Asa0;
247
+ BCa1 = Aba1^Aga1^Aka1^Ama1^Asa1;
248
+ BCe0 = Abe0^Age0^Ake0^Ame0^Ase0;
249
+ BCe1 = Abe1^Age1^Ake1^Ame1^Ase1;
250
+ BCi0 = Abi0^Agi0^Aki0^Ami0^Asi0;
251
+ BCi1 = Abi1^Agi1^Aki1^Ami1^Asi1;
252
+ BCo0 = Abo0^Ago0^Ako0^Amo0^Aso0;
253
+ BCo1 = Abo1^Ago1^Ako1^Amo1^Aso1;
254
+ BCu0 = Abu0^Agu0^Aku0^Amu0^Asu0;
255
+ BCu1 = Abu1^Agu1^Aku1^Amu1^Asu1;
256
+
257
+ //thetaRhoPiChiIota(round , A, E)
258
+ Da0 = BCu0^ROL32(BCe1, 1);
259
+ Da1 = BCu1^BCe0;
260
+ De0 = BCa0^ROL32(BCi1, 1);
261
+ De1 = BCa1^BCi0;
262
+ Di0 = BCe0^ROL32(BCo1, 1);
263
+ Di1 = BCe1^BCo0;
264
+ Do0 = BCi0^ROL32(BCu1, 1);
265
+ Do1 = BCi1^BCu0;
266
+ Du0 = BCo0^ROL32(BCa1, 1);
267
+ Du1 = BCo1^BCa0;
268
+
269
+ Aba0 ^= Da0;
270
+ BCa0 = Aba0;
271
+ Age0 ^= De0;
272
+ BCe0 = ROL32(Age0, 22);
273
+ Aki1 ^= Di1;
274
+ BCi0 = ROL32(Aki1, 22);
275
+ Amo1 ^= Do1;
276
+ BCo0 = ROL32(Amo1, 11);
277
+ Asu0 ^= Du0;
278
+ BCu0 = ROL32(Asu0, 7);
279
+ Eba0 = BCa0 ^((~BCe0)& BCi0 );
280
+ Eba0 ^= KeccakF1600RoundConstants_int2[round*2+0];
281
+ Ebe0 = BCe0 ^((~BCi0)& BCo0 );
282
+ Ebi0 = BCi0 ^((~BCo0)& BCu0 );
283
+ Ebo0 = BCo0 ^((~BCu0)& BCa0 );
284
+ Ebu0 = BCu0 ^((~BCa0)& BCe0 );
285
+
286
+ Aba1 ^= Da1;
287
+ BCa1 = Aba1;
288
+ Age1 ^= De1;
289
+ BCe1 = ROL32(Age1, 22);
290
+ Aki0 ^= Di0;
291
+ BCi1 = ROL32(Aki0, 21);
292
+ Amo0 ^= Do0;
293
+ BCo1 = ROL32(Amo0, 10);
294
+ Asu1 ^= Du1;
295
+ BCu1 = ROL32(Asu1, 7);
296
+ Eba1 = BCa1 ^((~BCe1)& BCi1 );
297
+ Eba1 ^= KeccakF1600RoundConstants_int2[round*2+1];
298
+ Ebe1 = BCe1 ^((~BCi1)& BCo1 );
299
+ Ebi1 = BCi1 ^((~BCo1)& BCu1 );
300
+ Ebo1 = BCo1 ^((~BCu1)& BCa1 );
301
+ Ebu1 = BCu1 ^((~BCa1)& BCe1 );
302
+
303
+ Abo0 ^= Do0;
304
+ BCa0 = ROL32(Abo0, 14);
305
+ Agu0 ^= Du0;
306
+ BCe0 = ROL32(Agu0, 10);
307
+ Aka1 ^= Da1;
308
+ BCi0 = ROL32(Aka1, 2);
309
+ Ame1 ^= De1;
310
+ BCo0 = ROL32(Ame1, 23);
311
+ Asi1 ^= Di1;
312
+ BCu0 = ROL32(Asi1, 31);
313
+ Ega0 = BCa0 ^((~BCe0)& BCi0 );
314
+ Ege0 = BCe0 ^((~BCi0)& BCo0 );
315
+ Egi0 = BCi0 ^((~BCo0)& BCu0 );
316
+ Ego0 = BCo0 ^((~BCu0)& BCa0 );
317
+ Egu0 = BCu0 ^((~BCa0)& BCe0 );
318
+
319
+ Abo1 ^= Do1;
320
+ BCa1 = ROL32(Abo1, 14);
321
+ Agu1 ^= Du1;
322
+ BCe1 = ROL32(Agu1, 10);
323
+ Aka0 ^= Da0;
324
+ BCi1 = ROL32(Aka0, 1);
325
+ Ame0 ^= De0;
326
+ BCo1 = ROL32(Ame0, 22);
327
+ Asi0 ^= Di0;
328
+ BCu1 = ROL32(Asi0, 30);
329
+ Ega1 = BCa1 ^((~BCe1)& BCi1 );
330
+ Ege1 = BCe1 ^((~BCi1)& BCo1 );
331
+ Egi1 = BCi1 ^((~BCo1)& BCu1 );
332
+ Ego1 = BCo1 ^((~BCu1)& BCa1 );
333
+ Egu1 = BCu1 ^((~BCa1)& BCe1 );
334
+
335
+ Abe1 ^= De1;
336
+ BCa0 = ROL32(Abe1, 1);
337
+ Agi0 ^= Di0;
338
+ BCe0 = ROL32(Agi0, 3);
339
+ Ako1 ^= Do1;
340
+ BCi0 = ROL32(Ako1, 13);
341
+ Amu0 ^= Du0;
342
+ BCo0 = ROL32(Amu0, 4);
343
+ Asa0 ^= Da0;
344
+ BCu0 = ROL32(Asa0, 9);
345
+ Eka0 = BCa0 ^((~BCe0)& BCi0 );
346
+ Eke0 = BCe0 ^((~BCi0)& BCo0 );
347
+ Eki0 = BCi0 ^((~BCo0)& BCu0 );
348
+ Eko0 = BCo0 ^((~BCu0)& BCa0 );
349
+ Eku0 = BCu0 ^((~BCa0)& BCe0 );
350
+
351
+ Abe0 ^= De0;
352
+ BCa1 = Abe0;
353
+ Agi1 ^= Di1;
354
+ BCe1 = ROL32(Agi1, 3);
355
+ Ako0 ^= Do0;
356
+ BCi1 = ROL32(Ako0, 12);
357
+ Amu1 ^= Du1;
358
+ BCo1 = ROL32(Amu1, 4);
359
+ Asa1 ^= Da1;
360
+ BCu1 = ROL32(Asa1, 9);
361
+ Eka1 = BCa1 ^((~BCe1)& BCi1 );
362
+ Eke1 = BCe1 ^((~BCi1)& BCo1 );
363
+ Eki1 = BCi1 ^((~BCo1)& BCu1 );
364
+ Eko1 = BCo1 ^((~BCu1)& BCa1 );
365
+ Eku1 = BCu1 ^((~BCa1)& BCe1 );
366
+
367
+ Abu1 ^= Du1;
368
+ BCa0 = ROL32(Abu1, 14);
369
+ Aga0 ^= Da0;
370
+ BCe0 = ROL32(Aga0, 18);
371
+ Ake0 ^= De0;
372
+ BCi0 = ROL32(Ake0, 5);
373
+ Ami1 ^= Di1;
374
+ BCo0 = ROL32(Ami1, 8);
375
+ Aso0 ^= Do0;
376
+ BCu0 = ROL32(Aso0, 28);
377
+ Ema0 = BCa0 ^((~BCe0)& BCi0 );
378
+ Eme0 = BCe0 ^((~BCi0)& BCo0 );
379
+ Emi0 = BCi0 ^((~BCo0)& BCu0 );
380
+ Emo0 = BCo0 ^((~BCu0)& BCa0 );
381
+ Emu0 = BCu0 ^((~BCa0)& BCe0 );
382
+
383
+ Abu0 ^= Du0;
384
+ BCa1 = ROL32(Abu0, 13);
385
+ Aga1 ^= Da1;
386
+ BCe1 = ROL32(Aga1, 18);
387
+ Ake1 ^= De1;
388
+ BCi1 = ROL32(Ake1, 5);
389
+ Ami0 ^= Di0;
390
+ BCo1 = ROL32(Ami0, 7);
391
+ Aso1 ^= Do1;
392
+ BCu1 = ROL32(Aso1, 28);
393
+ Ema1 = BCa1 ^((~BCe1)& BCi1 );
394
+ Eme1 = BCe1 ^((~BCi1)& BCo1 );
395
+ Emi1 = BCi1 ^((~BCo1)& BCu1 );
396
+ Emo1 = BCo1 ^((~BCu1)& BCa1 );
397
+ Emu1 = BCu1 ^((~BCa1)& BCe1 );
398
+
399
+ Abi0 ^= Di0;
400
+ BCa0 = ROL32(Abi0, 31);
401
+ Ago1 ^= Do1;
402
+ BCe0 = ROL32(Ago1, 28);
403
+ Aku1 ^= Du1;
404
+ BCi0 = ROL32(Aku1, 20);
405
+ Ama1 ^= Da1;
406
+ BCo0 = ROL32(Ama1, 21);
407
+ Ase0 ^= De0;
408
+ BCu0 = ROL32(Ase0, 1);
409
+ Esa0 = BCa0 ^((~BCe0)& BCi0 );
410
+ Ese0 = BCe0 ^((~BCi0)& BCo0 );
411
+ Esi0 = BCi0 ^((~BCo0)& BCu0 );
412
+ Eso0 = BCo0 ^((~BCu0)& BCa0 );
413
+ Esu0 = BCu0 ^((~BCa0)& BCe0 );
414
+
415
+ Abi1 ^= Di1;
416
+ BCa1 = ROL32(Abi1, 31);
417
+ Ago0 ^= Do0;
418
+ BCe1 = ROL32(Ago0, 27);
419
+ Aku0 ^= Du0;
420
+ BCi1 = ROL32(Aku0, 19);
421
+ Ama0 ^= Da0;
422
+ BCo1 = ROL32(Ama0, 20);
423
+ Ase1 ^= De1;
424
+ BCu1 = ROL32(Ase1, 1);
425
+ Esa1 = BCa1 ^((~BCe1)& BCi1 );
426
+ Ese1 = BCe1 ^((~BCi1)& BCo1 );
427
+ Esi1 = BCi1 ^((~BCo1)& BCu1 );
428
+ Eso1 = BCo1 ^((~BCu1)& BCa1 );
429
+ Esu1 = BCu1 ^((~BCa1)& BCe1 );
430
+
431
+ // prepareTheta
432
+ BCa0 = Eba0^Ega0^Eka0^Ema0^Esa0;
433
+ BCa1 = Eba1^Ega1^Eka1^Ema1^Esa1;
434
+ BCe0 = Ebe0^Ege0^Eke0^Eme0^Ese0;
435
+ BCe1 = Ebe1^Ege1^Eke1^Eme1^Ese1;
436
+ BCi0 = Ebi0^Egi0^Eki0^Emi0^Esi0;
437
+ BCi1 = Ebi1^Egi1^Eki1^Emi1^Esi1;
438
+ BCo0 = Ebo0^Ego0^Eko0^Emo0^Eso0;
439
+ BCo1 = Ebo1^Ego1^Eko1^Emo1^Eso1;
440
+ BCu0 = Ebu0^Egu0^Eku0^Emu0^Esu0;
441
+ BCu1 = Ebu1^Egu1^Eku1^Emu1^Esu1;
442
+
443
+ //thetaRhoPiChiIota(round+1, E, A)
444
+ Da0 = BCu0^ROL32(BCe1, 1);
445
+ Da1 = BCu1^BCe0;
446
+ De0 = BCa0^ROL32(BCi1, 1);
447
+ De1 = BCa1^BCi0;
448
+ Di0 = BCe0^ROL32(BCo1, 1);
449
+ Di1 = BCe1^BCo0;
450
+ Do0 = BCi0^ROL32(BCu1, 1);
451
+ Do1 = BCi1^BCu0;
452
+ Du0 = BCo0^ROL32(BCa1, 1);
453
+ Du1 = BCo1^BCa0;
454
+
455
+ Eba0 ^= Da0;
456
+ BCa0 = Eba0;
457
+ Ege0 ^= De0;
458
+ BCe0 = ROL32(Ege0, 22);
459
+ Eki1 ^= Di1;
460
+ BCi0 = ROL32(Eki1, 22);
461
+ Emo1 ^= Do1;
462
+ BCo0 = ROL32(Emo1, 11);
463
+ Esu0 ^= Du0;
464
+ BCu0 = ROL32(Esu0, 7);
465
+ Aba0 = BCa0 ^((~BCe0)& BCi0 );
466
+ Aba0 ^= KeccakF1600RoundConstants_int2[round*2+2];
467
+ Abe0 = BCe0 ^((~BCi0)& BCo0 );
468
+ Abi0 = BCi0 ^((~BCo0)& BCu0 );
469
+ Abo0 = BCo0 ^((~BCu0)& BCa0 );
470
+ Abu0 = BCu0 ^((~BCa0)& BCe0 );
471
+
472
+ Eba1 ^= Da1;
473
+ BCa1 = Eba1;
474
+ Ege1 ^= De1;
475
+ BCe1 = ROL32(Ege1, 22);
476
+ Eki0 ^= Di0;
477
+ BCi1 = ROL32(Eki0, 21);
478
+ Emo0 ^= Do0;
479
+ BCo1 = ROL32(Emo0, 10);
480
+ Esu1 ^= Du1;
481
+ BCu1 = ROL32(Esu1, 7);
482
+ Aba1 = BCa1 ^((~BCe1)& BCi1 );
483
+ Aba1 ^= KeccakF1600RoundConstants_int2[round*2+3];
484
+ Abe1 = BCe1 ^((~BCi1)& BCo1 );
485
+ Abi1 = BCi1 ^((~BCo1)& BCu1 );
486
+ Abo1 = BCo1 ^((~BCu1)& BCa1 );
487
+ Abu1 = BCu1 ^((~BCa1)& BCe1 );
488
+
489
+ Ebo0 ^= Do0;
490
+ BCa0 = ROL32(Ebo0, 14);
491
+ Egu0 ^= Du0;
492
+ BCe0 = ROL32(Egu0, 10);
493
+ Eka1 ^= Da1;
494
+ BCi0 = ROL32(Eka1, 2);
495
+ Eme1 ^= De1;
496
+ BCo0 = ROL32(Eme1, 23);
497
+ Esi1 ^= Di1;
498
+ BCu0 = ROL32(Esi1, 31);
499
+ Aga0 = BCa0 ^((~BCe0)& BCi0 );
500
+ Age0 = BCe0 ^((~BCi0)& BCo0 );
501
+ Agi0 = BCi0 ^((~BCo0)& BCu0 );
502
+ Ago0 = BCo0 ^((~BCu0)& BCa0 );
503
+ Agu0 = BCu0 ^((~BCa0)& BCe0 );
504
+
505
+ Ebo1 ^= Do1;
506
+ BCa1 = ROL32(Ebo1, 14);
507
+ Egu1 ^= Du1;
508
+ BCe1 = ROL32(Egu1, 10);
509
+ Eka0 ^= Da0;
510
+ BCi1 = ROL32(Eka0, 1);
511
+ Eme0 ^= De0;
512
+ BCo1 = ROL32(Eme0, 22);
513
+ Esi0 ^= Di0;
514
+ BCu1 = ROL32(Esi0, 30);
515
+ Aga1 = BCa1 ^((~BCe1)& BCi1 );
516
+ Age1 = BCe1 ^((~BCi1)& BCo1 );
517
+ Agi1 = BCi1 ^((~BCo1)& BCu1 );
518
+ Ago1 = BCo1 ^((~BCu1)& BCa1 );
519
+ Agu1 = BCu1 ^((~BCa1)& BCe1 );
520
+
521
+ Ebe1 ^= De1;
522
+ BCa0 = ROL32(Ebe1, 1);
523
+ Egi0 ^= Di0;
524
+ BCe0 = ROL32(Egi0, 3);
525
+ Eko1 ^= Do1;
526
+ BCi0 = ROL32(Eko1, 13);
527
+ Emu0 ^= Du0;
528
+ BCo0 = ROL32(Emu0, 4);
529
+ Esa0 ^= Da0;
530
+ BCu0 = ROL32(Esa0, 9);
531
+ Aka0 = BCa0 ^((~BCe0)& BCi0 );
532
+ Ake0 = BCe0 ^((~BCi0)& BCo0 );
533
+ Aki0 = BCi0 ^((~BCo0)& BCu0 );
534
+ Ako0 = BCo0 ^((~BCu0)& BCa0 );
535
+ Aku0 = BCu0 ^((~BCa0)& BCe0 );
536
+
537
+ Ebe0 ^= De0;
538
+ BCa1 = Ebe0;
539
+ Egi1 ^= Di1;
540
+ BCe1 = ROL32(Egi1, 3);
541
+ Eko0 ^= Do0;
542
+ BCi1 = ROL32(Eko0, 12);
543
+ Emu1 ^= Du1;
544
+ BCo1 = ROL32(Emu1, 4);
545
+ Esa1 ^= Da1;
546
+ BCu1 = ROL32(Esa1, 9);
547
+ Aka1 = BCa1 ^((~BCe1)& BCi1 );
548
+ Ake1 = BCe1 ^((~BCi1)& BCo1 );
549
+ Aki1 = BCi1 ^((~BCo1)& BCu1 );
550
+ Ako1 = BCo1 ^((~BCu1)& BCa1 );
551
+ Aku1 = BCu1 ^((~BCa1)& BCe1 );
552
+
553
+ Ebu1 ^= Du1;
554
+ BCa0 = ROL32(Ebu1, 14);
555
+ Ega0 ^= Da0;
556
+ BCe0 = ROL32(Ega0, 18);
557
+ Eke0 ^= De0;
558
+ BCi0 = ROL32(Eke0, 5);
559
+ Emi1 ^= Di1;
560
+ BCo0 = ROL32(Emi1, 8);
561
+ Eso0 ^= Do0;
562
+ BCu0 = ROL32(Eso0, 28);
563
+ Ama0 = BCa0 ^((~BCe0)& BCi0 );
564
+ Ame0 = BCe0 ^((~BCi0)& BCo0 );
565
+ Ami0 = BCi0 ^((~BCo0)& BCu0 );
566
+ Amo0 = BCo0 ^((~BCu0)& BCa0 );
567
+ Amu0 = BCu0 ^((~BCa0)& BCe0 );
568
+
569
+ Ebu0 ^= Du0;
570
+ BCa1 = ROL32(Ebu0, 13);
571
+ Ega1 ^= Da1;
572
+ BCe1 = ROL32(Ega1, 18);
573
+ Eke1 ^= De1;
574
+ BCi1 = ROL32(Eke1, 5);
575
+ Emi0 ^= Di0;
576
+ BCo1 = ROL32(Emi0, 7);
577
+ Eso1 ^= Do1;
578
+ BCu1 = ROL32(Eso1, 28);
579
+ Ama1 = BCa1 ^((~BCe1)& BCi1 );
580
+ Ame1 = BCe1 ^((~BCi1)& BCo1 );
581
+ Ami1 = BCi1 ^((~BCo1)& BCu1 );
582
+ Amo1 = BCo1 ^((~BCu1)& BCa1 );
583
+ Amu1 = BCu1 ^((~BCa1)& BCe1 );
584
+
585
+ Ebi0 ^= Di0;
586
+ BCa0 = ROL32(Ebi0, 31);
587
+ Ego1 ^= Do1;
588
+ BCe0 = ROL32(Ego1, 28);
589
+ Eku1 ^= Du1;
590
+ BCi0 = ROL32(Eku1, 20);
591
+ Ema1 ^= Da1;
592
+ BCo0 = ROL32(Ema1, 21);
593
+ Ese0 ^= De0;
594
+ BCu0 = ROL32(Ese0, 1);
595
+ Asa0 = BCa0 ^((~BCe0)& BCi0 );
596
+ Ase0 = BCe0 ^((~BCi0)& BCo0 );
597
+ Asi0 = BCi0 ^((~BCo0)& BCu0 );
598
+ Aso0 = BCo0 ^((~BCu0)& BCa0 );
599
+ Asu0 = BCu0 ^((~BCa0)& BCe0 );
600
+
601
+ Ebi1 ^= Di1;
602
+ BCa1 = ROL32(Ebi1, 31);
603
+ Ego0 ^= Do0;
604
+ BCe1 = ROL32(Ego0, 27);
605
+ Eku0 ^= Du0;
606
+ BCi1 = ROL32(Eku0, 19);
607
+ Ema0 ^= Da0;
608
+ BCo1 = ROL32(Ema0, 20);
609
+ Ese1 ^= De1;
610
+ BCu1 = ROL32(Ese1, 1);
611
+ Asa1 = BCa1 ^((~BCe1)& BCi1 );
612
+ Ase1 = BCe1 ^((~BCi1)& BCo1 );
613
+ Asi1 = BCi1 ^((~BCo1)& BCu1 );
614
+ Aso1 = BCo1 ^((~BCu1)& BCa1 );
615
+ Asu1 = BCu1 ^((~BCa1)& BCe1 );
616
+ }
617
+
618
+ //copyToState(state, A)
619
+ state[ 0] = Aba0;
620
+ state[ 1] = Aba1;
621
+ state[ 2] = Abe0;
622
+ state[ 3] = Abe1;
623
+ state[ 4] = Abi0;
624
+ state[ 5] = Abi1;
625
+ state[ 6] = Abo0;
626
+ state[ 7] = Abo1;
627
+ state[ 8] = Abu0;
628
+ state[ 9] = Abu1;
629
+ state[10] = Aga0;
630
+ state[11] = Aga1;
631
+ state[12] = Age0;
632
+ state[13] = Age1;
633
+ state[14] = Agi0;
634
+ state[15] = Agi1;
635
+ state[16] = Ago0;
636
+ state[17] = Ago1;
637
+ state[18] = Agu0;
638
+ state[19] = Agu1;
639
+ state[20] = Aka0;
640
+ state[21] = Aka1;
641
+ state[22] = Ake0;
642
+ state[23] = Ake1;
643
+ state[24] = Aki0;
644
+ state[25] = Aki1;
645
+ state[26] = Ako0;
646
+ state[27] = Ako1;
647
+ state[28] = Aku0;
648
+ state[29] = Aku1;
649
+ state[30] = Ama0;
650
+ state[31] = Ama1;
651
+ state[32] = Ame0;
652
+ state[33] = Ame1;
653
+ state[34] = Ami0;
654
+ state[35] = Ami1;
655
+ state[36] = Amo0;
656
+ state[37] = Amo1;
657
+ state[38] = Amu0;
658
+ state[39] = Amu1;
659
+ state[40] = Asa0;
660
+ state[41] = Asa1;
661
+ state[42] = Ase0;
662
+ state[43] = Ase1;
663
+ state[44] = Asi0;
664
+ state[45] = Asi1;
665
+ state[46] = Aso0;
666
+ state[47] = Aso1;
667
+ state[48] = Asu0;
668
+ state[49] = Asu1;
669
+
670
+ #undef round
671
+ }
672
+
673
+ }