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,68 @@
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 "KeccakDuplex.h"
16
+ #include "KeccakF-1600-interface.h"
17
+ #ifdef KeccakReference
18
+ #include "displayIntermediateValues.h"
19
+ #endif
20
+
21
+ int InitDuplex(duplexState *state, unsigned int rate, unsigned int capacity)
22
+ {
23
+ if (rate+capacity != 1600)
24
+ return 1;
25
+ if ((rate <= 0) || (rate > 1600))
26
+ return 1;
27
+ KeccakInitialize();
28
+ state->rate = rate;
29
+ state->capacity = capacity;
30
+ state->rho_max = rate-2;
31
+ KeccakInitializeState(state->state);
32
+ return 0;
33
+ }
34
+
35
+ int Duplexing(duplexState *state, const unsigned char *in, unsigned int inBitLen, unsigned char *out, unsigned int outBitLen)
36
+ {
37
+ ALIGN unsigned char block[KeccakPermutationSizeInBytes];
38
+
39
+ if (inBitLen > state->rho_max)
40
+ return 1;
41
+ if ((inBitLen % 8) != 0) {
42
+ unsigned char mask = ~((1 << (inBitLen % 8)) - 1);
43
+ if ((in[inBitLen/8] & mask) != 0)
44
+ return 1; // The bits of the last incomplete byte must be aligned on the LSB
45
+ }
46
+ if (outBitLen > state->rate)
47
+ return 1; // The output length must not be greater than the rate
48
+
49
+ memcpy(block, in, (inBitLen+7)/8);
50
+ memset(block+(inBitLen+7)/8, 0, ((state->rate+63)/64)*8 - (inBitLen+7)/8);
51
+
52
+ block[inBitLen/8] |= 1 << (inBitLen%8);
53
+ block[(state->rate-1)/8] |= 1 << ((state->rate-1) % 8);
54
+
55
+ #ifdef KeccakReference
56
+ displayBytes(1, "Block to be absorbed (after padding)", block, (state->rate+7)/8);
57
+ #endif
58
+ KeccakAbsorb(state->state, block, (state->rate+63)/64);
59
+
60
+ KeccakExtract(state->state, block, (state->rate+63)/64);
61
+ memcpy(out, block, (outBitLen+7)/8);
62
+ if ((outBitLen % 8) != 0) {
63
+ unsigned char mask = (1 << (outBitLen % 8)) - 1;
64
+ out[outBitLen/8] &= mask;
65
+ }
66
+
67
+ return 0;
68
+ }
@@ -0,0 +1,59 @@
1
+ /*
2
+ The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
3
+ Michaël Peeters and Gilles Van Assche. For more information, feedback or
4
+ questions, please refer to our website: http://keccak.noekeon.org/
5
+
6
+ Implementation by the designers,
7
+ hereby denoted as "the implementer".
8
+
9
+ To the extent possible under law, the implementer has waived all copyright
10
+ and related or neighboring rights to the source code in this file.
11
+ http://creativecommons.org/publicdomain/zero/1.0/
12
+ */
13
+
14
+ #ifndef _KeccakDuplex_h_
15
+ #define _KeccakDuplex_h_
16
+
17
+ #define KeccakPermutationSize 1600
18
+ #define KeccakPermutationSizeInBytes (KeccakPermutationSize/8)
19
+
20
+ #if defined(__GNUC__)
21
+ #define ALIGN __attribute__ ((aligned(32)))
22
+ #elif defined(_MSC_VER)
23
+ #define ALIGN __declspec(align(32))
24
+ #else
25
+ #define ALIGN
26
+ #endif
27
+
28
+ ALIGN typedef struct duplexStateStruct {
29
+ ALIGN unsigned char state[KeccakPermutationSizeInBytes];
30
+ unsigned int rate;
31
+ unsigned int capacity;
32
+ unsigned int rho_max;
33
+ } duplexState;
34
+
35
+ /**
36
+ * Function to initialize a duplex object Duplex[Keccak-f[r+c], pad10*1, r].
37
+ * @param state Pointer to the state of the duplex object to be initialized.
38
+ * @param rate The value of the rate r.
39
+ * @param capacity The value of the capacity c.
40
+ * @pre One must have r+c=1600 in this implementation. (The value of the rate is unrestricted.)
41
+ * @return Zero if successful, 1 otherwise.
42
+ */
43
+ int InitDuplex(duplexState *state, unsigned int rate, unsigned int capacity);
44
+ /**
45
+ * Function to make a duplexing call to the duplex object intialized with InitDuplex().
46
+ * @param state Pointer to the state of the duplex object initialized by InitDuplex().
47
+ * @param in Pointer to the input data.
48
+ * When @a inBitLen is not a multiple of 8, the last bits of data must be
49
+ * in the least significant bits of the last byte.
50
+ * @param inBitLen The number of input bits provided in the input data.
51
+ * @param out Pointer to the buffer where to store the output data.
52
+ * @param outBitLen The number of output bits desired.
53
+ * @pre inBitLen ≤ (r-2)
54
+ * @pre outBitLen ≤ r
55
+ * @return Zero if successful, 1 otherwise.
56
+ */
57
+ int Duplexing(duplexState *state, const unsigned char *in, unsigned int inBitLen, unsigned char *out, unsigned int outBitLen);
58
+
59
+ #endif
@@ -0,0 +1,555 @@
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
+ static const UINT32 KeccakF1600RoundConstants_int2[2*24] =
15
+ {
16
+ 0x00000001UL, 0x00000000UL,
17
+ 0x00000000UL, 0x00000089UL,
18
+ 0x00000000UL, 0x8000008bUL,
19
+ 0x00000000UL, 0x80008080UL,
20
+ 0x00000001UL, 0x0000008bUL,
21
+ 0x00000001UL, 0x00008000UL,
22
+ 0x00000001UL, 0x80008088UL,
23
+ 0x00000001UL, 0x80000082UL,
24
+ 0x00000000UL, 0x0000000bUL,
25
+ 0x00000000UL, 0x0000000aUL,
26
+ 0x00000001UL, 0x00008082UL,
27
+ 0x00000000UL, 0x00008003UL,
28
+ 0x00000001UL, 0x0000808bUL,
29
+ 0x00000001UL, 0x8000000bUL,
30
+ 0x00000001UL, 0x8000008aUL,
31
+ 0x00000001UL, 0x80000081UL,
32
+ 0x00000000UL, 0x80000081UL,
33
+ 0x00000000UL, 0x80000008UL,
34
+ 0x00000000UL, 0x00000083UL,
35
+ 0x00000000UL, 0x80008003UL,
36
+ 0x00000001UL, 0x80008088UL,
37
+ 0x00000000UL, 0x80000088UL,
38
+ 0x00000001UL, 0x00008000UL,
39
+ 0x00000000UL, 0x80008082UL
40
+ };
41
+
42
+ #undef rounds
43
+
44
+ #define rounds \
45
+ { \
46
+ UINT32 Da0, De0, Di0, Do0, Du0; \
47
+ UINT32 Da1, De1, Di1, Do1, Du1; \
48
+ UINT32 Ba, Be, Bi, Bo, Bu; \
49
+ UINT32 Aba0, Abe0, Abi0, Abo0, Abu0; \
50
+ UINT32 Aba1, Abe1, Abi1, Abo1, Abu1; \
51
+ UINT32 Aga0, Age0, Agi0, Ago0, Agu0; \
52
+ UINT32 Aga1, Age1, Agi1, Ago1, Agu1; \
53
+ UINT32 Aka0, Ake0, Aki0, Ako0, Aku0; \
54
+ UINT32 Aka1, Ake1, Aki1, Ako1, Aku1; \
55
+ UINT32 Ama0, Ame0, Ami0, Amo0, Amu0; \
56
+ UINT32 Ama1, Ame1, Ami1, Amo1, Amu1; \
57
+ UINT32 Asa0, Ase0, Asi0, Aso0, Asu0; \
58
+ UINT32 Asa1, Ase1, Asi1, Aso1, Asu1; \
59
+ UINT32 Cw, Cx, Cy, Cz; \
60
+ UINT32 Eba0, Ebe0, Ebi0, Ebo0, Ebu0; \
61
+ UINT32 Eba1, Ebe1, Ebi1, Ebo1, Ebu1; \
62
+ UINT32 Ega0, Ege0, Egi0, Ego0, Egu0; \
63
+ UINT32 Ega1, Ege1, Egi1, Ego1, Egu1; \
64
+ UINT32 Eka0, Eke0, Eki0, Eko0, Eku0; \
65
+ UINT32 Eka1, Eke1, Eki1, Eko1, Eku1; \
66
+ UINT32 Ema0, Eme0, Emi0, Emo0, Emu0; \
67
+ UINT32 Ema1, Eme1, Emi1, Emo1, Emu1; \
68
+ UINT32 Esa0, Ese0, Esi0, Eso0, Esu0; \
69
+ UINT32 Esa1, Ese1, Esi1, Eso1, Esu1; \
70
+ const UINT32 * pRoundConstants = KeccakF1600RoundConstants_int2; \
71
+ UINT32 i; \
72
+ \
73
+ copyFromState(A, state) \
74
+ \
75
+ for( i = 12; i != 0; --i ) { \
76
+ Cx = Abu0^Agu0^Aku0^Amu0^Asu0; \
77
+ Du1 = Abe1^Age1^Ake1^Ame1^Ase1; \
78
+ Da0 = Cx^ROL32(Du1, 1); \
79
+ Cz = Abu1^Agu1^Aku1^Amu1^Asu1; \
80
+ Du0 = Abe0^Age0^Ake0^Ame0^Ase0; \
81
+ Da1 = Cz^Du0; \
82
+ \
83
+ Cw = Abi0^Agi0^Aki0^Ami0^Asi0; \
84
+ Do0 = Cw^ROL32(Cz, 1); \
85
+ Cy = Abi1^Agi1^Aki1^Ami1^Asi1; \
86
+ Do1 = Cy^Cx; \
87
+ \
88
+ Cx = Aba0^Aga0^Aka0^Ama0^Asa0; \
89
+ De0 = Cx^ROL32(Cy, 1); \
90
+ Cz = Aba1^Aga1^Aka1^Ama1^Asa1; \
91
+ De1 = Cz^Cw; \
92
+ \
93
+ Cy = Abo1^Ago1^Ako1^Amo1^Aso1; \
94
+ Di0 = Du0^ROL32(Cy, 1); \
95
+ Cw = Abo0^Ago0^Ako0^Amo0^Aso0; \
96
+ Di1 = Du1^Cw; \
97
+ \
98
+ Du0 = Cw^ROL32(Cz, 1); \
99
+ Du1 = Cy^Cx; \
100
+ \
101
+ Aba0 ^= Da0; \
102
+ Ba = Aba0; \
103
+ Age0 ^= De0; \
104
+ Be = ROL32(Age0, 22); \
105
+ Aki1 ^= Di1; \
106
+ Bi = ROL32(Aki1, 22); \
107
+ Amo1 ^= Do1; \
108
+ Bo = ROL32(Amo1, 11); \
109
+ Asu0 ^= Du0; \
110
+ Bu = ROL32(Asu0, 7); \
111
+ Eba0 = Ba ^((~Be)& Bi ) ^ *(pRoundConstants++); \
112
+ Ebe0 = Be ^((~Bi)& Bo ); \
113
+ Ebi0 = Bi ^((~Bo)& Bu ); \
114
+ Ebo0 = Bo ^((~Bu)& Ba ); \
115
+ Ebu0 = Bu ^((~Ba)& Be ); \
116
+ \
117
+ Abo0 ^= Do0; \
118
+ Ba = ROL32(Abo0, 14); \
119
+ Agu0 ^= Du0; \
120
+ Be = ROL32(Agu0, 10); \
121
+ Aka1 ^= Da1; \
122
+ Bi = ROL32(Aka1, 2); \
123
+ Ame1 ^= De1; \
124
+ Bo = ROL32(Ame1, 23); \
125
+ Asi1 ^= Di1; \
126
+ Bu = ROL32(Asi1, 31); \
127
+ Ega0 = Ba ^((~Be)& Bi ); \
128
+ Ege0 = Be ^((~Bi)& Bo ); \
129
+ Egi0 = Bi ^((~Bo)& Bu ); \
130
+ Ego0 = Bo ^((~Bu)& Ba ); \
131
+ Egu0 = Bu ^((~Ba)& Be ); \
132
+ \
133
+ Abe1 ^= De1; \
134
+ Ba = ROL32(Abe1, 1); \
135
+ Agi0 ^= Di0; \
136
+ Be = ROL32(Agi0, 3); \
137
+ Ako1 ^= Do1; \
138
+ Bi = ROL32(Ako1, 13); \
139
+ Amu0 ^= Du0; \
140
+ Bo = ROL32(Amu0, 4); \
141
+ Asa0 ^= Da0; \
142
+ Bu = ROL32(Asa0, 9); \
143
+ Eka0 = Ba ^((~Be)& Bi ); \
144
+ Eke0 = Be ^((~Bi)& Bo ); \
145
+ Eki0 = Bi ^((~Bo)& Bu ); \
146
+ Eko0 = Bo ^((~Bu)& Ba ); \
147
+ Eku0 = Bu ^((~Ba)& Be ); \
148
+ \
149
+ Abu1 ^= Du1; \
150
+ Ba = ROL32(Abu1, 14); \
151
+ Aga0 ^= Da0; \
152
+ Be = ROL32(Aga0, 18); \
153
+ Ake0 ^= De0; \
154
+ Bi = ROL32(Ake0, 5); \
155
+ Ami1 ^= Di1; \
156
+ Bo = ROL32(Ami1, 8); \
157
+ Aso0 ^= Do0; \
158
+ Bu = ROL32(Aso0, 28); \
159
+ Ema0 = Ba ^((~Be)& Bi ); \
160
+ Eme0 = Be ^((~Bi)& Bo ); \
161
+ Emi0 = Bi ^((~Bo)& Bu ); \
162
+ Emo0 = Bo ^((~Bu)& Ba ); \
163
+ Emu0 = Bu ^((~Ba)& Be ); \
164
+ \
165
+ Abi0 ^= Di0; \
166
+ Ba = ROL32(Abi0, 31); \
167
+ Ago1 ^= Do1; \
168
+ Be = ROL32(Ago1, 28); \
169
+ Aku1 ^= Du1; \
170
+ Bi = ROL32(Aku1, 20); \
171
+ Ama1 ^= Da1; \
172
+ Bo = ROL32(Ama1, 21); \
173
+ Ase0 ^= De0; \
174
+ Bu = ROL32(Ase0, 1); \
175
+ Esa0 = Ba ^((~Be)& Bi ); \
176
+ Ese0 = Be ^((~Bi)& Bo ); \
177
+ Esi0 = Bi ^((~Bo)& Bu ); \
178
+ Eso0 = Bo ^((~Bu)& Ba ); \
179
+ Esu0 = Bu ^((~Ba)& Be ); \
180
+ \
181
+ Aba1 ^= Da1; \
182
+ Ba = Aba1; \
183
+ Age1 ^= De1; \
184
+ Be = ROL32(Age1, 22); \
185
+ Aki0 ^= Di0; \
186
+ Bi = ROL32(Aki0, 21); \
187
+ Amo0 ^= Do0; \
188
+ Bo = ROL32(Amo0, 10); \
189
+ Asu1 ^= Du1; \
190
+ Bu = ROL32(Asu1, 7); \
191
+ Eba1 = Ba ^((~Be)& Bi ); \
192
+ Eba1 ^= *(pRoundConstants++); \
193
+ Ebe1 = Be ^((~Bi)& Bo ); \
194
+ Ebi1 = Bi ^((~Bo)& Bu ); \
195
+ Ebo1 = Bo ^((~Bu)& Ba ); \
196
+ Ebu1 = Bu ^((~Ba)& Be ); \
197
+ \
198
+ Abo1 ^= Do1; \
199
+ Ba = ROL32(Abo1, 14); \
200
+ Agu1 ^= Du1; \
201
+ Be = ROL32(Agu1, 10); \
202
+ Aka0 ^= Da0; \
203
+ Bi = ROL32(Aka0, 1); \
204
+ Ame0 ^= De0; \
205
+ Bo = ROL32(Ame0, 22); \
206
+ Asi0 ^= Di0; \
207
+ Bu = ROL32(Asi0, 30); \
208
+ Ega1 = Ba ^((~Be)& Bi ); \
209
+ Ege1 = Be ^((~Bi)& Bo ); \
210
+ Egi1 = Bi ^((~Bo)& Bu ); \
211
+ Ego1 = Bo ^((~Bu)& Ba ); \
212
+ Egu1 = Bu ^((~Ba)& Be ); \
213
+ \
214
+ Abe0 ^= De0; \
215
+ Ba = Abe0; \
216
+ Agi1 ^= Di1; \
217
+ Be = ROL32(Agi1, 3); \
218
+ Ako0 ^= Do0; \
219
+ Bi = ROL32(Ako0, 12); \
220
+ Amu1 ^= Du1; \
221
+ Bo = ROL32(Amu1, 4); \
222
+ Asa1 ^= Da1; \
223
+ Bu = ROL32(Asa1, 9); \
224
+ Eka1 = Ba ^((~Be)& Bi ); \
225
+ Eke1 = Be ^((~Bi)& Bo ); \
226
+ Eki1 = Bi ^((~Bo)& Bu ); \
227
+ Eko1 = Bo ^((~Bu)& Ba ); \
228
+ Eku1 = Bu ^((~Ba)& Be ); \
229
+ \
230
+ Abu0 ^= Du0; \
231
+ Ba = ROL32(Abu0, 13); \
232
+ Aga1 ^= Da1; \
233
+ Be = ROL32(Aga1, 18); \
234
+ Ake1 ^= De1; \
235
+ Bi = ROL32(Ake1, 5); \
236
+ Ami0 ^= Di0; \
237
+ Bo = ROL32(Ami0, 7); \
238
+ Aso1 ^= Do1; \
239
+ Bu = ROL32(Aso1, 28); \
240
+ Ema1 = Ba ^((~Be)& Bi ); \
241
+ Eme1 = Be ^((~Bi)& Bo ); \
242
+ Emi1 = Bi ^((~Bo)& Bu ); \
243
+ Emo1 = Bo ^((~Bu)& Ba ); \
244
+ Emu1 = Bu ^((~Ba)& Be ); \
245
+ \
246
+ Abi1 ^= Di1; \
247
+ Ba = ROL32(Abi1, 31); \
248
+ Ago0 ^= Do0; \
249
+ Be = ROL32(Ago0, 27); \
250
+ Aku0 ^= Du0; \
251
+ Bi = ROL32(Aku0, 19); \
252
+ Ama0 ^= Da0; \
253
+ Bo = ROL32(Ama0, 20); \
254
+ Ase1 ^= De1; \
255
+ Bu = ROL32(Ase1, 1); \
256
+ Esa1 = Ba ^((~Be)& Bi ); \
257
+ Ese1 = Be ^((~Bi)& Bo ); \
258
+ Esi1 = Bi ^((~Bo)& Bu ); \
259
+ Eso1 = Bo ^((~Bu)& Ba ); \
260
+ Esu1 = Bu ^((~Ba)& Be ); \
261
+ \
262
+ Cx = Ebu0^Egu0^Eku0^Emu0^Esu0; \
263
+ Du1 = Ebe1^Ege1^Eke1^Eme1^Ese1; \
264
+ Da0 = Cx^ROL32(Du1, 1); \
265
+ Cz = Ebu1^Egu1^Eku1^Emu1^Esu1; \
266
+ Du0 = Ebe0^Ege0^Eke0^Eme0^Ese0; \
267
+ Da1 = Cz^Du0; \
268
+ \
269
+ Cw = Ebi0^Egi0^Eki0^Emi0^Esi0; \
270
+ Do0 = Cw^ROL32(Cz, 1); \
271
+ Cy = Ebi1^Egi1^Eki1^Emi1^Esi1; \
272
+ Do1 = Cy^Cx; \
273
+ \
274
+ Cx = Eba0^Ega0^Eka0^Ema0^Esa0; \
275
+ De0 = Cx^ROL32(Cy, 1); \
276
+ Cz = Eba1^Ega1^Eka1^Ema1^Esa1; \
277
+ De1 = Cz^Cw; \
278
+ \
279
+ Cy = Ebo1^Ego1^Eko1^Emo1^Eso1; \
280
+ Di0 = Du0^ROL32(Cy, 1); \
281
+ Cw = Ebo0^Ego0^Eko0^Emo0^Eso0; \
282
+ Di1 = Du1^Cw; \
283
+ \
284
+ Du0 = Cw^ROL32(Cz, 1); \
285
+ Du1 = Cy^Cx; \
286
+ \
287
+ Eba0 ^= Da0; \
288
+ Ba = Eba0; \
289
+ Ege0 ^= De0; \
290
+ Be = ROL32(Ege0, 22); \
291
+ Eki1 ^= Di1; \
292
+ Bi = ROL32(Eki1, 22); \
293
+ Emo1 ^= Do1; \
294
+ Bo = ROL32(Emo1, 11); \
295
+ Esu0 ^= Du0; \
296
+ Bu = ROL32(Esu0, 7); \
297
+ Aba0 = Ba ^((~Be)& Bi ); \
298
+ Aba0 ^= *(pRoundConstants++); \
299
+ Abe0 = Be ^((~Bi)& Bo ); \
300
+ Abi0 = Bi ^((~Bo)& Bu ); \
301
+ Abo0 = Bo ^((~Bu)& Ba ); \
302
+ Abu0 = Bu ^((~Ba)& Be ); \
303
+ \
304
+ Ebo0 ^= Do0; \
305
+ Ba = ROL32(Ebo0, 14); \
306
+ Egu0 ^= Du0; \
307
+ Be = ROL32(Egu0, 10); \
308
+ Eka1 ^= Da1; \
309
+ Bi = ROL32(Eka1, 2); \
310
+ Eme1 ^= De1; \
311
+ Bo = ROL32(Eme1, 23); \
312
+ Esi1 ^= Di1; \
313
+ Bu = ROL32(Esi1, 31); \
314
+ Aga0 = Ba ^((~Be)& Bi ); \
315
+ Age0 = Be ^((~Bi)& Bo ); \
316
+ Agi0 = Bi ^((~Bo)& Bu ); \
317
+ Ago0 = Bo ^((~Bu)& Ba ); \
318
+ Agu0 = Bu ^((~Ba)& Be ); \
319
+ \
320
+ Ebe1 ^= De1; \
321
+ Ba = ROL32(Ebe1, 1); \
322
+ Egi0 ^= Di0; \
323
+ Be = ROL32(Egi0, 3); \
324
+ Eko1 ^= Do1; \
325
+ Bi = ROL32(Eko1, 13); \
326
+ Emu0 ^= Du0; \
327
+ Bo = ROL32(Emu0, 4); \
328
+ Esa0 ^= Da0; \
329
+ Bu = ROL32(Esa0, 9); \
330
+ Aka0 = Ba ^((~Be)& Bi ); \
331
+ Ake0 = Be ^((~Bi)& Bo ); \
332
+ Aki0 = Bi ^((~Bo)& Bu ); \
333
+ Ako0 = Bo ^((~Bu)& Ba ); \
334
+ Aku0 = Bu ^((~Ba)& Be ); \
335
+ \
336
+ Ebu1 ^= Du1; \
337
+ Ba = ROL32(Ebu1, 14); \
338
+ Ega0 ^= Da0; \
339
+ Be = ROL32(Ega0, 18); \
340
+ Eke0 ^= De0; \
341
+ Bi = ROL32(Eke0, 5); \
342
+ Emi1 ^= Di1; \
343
+ Bo = ROL32(Emi1, 8); \
344
+ Eso0 ^= Do0; \
345
+ Bu = ROL32(Eso0, 28); \
346
+ Ama0 = Ba ^((~Be)& Bi ); \
347
+ Ame0 = Be ^((~Bi)& Bo ); \
348
+ Ami0 = Bi ^((~Bo)& Bu ); \
349
+ Amo0 = Bo ^((~Bu)& Ba ); \
350
+ Amu0 = Bu ^((~Ba)& Be ); \
351
+ \
352
+ Ebi0 ^= Di0; \
353
+ Ba = ROL32(Ebi0, 31); \
354
+ Ego1 ^= Do1; \
355
+ Be = ROL32(Ego1, 28); \
356
+ Eku1 ^= Du1; \
357
+ Bi = ROL32(Eku1, 20); \
358
+ Ema1 ^= Da1; \
359
+ Bo = ROL32(Ema1, 21); \
360
+ Ese0 ^= De0; \
361
+ Bu = ROL32(Ese0, 1); \
362
+ Asa0 = Ba ^((~Be)& Bi ); \
363
+ Ase0 = Be ^((~Bi)& Bo ); \
364
+ Asi0 = Bi ^((~Bo)& Bu ); \
365
+ Aso0 = Bo ^((~Bu)& Ba ); \
366
+ Asu0 = Bu ^((~Ba)& Be ); \
367
+ \
368
+ Eba1 ^= Da1; \
369
+ Ba = Eba1; \
370
+ Ege1 ^= De1; \
371
+ Be = ROL32(Ege1, 22); \
372
+ Eki0 ^= Di0; \
373
+ Bi = ROL32(Eki0, 21); \
374
+ Emo0 ^= Do0; \
375
+ Bo = ROL32(Emo0, 10); \
376
+ Esu1 ^= Du1; \
377
+ Bu = ROL32(Esu1, 7); \
378
+ Aba1 = Ba ^((~Be)& Bi ); \
379
+ Aba1 ^= *(pRoundConstants++); \
380
+ Abe1 = Be ^((~Bi)& Bo ); \
381
+ Abi1 = Bi ^((~Bo)& Bu ); \
382
+ Abo1 = Bo ^((~Bu)& Ba ); \
383
+ Abu1 = Bu ^((~Ba)& Be ); \
384
+ \
385
+ Ebo1 ^= Do1; \
386
+ Ba = ROL32(Ebo1, 14); \
387
+ Egu1 ^= Du1; \
388
+ Be = ROL32(Egu1, 10); \
389
+ Eka0 ^= Da0; \
390
+ Bi = ROL32(Eka0, 1); \
391
+ Eme0 ^= De0; \
392
+ Bo = ROL32(Eme0, 22); \
393
+ Esi0 ^= Di0; \
394
+ Bu = ROL32(Esi0, 30); \
395
+ Aga1 = Ba ^((~Be)& Bi ); \
396
+ Age1 = Be ^((~Bi)& Bo ); \
397
+ Agi1 = Bi ^((~Bo)& Bu ); \
398
+ Ago1 = Bo ^((~Bu)& Ba ); \
399
+ Agu1 = Bu ^((~Ba)& Be ); \
400
+ \
401
+ Ebe0 ^= De0; \
402
+ Ba = Ebe0; \
403
+ Egi1 ^= Di1; \
404
+ Be = ROL32(Egi1, 3); \
405
+ Eko0 ^= Do0; \
406
+ Bi = ROL32(Eko0, 12); \
407
+ Emu1 ^= Du1; \
408
+ Bo = ROL32(Emu1, 4); \
409
+ Esa1 ^= Da1; \
410
+ Bu = ROL32(Esa1, 9); \
411
+ Aka1 = Ba ^((~Be)& Bi ); \
412
+ Ake1 = Be ^((~Bi)& Bo ); \
413
+ Aki1 = Bi ^((~Bo)& Bu ); \
414
+ Ako1 = Bo ^((~Bu)& Ba ); \
415
+ Aku1 = Bu ^((~Ba)& Be ); \
416
+ \
417
+ Ebu0 ^= Du0; \
418
+ Ba = ROL32(Ebu0, 13); \
419
+ Ega1 ^= Da1; \
420
+ Be = ROL32(Ega1, 18); \
421
+ Eke1 ^= De1; \
422
+ Bi = ROL32(Eke1, 5); \
423
+ Emi0 ^= Di0; \
424
+ Bo = ROL32(Emi0, 7); \
425
+ Eso1 ^= Do1; \
426
+ Bu = ROL32(Eso1, 28); \
427
+ Ama1 = Ba ^((~Be)& Bi ); \
428
+ Ame1 = Be ^((~Bi)& Bo ); \
429
+ Ami1 = Bi ^((~Bo)& Bu ); \
430
+ Amo1 = Bo ^((~Bu)& Ba ); \
431
+ Amu1 = Bu ^((~Ba)& Be ); \
432
+ \
433
+ Ebi1 ^= Di1; \
434
+ Ba = ROL32(Ebi1, 31); \
435
+ Ego0 ^= Do0; \
436
+ Be = ROL32(Ego0, 27); \
437
+ Eku0 ^= Du0; \
438
+ Bi = ROL32(Eku0, 19); \
439
+ Ema0 ^= Da0; \
440
+ Bo = ROL32(Ema0, 20); \
441
+ Ese1 ^= De1; \
442
+ Bu = ROL32(Ese1, 1); \
443
+ Asa1 = Ba ^((~Be)& Bi ); \
444
+ Ase1 = Be ^((~Bi)& Bo ); \
445
+ Asi1 = Bi ^((~Bo)& Bu ); \
446
+ Aso1 = Bo ^((~Bu)& Ba ); \
447
+ Asu1 = Bu ^((~Ba)& Be ); \
448
+ } \
449
+ copyToState(state, A) \
450
+ }
451
+
452
+ #define copyFromState(X, state) \
453
+ X##ba0 = state[ 0]; \
454
+ X##ba1 = state[ 1]; \
455
+ X##be0 = state[ 2]; \
456
+ X##be1 = state[ 3]; \
457
+ X##bi0 = state[ 4]; \
458
+ X##bi1 = state[ 5]; \
459
+ X##bo0 = state[ 6]; \
460
+ X##bo1 = state[ 7]; \
461
+ X##bu0 = state[ 8]; \
462
+ X##bu1 = state[ 9]; \
463
+ X##ga0 = state[10]; \
464
+ X##ga1 = state[11]; \
465
+ X##ge0 = state[12]; \
466
+ X##ge1 = state[13]; \
467
+ X##gi0 = state[14]; \
468
+ X##gi1 = state[15]; \
469
+ X##go0 = state[16]; \
470
+ X##go1 = state[17]; \
471
+ X##gu0 = state[18]; \
472
+ X##gu1 = state[19]; \
473
+ X##ka0 = state[20]; \
474
+ X##ka1 = state[21]; \
475
+ X##ke0 = state[22]; \
476
+ X##ke1 = state[23]; \
477
+ X##ki0 = state[24]; \
478
+ X##ki1 = state[25]; \
479
+ X##ko0 = state[26]; \
480
+ X##ko1 = state[27]; \
481
+ X##ku0 = state[28]; \
482
+ X##ku1 = state[29]; \
483
+ X##ma0 = state[30]; \
484
+ X##ma1 = state[31]; \
485
+ X##me0 = state[32]; \
486
+ X##me1 = state[33]; \
487
+ X##mi0 = state[34]; \
488
+ X##mi1 = state[35]; \
489
+ X##mo0 = state[36]; \
490
+ X##mo1 = state[37]; \
491
+ X##mu0 = state[38]; \
492
+ X##mu1 = state[39]; \
493
+ X##sa0 = state[40]; \
494
+ X##sa1 = state[41]; \
495
+ X##se0 = state[42]; \
496
+ X##se1 = state[43]; \
497
+ X##si0 = state[44]; \
498
+ X##si1 = state[45]; \
499
+ X##so0 = state[46]; \
500
+ X##so1 = state[47]; \
501
+ X##su0 = state[48]; \
502
+ X##su1 = state[49]; \
503
+
504
+ #define copyToState(state, X) \
505
+ state[ 0] = X##ba0; \
506
+ state[ 1] = X##ba1; \
507
+ state[ 2] = X##be0; \
508
+ state[ 3] = X##be1; \
509
+ state[ 4] = X##bi0; \
510
+ state[ 5] = X##bi1; \
511
+ state[ 6] = X##bo0; \
512
+ state[ 7] = X##bo1; \
513
+ state[ 8] = X##bu0; \
514
+ state[ 9] = X##bu1; \
515
+ state[10] = X##ga0; \
516
+ state[11] = X##ga1; \
517
+ state[12] = X##ge0; \
518
+ state[13] = X##ge1; \
519
+ state[14] = X##gi0; \
520
+ state[15] = X##gi1; \
521
+ state[16] = X##go0; \
522
+ state[17] = X##go1; \
523
+ state[18] = X##gu0; \
524
+ state[19] = X##gu1; \
525
+ state[20] = X##ka0; \
526
+ state[21] = X##ka1; \
527
+ state[22] = X##ke0; \
528
+ state[23] = X##ke1; \
529
+ state[24] = X##ki0; \
530
+ state[25] = X##ki1; \
531
+ state[26] = X##ko0; \
532
+ state[27] = X##ko1; \
533
+ state[28] = X##ku0; \
534
+ state[29] = X##ku1; \
535
+ state[30] = X##ma0; \
536
+ state[31] = X##ma1; \
537
+ state[32] = X##me0; \
538
+ state[33] = X##me1; \
539
+ state[34] = X##mi0; \
540
+ state[35] = X##mi1; \
541
+ state[36] = X##mo0; \
542
+ state[37] = X##mo1; \
543
+ state[38] = X##mu0; \
544
+ state[39] = X##mu1; \
545
+ state[40] = X##sa0; \
546
+ state[41] = X##sa1; \
547
+ state[42] = X##se0; \
548
+ state[43] = X##se1; \
549
+ state[44] = X##si0; \
550
+ state[45] = X##si1; \
551
+ state[46] = X##so0; \
552
+ state[47] = X##so1; \
553
+ state[48] = X##su0; \
554
+ state[49] = X##su1; \
555
+