wp_block.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. /*
  2. * Copyright 2005-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /**
  10. * The Whirlpool hashing function.
  11. *
  12. * See
  13. * P.S.L.M. Barreto, V. Rijmen,
  14. * ``The Whirlpool hashing function,''
  15. * NESSIE submission, 2000 (tweaked version, 2001),
  16. * <https://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/whirlpool.zip>
  17. *
  18. * Based on "@version 3.0 (2003.03.12)" by Paulo S.L.M. Barreto and
  19. * Vincent Rijmen. Lookup "reference implementations" on
  20. * <http://planeta.terra.com.br/informatica/paulobarreto/>
  21. *
  22. * =============================================================================
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
  25. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  26. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  31. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  32. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  33. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  34. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. */
  37. /*
  38. * Whirlpool low level APIs are deprecated for public use, but still ok for
  39. * internal use.
  40. */
  41. #include "internal/deprecated.h"
  42. #include "internal/cryptlib.h"
  43. #include "wp_local.h"
  44. #include <string.h>
  45. typedef unsigned char u8;
  46. #if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32)
  47. typedef unsigned __int64 u64;
  48. #elif defined(__arch64__)
  49. typedef unsigned long u64;
  50. #else
  51. typedef unsigned long long u64;
  52. #endif
  53. #define ROUNDS 10
  54. #define STRICT_ALIGNMENT
  55. #if !defined(PEDANTIC) && (defined(__i386) || defined(__i386__) || \
  56. defined(__x86_64) || defined(__x86_64__) || \
  57. defined(_M_IX86) || defined(_M_AMD64) || \
  58. defined(_M_X64))
  59. /*
  60. * Well, formally there're couple of other architectures, which permit
  61. * unaligned loads, specifically those not crossing cache lines, IA-64 and
  62. * PowerPC...
  63. */
  64. # undef STRICT_ALIGNMENT
  65. #endif
  66. #ifndef STRICT_ALIGNMENT
  67. # ifdef __GNUC__
  68. typedef u64 u64_a1 __attribute((__aligned__(1)));
  69. # else
  70. typedef u64 u64_a1;
  71. # endif
  72. #endif
  73. #if defined(__GNUC__) && !defined(STRICT_ALIGNMENT)
  74. typedef u64 u64_aX __attribute((__aligned__(1)));
  75. #else
  76. typedef u64 u64_aX;
  77. #endif
  78. #undef SMALL_REGISTER_BANK
  79. #if defined(__i386) || defined(__i386__) || defined(_M_IX86)
  80. # define SMALL_REGISTER_BANK
  81. # if defined(WHIRLPOOL_ASM)
  82. # ifndef OPENSSL_SMALL_FOOTPRINT
  83. /*
  84. * it appears that for elder non-MMX
  85. * CPUs this is actually faster!
  86. */
  87. # define OPENSSL_SMALL_FOOTPRINT
  88. # endif
  89. # define GO_FOR_MMX(ctx,inp,num) do { \
  90. void whirlpool_block_mmx(void *,const void *,size_t); \
  91. if (!(OPENSSL_ia32cap_P[0] & (1<<23))) break; \
  92. whirlpool_block_mmx(ctx->H.c,inp,num); return; \
  93. } while (0)
  94. # endif
  95. #endif
  96. #undef ROTATE
  97. #ifndef PEDANTIC
  98. # if defined(_MSC_VER)
  99. # if defined(_WIN64) /* applies to both IA-64 and AMD64 */
  100. # include <stdlib.h>
  101. # pragma intrinsic(_rotl64)
  102. # define ROTATE(a,n) _rotl64((a),n)
  103. # endif
  104. # elif defined(__GNUC__) && __GNUC__>=2
  105. # if defined(__x86_64) || defined(__x86_64__)
  106. # if defined(L_ENDIAN)
  107. # define ROTATE(a,n) ({ u64 ret; asm ("rolq %1,%0" \
  108. : "=r"(ret) : "J"(n),"0"(a) : "cc"); ret; })
  109. # elif defined(B_ENDIAN)
  110. /*
  111. * Most will argue that x86_64 is always little-endian. Well, yes, but
  112. * then we have stratus.com who has modified gcc to "emulate"
  113. * big-endian on x86. Is there evidence that they [or somebody else]
  114. * won't do same for x86_64? Naturally no. And this line is waiting
  115. * ready for that brave soul:-)
  116. */
  117. # define ROTATE(a,n) ({ u64 ret; asm ("rorq %1,%0" \
  118. : "=r"(ret) : "J"(n),"0"(a) : "cc"); ret; })
  119. # endif
  120. # elif defined(__ia64) || defined(__ia64__)
  121. # if defined(L_ENDIAN)
  122. # define ROTATE(a,n) ({ u64 ret; asm ("shrp %0=%1,%1,%2" \
  123. : "=r"(ret) : "r"(a),"M"(64-(n))); ret; })
  124. # elif defined(B_ENDIAN)
  125. # define ROTATE(a,n) ({ u64 ret; asm ("shrp %0=%1,%1,%2" \
  126. : "=r"(ret) : "r"(a),"M"(n)); ret; })
  127. # endif
  128. # endif
  129. # endif
  130. #endif
  131. #if defined(OPENSSL_SMALL_FOOTPRINT)
  132. # if !defined(ROTATE)
  133. # if defined(L_ENDIAN) /* little-endians have to rotate left */
  134. # define ROTATE(i,n) ((i)<<(n) ^ (i)>>(64-n))
  135. # elif defined(B_ENDIAN) /* big-endians have to rotate right */
  136. # define ROTATE(i,n) ((i)>>(n) ^ (i)<<(64-n))
  137. # endif
  138. # endif
  139. # if defined(ROTATE) && !defined(STRICT_ALIGNMENT)
  140. # define STRICT_ALIGNMENT /* ensure smallest table size */
  141. # endif
  142. #endif
  143. /*
  144. * Table size depends on STRICT_ALIGNMENT and whether or not endian-
  145. * specific ROTATE macro is defined. If STRICT_ALIGNMENT is not
  146. * defined, which is normally the case on x86[_64] CPUs, the table is
  147. * 4KB large unconditionally. Otherwise if ROTATE is defined, the
  148. * table is 2KB large, and otherwise - 16KB. 2KB table requires a
  149. * whole bunch of additional rotations, but I'm willing to "trade,"
  150. * because 16KB table certainly trashes L1 cache. I wish all CPUs
  151. * could handle unaligned load as 4KB table doesn't trash the cache,
  152. * nor does it require additional rotations.
  153. */
  154. /*
  155. * Note that every Cn macro expands as two loads: one byte load and
  156. * one quadword load. One can argue that many single-byte loads
  157. * is too excessive, as one could load a quadword and "milk" it for
  158. * eight 8-bit values instead. Well, yes, but in order to do so *and*
  159. * avoid excessive loads you have to accommodate a handful of 64-bit
  160. * values in the register bank and issue a bunch of shifts and mask.
  161. * It's a tradeoff: loads vs. shift and mask in big register bank[!].
  162. * On most CPUs eight single-byte loads are faster and I let other
  163. * ones to depend on smart compiler to fold byte loads if beneficial.
  164. * Hand-coded assembler would be another alternative:-)
  165. */
  166. #ifdef STRICT_ALIGNMENT
  167. # if defined(ROTATE)
  168. # define N 1
  169. # define LL(c0,c1,c2,c3,c4,c5,c6,c7) c0,c1,c2,c3,c4,c5,c6,c7
  170. # define C0(K,i) (Cx.q[K.c[(i)*8+0]])
  171. # define C1(K,i) ROTATE(Cx.q[K.c[(i)*8+1]],8)
  172. # define C2(K,i) ROTATE(Cx.q[K.c[(i)*8+2]],16)
  173. # define C3(K,i) ROTATE(Cx.q[K.c[(i)*8+3]],24)
  174. # define C4(K,i) ROTATE(Cx.q[K.c[(i)*8+4]],32)
  175. # define C5(K,i) ROTATE(Cx.q[K.c[(i)*8+5]],40)
  176. # define C6(K,i) ROTATE(Cx.q[K.c[(i)*8+6]],48)
  177. # define C7(K,i) ROTATE(Cx.q[K.c[(i)*8+7]],56)
  178. # else
  179. # define N 8
  180. # define LL(c0,c1,c2,c3,c4,c5,c6,c7) c0,c1,c2,c3,c4,c5,c6,c7, \
  181. c7,c0,c1,c2,c3,c4,c5,c6, \
  182. c6,c7,c0,c1,c2,c3,c4,c5, \
  183. c5,c6,c7,c0,c1,c2,c3,c4, \
  184. c4,c5,c6,c7,c0,c1,c2,c3, \
  185. c3,c4,c5,c6,c7,c0,c1,c2, \
  186. c2,c3,c4,c5,c6,c7,c0,c1, \
  187. c1,c2,c3,c4,c5,c6,c7,c0
  188. # define C0(K,i) (Cx.q[0+8*K.c[(i)*8+0]])
  189. # define C1(K,i) (Cx.q[1+8*K.c[(i)*8+1]])
  190. # define C2(K,i) (Cx.q[2+8*K.c[(i)*8+2]])
  191. # define C3(K,i) (Cx.q[3+8*K.c[(i)*8+3]])
  192. # define C4(K,i) (Cx.q[4+8*K.c[(i)*8+4]])
  193. # define C5(K,i) (Cx.q[5+8*K.c[(i)*8+5]])
  194. # define C6(K,i) (Cx.q[6+8*K.c[(i)*8+6]])
  195. # define C7(K,i) (Cx.q[7+8*K.c[(i)*8+7]])
  196. # endif
  197. #else
  198. # define N 2
  199. # define LL(c0,c1,c2,c3,c4,c5,c6,c7) c0,c1,c2,c3,c4,c5,c6,c7, \
  200. c0,c1,c2,c3,c4,c5,c6,c7
  201. # define C0(K,i) (((u64*)(Cx.c+0))[2*K.c[(i)*8+0]])
  202. # define C1(K,i) (((u64_a1*)(Cx.c+7))[2*K.c[(i)*8+1]])
  203. # define C2(K,i) (((u64_a1*)(Cx.c+6))[2*K.c[(i)*8+2]])
  204. # define C3(K,i) (((u64_a1*)(Cx.c+5))[2*K.c[(i)*8+3]])
  205. # define C4(K,i) (((u64_a1*)(Cx.c+4))[2*K.c[(i)*8+4]])
  206. # define C5(K,i) (((u64_a1*)(Cx.c+3))[2*K.c[(i)*8+5]])
  207. # define C6(K,i) (((u64_a1*)(Cx.c+2))[2*K.c[(i)*8+6]])
  208. # define C7(K,i) (((u64_a1*)(Cx.c+1))[2*K.c[(i)*8+7]])
  209. #endif
  210. static const
  211. union {
  212. u8 c[(256 * N + ROUNDS) * sizeof(u64)];
  213. u64 q[(256 * N + ROUNDS)];
  214. } Cx = {
  215. {
  216. /* Note endian-neutral representation:-) */
  217. LL(0x18, 0x18, 0x60, 0x18, 0xc0, 0x78, 0x30, 0xd8),
  218. LL(0x23, 0x23, 0x8c, 0x23, 0x05, 0xaf, 0x46, 0x26),
  219. LL(0xc6, 0xc6, 0x3f, 0xc6, 0x7e, 0xf9, 0x91, 0xb8),
  220. LL(0xe8, 0xe8, 0x87, 0xe8, 0x13, 0x6f, 0xcd, 0xfb),
  221. LL(0x87, 0x87, 0x26, 0x87, 0x4c, 0xa1, 0x13, 0xcb),
  222. LL(0xb8, 0xb8, 0xda, 0xb8, 0xa9, 0x62, 0x6d, 0x11),
  223. LL(0x01, 0x01, 0x04, 0x01, 0x08, 0x05, 0x02, 0x09),
  224. LL(0x4f, 0x4f, 0x21, 0x4f, 0x42, 0x6e, 0x9e, 0x0d),
  225. LL(0x36, 0x36, 0xd8, 0x36, 0xad, 0xee, 0x6c, 0x9b),
  226. LL(0xa6, 0xa6, 0xa2, 0xa6, 0x59, 0x04, 0x51, 0xff),
  227. LL(0xd2, 0xd2, 0x6f, 0xd2, 0xde, 0xbd, 0xb9, 0x0c),
  228. LL(0xf5, 0xf5, 0xf3, 0xf5, 0xfb, 0x06, 0xf7, 0x0e),
  229. LL(0x79, 0x79, 0xf9, 0x79, 0xef, 0x80, 0xf2, 0x96),
  230. LL(0x6f, 0x6f, 0xa1, 0x6f, 0x5f, 0xce, 0xde, 0x30),
  231. LL(0x91, 0x91, 0x7e, 0x91, 0xfc, 0xef, 0x3f, 0x6d),
  232. LL(0x52, 0x52, 0x55, 0x52, 0xaa, 0x07, 0xa4, 0xf8),
  233. LL(0x60, 0x60, 0x9d, 0x60, 0x27, 0xfd, 0xc0, 0x47),
  234. LL(0xbc, 0xbc, 0xca, 0xbc, 0x89, 0x76, 0x65, 0x35),
  235. LL(0x9b, 0x9b, 0x56, 0x9b, 0xac, 0xcd, 0x2b, 0x37),
  236. LL(0x8e, 0x8e, 0x02, 0x8e, 0x04, 0x8c, 0x01, 0x8a),
  237. LL(0xa3, 0xa3, 0xb6, 0xa3, 0x71, 0x15, 0x5b, 0xd2),
  238. LL(0x0c, 0x0c, 0x30, 0x0c, 0x60, 0x3c, 0x18, 0x6c),
  239. LL(0x7b, 0x7b, 0xf1, 0x7b, 0xff, 0x8a, 0xf6, 0x84),
  240. LL(0x35, 0x35, 0xd4, 0x35, 0xb5, 0xe1, 0x6a, 0x80),
  241. LL(0x1d, 0x1d, 0x74, 0x1d, 0xe8, 0x69, 0x3a, 0xf5),
  242. LL(0xe0, 0xe0, 0xa7, 0xe0, 0x53, 0x47, 0xdd, 0xb3),
  243. LL(0xd7, 0xd7, 0x7b, 0xd7, 0xf6, 0xac, 0xb3, 0x21),
  244. LL(0xc2, 0xc2, 0x2f, 0xc2, 0x5e, 0xed, 0x99, 0x9c),
  245. LL(0x2e, 0x2e, 0xb8, 0x2e, 0x6d, 0x96, 0x5c, 0x43),
  246. LL(0x4b, 0x4b, 0x31, 0x4b, 0x62, 0x7a, 0x96, 0x29),
  247. LL(0xfe, 0xfe, 0xdf, 0xfe, 0xa3, 0x21, 0xe1, 0x5d),
  248. LL(0x57, 0x57, 0x41, 0x57, 0x82, 0x16, 0xae, 0xd5),
  249. LL(0x15, 0x15, 0x54, 0x15, 0xa8, 0x41, 0x2a, 0xbd),
  250. LL(0x77, 0x77, 0xc1, 0x77, 0x9f, 0xb6, 0xee, 0xe8),
  251. LL(0x37, 0x37, 0xdc, 0x37, 0xa5, 0xeb, 0x6e, 0x92),
  252. LL(0xe5, 0xe5, 0xb3, 0xe5, 0x7b, 0x56, 0xd7, 0x9e),
  253. LL(0x9f, 0x9f, 0x46, 0x9f, 0x8c, 0xd9, 0x23, 0x13),
  254. LL(0xf0, 0xf0, 0xe7, 0xf0, 0xd3, 0x17, 0xfd, 0x23),
  255. LL(0x4a, 0x4a, 0x35, 0x4a, 0x6a, 0x7f, 0x94, 0x20),
  256. LL(0xda, 0xda, 0x4f, 0xda, 0x9e, 0x95, 0xa9, 0x44),
  257. LL(0x58, 0x58, 0x7d, 0x58, 0xfa, 0x25, 0xb0, 0xa2),
  258. LL(0xc9, 0xc9, 0x03, 0xc9, 0x06, 0xca, 0x8f, 0xcf),
  259. LL(0x29, 0x29, 0xa4, 0x29, 0x55, 0x8d, 0x52, 0x7c),
  260. LL(0x0a, 0x0a, 0x28, 0x0a, 0x50, 0x22, 0x14, 0x5a),
  261. LL(0xb1, 0xb1, 0xfe, 0xb1, 0xe1, 0x4f, 0x7f, 0x50),
  262. LL(0xa0, 0xa0, 0xba, 0xa0, 0x69, 0x1a, 0x5d, 0xc9),
  263. LL(0x6b, 0x6b, 0xb1, 0x6b, 0x7f, 0xda, 0xd6, 0x14),
  264. LL(0x85, 0x85, 0x2e, 0x85, 0x5c, 0xab, 0x17, 0xd9),
  265. LL(0xbd, 0xbd, 0xce, 0xbd, 0x81, 0x73, 0x67, 0x3c),
  266. LL(0x5d, 0x5d, 0x69, 0x5d, 0xd2, 0x34, 0xba, 0x8f),
  267. LL(0x10, 0x10, 0x40, 0x10, 0x80, 0x50, 0x20, 0x90),
  268. LL(0xf4, 0xf4, 0xf7, 0xf4, 0xf3, 0x03, 0xf5, 0x07),
  269. LL(0xcb, 0xcb, 0x0b, 0xcb, 0x16, 0xc0, 0x8b, 0xdd),
  270. LL(0x3e, 0x3e, 0xf8, 0x3e, 0xed, 0xc6, 0x7c, 0xd3),
  271. LL(0x05, 0x05, 0x14, 0x05, 0x28, 0x11, 0x0a, 0x2d),
  272. LL(0x67, 0x67, 0x81, 0x67, 0x1f, 0xe6, 0xce, 0x78),
  273. LL(0xe4, 0xe4, 0xb7, 0xe4, 0x73, 0x53, 0xd5, 0x97),
  274. LL(0x27, 0x27, 0x9c, 0x27, 0x25, 0xbb, 0x4e, 0x02),
  275. LL(0x41, 0x41, 0x19, 0x41, 0x32, 0x58, 0x82, 0x73),
  276. LL(0x8b, 0x8b, 0x16, 0x8b, 0x2c, 0x9d, 0x0b, 0xa7),
  277. LL(0xa7, 0xa7, 0xa6, 0xa7, 0x51, 0x01, 0x53, 0xf6),
  278. LL(0x7d, 0x7d, 0xe9, 0x7d, 0xcf, 0x94, 0xfa, 0xb2),
  279. LL(0x95, 0x95, 0x6e, 0x95, 0xdc, 0xfb, 0x37, 0x49),
  280. LL(0xd8, 0xd8, 0x47, 0xd8, 0x8e, 0x9f, 0xad, 0x56),
  281. LL(0xfb, 0xfb, 0xcb, 0xfb, 0x8b, 0x30, 0xeb, 0x70),
  282. LL(0xee, 0xee, 0x9f, 0xee, 0x23, 0x71, 0xc1, 0xcd),
  283. LL(0x7c, 0x7c, 0xed, 0x7c, 0xc7, 0x91, 0xf8, 0xbb),
  284. LL(0x66, 0x66, 0x85, 0x66, 0x17, 0xe3, 0xcc, 0x71),
  285. LL(0xdd, 0xdd, 0x53, 0xdd, 0xa6, 0x8e, 0xa7, 0x7b),
  286. LL(0x17, 0x17, 0x5c, 0x17, 0xb8, 0x4b, 0x2e, 0xaf),
  287. LL(0x47, 0x47, 0x01, 0x47, 0x02, 0x46, 0x8e, 0x45),
  288. LL(0x9e, 0x9e, 0x42, 0x9e, 0x84, 0xdc, 0x21, 0x1a),
  289. LL(0xca, 0xca, 0x0f, 0xca, 0x1e, 0xc5, 0x89, 0xd4),
  290. LL(0x2d, 0x2d, 0xb4, 0x2d, 0x75, 0x99, 0x5a, 0x58),
  291. LL(0xbf, 0xbf, 0xc6, 0xbf, 0x91, 0x79, 0x63, 0x2e),
  292. LL(0x07, 0x07, 0x1c, 0x07, 0x38, 0x1b, 0x0e, 0x3f),
  293. LL(0xad, 0xad, 0x8e, 0xad, 0x01, 0x23, 0x47, 0xac),
  294. LL(0x5a, 0x5a, 0x75, 0x5a, 0xea, 0x2f, 0xb4, 0xb0),
  295. LL(0x83, 0x83, 0x36, 0x83, 0x6c, 0xb5, 0x1b, 0xef),
  296. LL(0x33, 0x33, 0xcc, 0x33, 0x85, 0xff, 0x66, 0xb6),
  297. LL(0x63, 0x63, 0x91, 0x63, 0x3f, 0xf2, 0xc6, 0x5c),
  298. LL(0x02, 0x02, 0x08, 0x02, 0x10, 0x0a, 0x04, 0x12),
  299. LL(0xaa, 0xaa, 0x92, 0xaa, 0x39, 0x38, 0x49, 0x93),
  300. LL(0x71, 0x71, 0xd9, 0x71, 0xaf, 0xa8, 0xe2, 0xde),
  301. LL(0xc8, 0xc8, 0x07, 0xc8, 0x0e, 0xcf, 0x8d, 0xc6),
  302. LL(0x19, 0x19, 0x64, 0x19, 0xc8, 0x7d, 0x32, 0xd1),
  303. LL(0x49, 0x49, 0x39, 0x49, 0x72, 0x70, 0x92, 0x3b),
  304. LL(0xd9, 0xd9, 0x43, 0xd9, 0x86, 0x9a, 0xaf, 0x5f),
  305. LL(0xf2, 0xf2, 0xef, 0xf2, 0xc3, 0x1d, 0xf9, 0x31),
  306. LL(0xe3, 0xe3, 0xab, 0xe3, 0x4b, 0x48, 0xdb, 0xa8),
  307. LL(0x5b, 0x5b, 0x71, 0x5b, 0xe2, 0x2a, 0xb6, 0xb9),
  308. LL(0x88, 0x88, 0x1a, 0x88, 0x34, 0x92, 0x0d, 0xbc),
  309. LL(0x9a, 0x9a, 0x52, 0x9a, 0xa4, 0xc8, 0x29, 0x3e),
  310. LL(0x26, 0x26, 0x98, 0x26, 0x2d, 0xbe, 0x4c, 0x0b),
  311. LL(0x32, 0x32, 0xc8, 0x32, 0x8d, 0xfa, 0x64, 0xbf),
  312. LL(0xb0, 0xb0, 0xfa, 0xb0, 0xe9, 0x4a, 0x7d, 0x59),
  313. LL(0xe9, 0xe9, 0x83, 0xe9, 0x1b, 0x6a, 0xcf, 0xf2),
  314. LL(0x0f, 0x0f, 0x3c, 0x0f, 0x78, 0x33, 0x1e, 0x77),
  315. LL(0xd5, 0xd5, 0x73, 0xd5, 0xe6, 0xa6, 0xb7, 0x33),
  316. LL(0x80, 0x80, 0x3a, 0x80, 0x74, 0xba, 0x1d, 0xf4),
  317. LL(0xbe, 0xbe, 0xc2, 0xbe, 0x99, 0x7c, 0x61, 0x27),
  318. LL(0xcd, 0xcd, 0x13, 0xcd, 0x26, 0xde, 0x87, 0xeb),
  319. LL(0x34, 0x34, 0xd0, 0x34, 0xbd, 0xe4, 0x68, 0x89),
  320. LL(0x48, 0x48, 0x3d, 0x48, 0x7a, 0x75, 0x90, 0x32),
  321. LL(0xff, 0xff, 0xdb, 0xff, 0xab, 0x24, 0xe3, 0x54),
  322. LL(0x7a, 0x7a, 0xf5, 0x7a, 0xf7, 0x8f, 0xf4, 0x8d),
  323. LL(0x90, 0x90, 0x7a, 0x90, 0xf4, 0xea, 0x3d, 0x64),
  324. LL(0x5f, 0x5f, 0x61, 0x5f, 0xc2, 0x3e, 0xbe, 0x9d),
  325. LL(0x20, 0x20, 0x80, 0x20, 0x1d, 0xa0, 0x40, 0x3d),
  326. LL(0x68, 0x68, 0xbd, 0x68, 0x67, 0xd5, 0xd0, 0x0f),
  327. LL(0x1a, 0x1a, 0x68, 0x1a, 0xd0, 0x72, 0x34, 0xca),
  328. LL(0xae, 0xae, 0x82, 0xae, 0x19, 0x2c, 0x41, 0xb7),
  329. LL(0xb4, 0xb4, 0xea, 0xb4, 0xc9, 0x5e, 0x75, 0x7d),
  330. LL(0x54, 0x54, 0x4d, 0x54, 0x9a, 0x19, 0xa8, 0xce),
  331. LL(0x93, 0x93, 0x76, 0x93, 0xec, 0xe5, 0x3b, 0x7f),
  332. LL(0x22, 0x22, 0x88, 0x22, 0x0d, 0xaa, 0x44, 0x2f),
  333. LL(0x64, 0x64, 0x8d, 0x64, 0x07, 0xe9, 0xc8, 0x63),
  334. LL(0xf1, 0xf1, 0xe3, 0xf1, 0xdb, 0x12, 0xff, 0x2a),
  335. LL(0x73, 0x73, 0xd1, 0x73, 0xbf, 0xa2, 0xe6, 0xcc),
  336. LL(0x12, 0x12, 0x48, 0x12, 0x90, 0x5a, 0x24, 0x82),
  337. LL(0x40, 0x40, 0x1d, 0x40, 0x3a, 0x5d, 0x80, 0x7a),
  338. LL(0x08, 0x08, 0x20, 0x08, 0x40, 0x28, 0x10, 0x48),
  339. LL(0xc3, 0xc3, 0x2b, 0xc3, 0x56, 0xe8, 0x9b, 0x95),
  340. LL(0xec, 0xec, 0x97, 0xec, 0x33, 0x7b, 0xc5, 0xdf),
  341. LL(0xdb, 0xdb, 0x4b, 0xdb, 0x96, 0x90, 0xab, 0x4d),
  342. LL(0xa1, 0xa1, 0xbe, 0xa1, 0x61, 0x1f, 0x5f, 0xc0),
  343. LL(0x8d, 0x8d, 0x0e, 0x8d, 0x1c, 0x83, 0x07, 0x91),
  344. LL(0x3d, 0x3d, 0xf4, 0x3d, 0xf5, 0xc9, 0x7a, 0xc8),
  345. LL(0x97, 0x97, 0x66, 0x97, 0xcc, 0xf1, 0x33, 0x5b),
  346. LL(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
  347. LL(0xcf, 0xcf, 0x1b, 0xcf, 0x36, 0xd4, 0x83, 0xf9),
  348. LL(0x2b, 0x2b, 0xac, 0x2b, 0x45, 0x87, 0x56, 0x6e),
  349. LL(0x76, 0x76, 0xc5, 0x76, 0x97, 0xb3, 0xec, 0xe1),
  350. LL(0x82, 0x82, 0x32, 0x82, 0x64, 0xb0, 0x19, 0xe6),
  351. LL(0xd6, 0xd6, 0x7f, 0xd6, 0xfe, 0xa9, 0xb1, 0x28),
  352. LL(0x1b, 0x1b, 0x6c, 0x1b, 0xd8, 0x77, 0x36, 0xc3),
  353. LL(0xb5, 0xb5, 0xee, 0xb5, 0xc1, 0x5b, 0x77, 0x74),
  354. LL(0xaf, 0xaf, 0x86, 0xaf, 0x11, 0x29, 0x43, 0xbe),
  355. LL(0x6a, 0x6a, 0xb5, 0x6a, 0x77, 0xdf, 0xd4, 0x1d),
  356. LL(0x50, 0x50, 0x5d, 0x50, 0xba, 0x0d, 0xa0, 0xea),
  357. LL(0x45, 0x45, 0x09, 0x45, 0x12, 0x4c, 0x8a, 0x57),
  358. LL(0xf3, 0xf3, 0xeb, 0xf3, 0xcb, 0x18, 0xfb, 0x38),
  359. LL(0x30, 0x30, 0xc0, 0x30, 0x9d, 0xf0, 0x60, 0xad),
  360. LL(0xef, 0xef, 0x9b, 0xef, 0x2b, 0x74, 0xc3, 0xc4),
  361. LL(0x3f, 0x3f, 0xfc, 0x3f, 0xe5, 0xc3, 0x7e, 0xda),
  362. LL(0x55, 0x55, 0x49, 0x55, 0x92, 0x1c, 0xaa, 0xc7),
  363. LL(0xa2, 0xa2, 0xb2, 0xa2, 0x79, 0x10, 0x59, 0xdb),
  364. LL(0xea, 0xea, 0x8f, 0xea, 0x03, 0x65, 0xc9, 0xe9),
  365. LL(0x65, 0x65, 0x89, 0x65, 0x0f, 0xec, 0xca, 0x6a),
  366. LL(0xba, 0xba, 0xd2, 0xba, 0xb9, 0x68, 0x69, 0x03),
  367. LL(0x2f, 0x2f, 0xbc, 0x2f, 0x65, 0x93, 0x5e, 0x4a),
  368. LL(0xc0, 0xc0, 0x27, 0xc0, 0x4e, 0xe7, 0x9d, 0x8e),
  369. LL(0xde, 0xde, 0x5f, 0xde, 0xbe, 0x81, 0xa1, 0x60),
  370. LL(0x1c, 0x1c, 0x70, 0x1c, 0xe0, 0x6c, 0x38, 0xfc),
  371. LL(0xfd, 0xfd, 0xd3, 0xfd, 0xbb, 0x2e, 0xe7, 0x46),
  372. LL(0x4d, 0x4d, 0x29, 0x4d, 0x52, 0x64, 0x9a, 0x1f),
  373. LL(0x92, 0x92, 0x72, 0x92, 0xe4, 0xe0, 0x39, 0x76),
  374. LL(0x75, 0x75, 0xc9, 0x75, 0x8f, 0xbc, 0xea, 0xfa),
  375. LL(0x06, 0x06, 0x18, 0x06, 0x30, 0x1e, 0x0c, 0x36),
  376. LL(0x8a, 0x8a, 0x12, 0x8a, 0x24, 0x98, 0x09, 0xae),
  377. LL(0xb2, 0xb2, 0xf2, 0xb2, 0xf9, 0x40, 0x79, 0x4b),
  378. LL(0xe6, 0xe6, 0xbf, 0xe6, 0x63, 0x59, 0xd1, 0x85),
  379. LL(0x0e, 0x0e, 0x38, 0x0e, 0x70, 0x36, 0x1c, 0x7e),
  380. LL(0x1f, 0x1f, 0x7c, 0x1f, 0xf8, 0x63, 0x3e, 0xe7),
  381. LL(0x62, 0x62, 0x95, 0x62, 0x37, 0xf7, 0xc4, 0x55),
  382. LL(0xd4, 0xd4, 0x77, 0xd4, 0xee, 0xa3, 0xb5, 0x3a),
  383. LL(0xa8, 0xa8, 0x9a, 0xa8, 0x29, 0x32, 0x4d, 0x81),
  384. LL(0x96, 0x96, 0x62, 0x96, 0xc4, 0xf4, 0x31, 0x52),
  385. LL(0xf9, 0xf9, 0xc3, 0xf9, 0x9b, 0x3a, 0xef, 0x62),
  386. LL(0xc5, 0xc5, 0x33, 0xc5, 0x66, 0xf6, 0x97, 0xa3),
  387. LL(0x25, 0x25, 0x94, 0x25, 0x35, 0xb1, 0x4a, 0x10),
  388. LL(0x59, 0x59, 0x79, 0x59, 0xf2, 0x20, 0xb2, 0xab),
  389. LL(0x84, 0x84, 0x2a, 0x84, 0x54, 0xae, 0x15, 0xd0),
  390. LL(0x72, 0x72, 0xd5, 0x72, 0xb7, 0xa7, 0xe4, 0xc5),
  391. LL(0x39, 0x39, 0xe4, 0x39, 0xd5, 0xdd, 0x72, 0xec),
  392. LL(0x4c, 0x4c, 0x2d, 0x4c, 0x5a, 0x61, 0x98, 0x16),
  393. LL(0x5e, 0x5e, 0x65, 0x5e, 0xca, 0x3b, 0xbc, 0x94),
  394. LL(0x78, 0x78, 0xfd, 0x78, 0xe7, 0x85, 0xf0, 0x9f),
  395. LL(0x38, 0x38, 0xe0, 0x38, 0xdd, 0xd8, 0x70, 0xe5),
  396. LL(0x8c, 0x8c, 0x0a, 0x8c, 0x14, 0x86, 0x05, 0x98),
  397. LL(0xd1, 0xd1, 0x63, 0xd1, 0xc6, 0xb2, 0xbf, 0x17),
  398. LL(0xa5, 0xa5, 0xae, 0xa5, 0x41, 0x0b, 0x57, 0xe4),
  399. LL(0xe2, 0xe2, 0xaf, 0xe2, 0x43, 0x4d, 0xd9, 0xa1),
  400. LL(0x61, 0x61, 0x99, 0x61, 0x2f, 0xf8, 0xc2, 0x4e),
  401. LL(0xb3, 0xb3, 0xf6, 0xb3, 0xf1, 0x45, 0x7b, 0x42),
  402. LL(0x21, 0x21, 0x84, 0x21, 0x15, 0xa5, 0x42, 0x34),
  403. LL(0x9c, 0x9c, 0x4a, 0x9c, 0x94, 0xd6, 0x25, 0x08),
  404. LL(0x1e, 0x1e, 0x78, 0x1e, 0xf0, 0x66, 0x3c, 0xee),
  405. LL(0x43, 0x43, 0x11, 0x43, 0x22, 0x52, 0x86, 0x61),
  406. LL(0xc7, 0xc7, 0x3b, 0xc7, 0x76, 0xfc, 0x93, 0xb1),
  407. LL(0xfc, 0xfc, 0xd7, 0xfc, 0xb3, 0x2b, 0xe5, 0x4f),
  408. LL(0x04, 0x04, 0x10, 0x04, 0x20, 0x14, 0x08, 0x24),
  409. LL(0x51, 0x51, 0x59, 0x51, 0xb2, 0x08, 0xa2, 0xe3),
  410. LL(0x99, 0x99, 0x5e, 0x99, 0xbc, 0xc7, 0x2f, 0x25),
  411. LL(0x6d, 0x6d, 0xa9, 0x6d, 0x4f, 0xc4, 0xda, 0x22),
  412. LL(0x0d, 0x0d, 0x34, 0x0d, 0x68, 0x39, 0x1a, 0x65),
  413. LL(0xfa, 0xfa, 0xcf, 0xfa, 0x83, 0x35, 0xe9, 0x79),
  414. LL(0xdf, 0xdf, 0x5b, 0xdf, 0xb6, 0x84, 0xa3, 0x69),
  415. LL(0x7e, 0x7e, 0xe5, 0x7e, 0xd7, 0x9b, 0xfc, 0xa9),
  416. LL(0x24, 0x24, 0x90, 0x24, 0x3d, 0xb4, 0x48, 0x19),
  417. LL(0x3b, 0x3b, 0xec, 0x3b, 0xc5, 0xd7, 0x76, 0xfe),
  418. LL(0xab, 0xab, 0x96, 0xab, 0x31, 0x3d, 0x4b, 0x9a),
  419. LL(0xce, 0xce, 0x1f, 0xce, 0x3e, 0xd1, 0x81, 0xf0),
  420. LL(0x11, 0x11, 0x44, 0x11, 0x88, 0x55, 0x22, 0x99),
  421. LL(0x8f, 0x8f, 0x06, 0x8f, 0x0c, 0x89, 0x03, 0x83),
  422. LL(0x4e, 0x4e, 0x25, 0x4e, 0x4a, 0x6b, 0x9c, 0x04),
  423. LL(0xb7, 0xb7, 0xe6, 0xb7, 0xd1, 0x51, 0x73, 0x66),
  424. LL(0xeb, 0xeb, 0x8b, 0xeb, 0x0b, 0x60, 0xcb, 0xe0),
  425. LL(0x3c, 0x3c, 0xf0, 0x3c, 0xfd, 0xcc, 0x78, 0xc1),
  426. LL(0x81, 0x81, 0x3e, 0x81, 0x7c, 0xbf, 0x1f, 0xfd),
  427. LL(0x94, 0x94, 0x6a, 0x94, 0xd4, 0xfe, 0x35, 0x40),
  428. LL(0xf7, 0xf7, 0xfb, 0xf7, 0xeb, 0x0c, 0xf3, 0x1c),
  429. LL(0xb9, 0xb9, 0xde, 0xb9, 0xa1, 0x67, 0x6f, 0x18),
  430. LL(0x13, 0x13, 0x4c, 0x13, 0x98, 0x5f, 0x26, 0x8b),
  431. LL(0x2c, 0x2c, 0xb0, 0x2c, 0x7d, 0x9c, 0x58, 0x51),
  432. LL(0xd3, 0xd3, 0x6b, 0xd3, 0xd6, 0xb8, 0xbb, 0x05),
  433. LL(0xe7, 0xe7, 0xbb, 0xe7, 0x6b, 0x5c, 0xd3, 0x8c),
  434. LL(0x6e, 0x6e, 0xa5, 0x6e, 0x57, 0xcb, 0xdc, 0x39),
  435. LL(0xc4, 0xc4, 0x37, 0xc4, 0x6e, 0xf3, 0x95, 0xaa),
  436. LL(0x03, 0x03, 0x0c, 0x03, 0x18, 0x0f, 0x06, 0x1b),
  437. LL(0x56, 0x56, 0x45, 0x56, 0x8a, 0x13, 0xac, 0xdc),
  438. LL(0x44, 0x44, 0x0d, 0x44, 0x1a, 0x49, 0x88, 0x5e),
  439. LL(0x7f, 0x7f, 0xe1, 0x7f, 0xdf, 0x9e, 0xfe, 0xa0),
  440. LL(0xa9, 0xa9, 0x9e, 0xa9, 0x21, 0x37, 0x4f, 0x88),
  441. LL(0x2a, 0x2a, 0xa8, 0x2a, 0x4d, 0x82, 0x54, 0x67),
  442. LL(0xbb, 0xbb, 0xd6, 0xbb, 0xb1, 0x6d, 0x6b, 0x0a),
  443. LL(0xc1, 0xc1, 0x23, 0xc1, 0x46, 0xe2, 0x9f, 0x87),
  444. LL(0x53, 0x53, 0x51, 0x53, 0xa2, 0x02, 0xa6, 0xf1),
  445. LL(0xdc, 0xdc, 0x57, 0xdc, 0xae, 0x8b, 0xa5, 0x72),
  446. LL(0x0b, 0x0b, 0x2c, 0x0b, 0x58, 0x27, 0x16, 0x53),
  447. LL(0x9d, 0x9d, 0x4e, 0x9d, 0x9c, 0xd3, 0x27, 0x01),
  448. LL(0x6c, 0x6c, 0xad, 0x6c, 0x47, 0xc1, 0xd8, 0x2b),
  449. LL(0x31, 0x31, 0xc4, 0x31, 0x95, 0xf5, 0x62, 0xa4),
  450. LL(0x74, 0x74, 0xcd, 0x74, 0x87, 0xb9, 0xe8, 0xf3),
  451. LL(0xf6, 0xf6, 0xff, 0xf6, 0xe3, 0x09, 0xf1, 0x15),
  452. LL(0x46, 0x46, 0x05, 0x46, 0x0a, 0x43, 0x8c, 0x4c),
  453. LL(0xac, 0xac, 0x8a, 0xac, 0x09, 0x26, 0x45, 0xa5),
  454. LL(0x89, 0x89, 0x1e, 0x89, 0x3c, 0x97, 0x0f, 0xb5),
  455. LL(0x14, 0x14, 0x50, 0x14, 0xa0, 0x44, 0x28, 0xb4),
  456. LL(0xe1, 0xe1, 0xa3, 0xe1, 0x5b, 0x42, 0xdf, 0xba),
  457. LL(0x16, 0x16, 0x58, 0x16, 0xb0, 0x4e, 0x2c, 0xa6),
  458. LL(0x3a, 0x3a, 0xe8, 0x3a, 0xcd, 0xd2, 0x74, 0xf7),
  459. LL(0x69, 0x69, 0xb9, 0x69, 0x6f, 0xd0, 0xd2, 0x06),
  460. LL(0x09, 0x09, 0x24, 0x09, 0x48, 0x2d, 0x12, 0x41),
  461. LL(0x70, 0x70, 0xdd, 0x70, 0xa7, 0xad, 0xe0, 0xd7),
  462. LL(0xb6, 0xb6, 0xe2, 0xb6, 0xd9, 0x54, 0x71, 0x6f),
  463. LL(0xd0, 0xd0, 0x67, 0xd0, 0xce, 0xb7, 0xbd, 0x1e),
  464. LL(0xed, 0xed, 0x93, 0xed, 0x3b, 0x7e, 0xc7, 0xd6),
  465. LL(0xcc, 0xcc, 0x17, 0xcc, 0x2e, 0xdb, 0x85, 0xe2),
  466. LL(0x42, 0x42, 0x15, 0x42, 0x2a, 0x57, 0x84, 0x68),
  467. LL(0x98, 0x98, 0x5a, 0x98, 0xb4, 0xc2, 0x2d, 0x2c),
  468. LL(0xa4, 0xa4, 0xaa, 0xa4, 0x49, 0x0e, 0x55, 0xed),
  469. LL(0x28, 0x28, 0xa0, 0x28, 0x5d, 0x88, 0x50, 0x75),
  470. LL(0x5c, 0x5c, 0x6d, 0x5c, 0xda, 0x31, 0xb8, 0x86),
  471. LL(0xf8, 0xf8, 0xc7, 0xf8, 0x93, 0x3f, 0xed, 0x6b),
  472. LL(0x86, 0x86, 0x22, 0x86, 0x44, 0xa4, 0x11, 0xc2),
  473. #define RC (&(Cx.q[256*N]))
  474. 0x18, 0x23, 0xc6, 0xe8, 0x87, 0xb8, 0x01, 0x4f,
  475. /* rc[ROUNDS] */
  476. 0x36, 0xa6, 0xd2, 0xf5, 0x79, 0x6f, 0x91, 0x52, 0x60, 0xbc, 0x9b,
  477. 0x8e, 0xa3, 0x0c, 0x7b, 0x35, 0x1d, 0xe0, 0xd7, 0xc2, 0x2e, 0x4b,
  478. 0xfe, 0x57, 0x15, 0x77, 0x37, 0xe5, 0x9f, 0xf0, 0x4a, 0xda, 0x58,
  479. 0xc9, 0x29, 0x0a, 0xb1, 0xa0, 0x6b, 0x85, 0xbd, 0x5d, 0x10, 0xf4,
  480. 0xcb, 0x3e, 0x05, 0x67, 0xe4, 0x27, 0x41, 0x8b, 0xa7, 0x7d, 0x95,
  481. 0xd8, 0xfb, 0xee, 0x7c, 0x66, 0xdd, 0x17, 0x47, 0x9e, 0xca, 0x2d,
  482. 0xbf, 0x07, 0xad, 0x5a, 0x83, 0x33
  483. }
  484. };
  485. void whirlpool_block(WHIRLPOOL_CTX *ctx, const void *inp, size_t n)
  486. {
  487. int r;
  488. const u8 *p = inp;
  489. union {
  490. u64 q[8];
  491. u8 c[64];
  492. } S, K, *H = (void *)ctx->H.q;
  493. #ifdef GO_FOR_MMX
  494. GO_FOR_MMX(ctx, inp, n);
  495. #endif
  496. do {
  497. #ifdef OPENSSL_SMALL_FOOTPRINT
  498. u64 L[8];
  499. int i;
  500. for (i = 0; i < 64; i++)
  501. S.c[i] = (K.c[i] = H->c[i]) ^ p[i];
  502. for (r = 0; r < ROUNDS; r++) {
  503. for (i = 0; i < 8; i++) {
  504. L[i] = i ? 0 : RC[r];
  505. L[i] ^= C0(K, i) ^ C1(K, (i - 1) & 7) ^
  506. C2(K, (i - 2) & 7) ^ C3(K, (i - 3) & 7) ^
  507. C4(K, (i - 4) & 7) ^ C5(K, (i - 5) & 7) ^
  508. C6(K, (i - 6) & 7) ^ C7(K, (i - 7) & 7);
  509. }
  510. memcpy(K.q, L, 64);
  511. for (i = 0; i < 8; i++) {
  512. L[i] ^= C0(S, i) ^ C1(S, (i - 1) & 7) ^
  513. C2(S, (i - 2) & 7) ^ C3(S, (i - 3) & 7) ^
  514. C4(S, (i - 4) & 7) ^ C5(S, (i - 5) & 7) ^
  515. C6(S, (i - 6) & 7) ^ C7(S, (i - 7) & 7);
  516. }
  517. memcpy(S.q, L, 64);
  518. }
  519. for (i = 0; i < 64; i++)
  520. H->c[i] ^= S.c[i] ^ p[i];
  521. #else
  522. u64 L0, L1, L2, L3, L4, L5, L6, L7;
  523. # ifdef STRICT_ALIGNMENT
  524. if ((size_t)p & 7) {
  525. memcpy(S.c, p, 64);
  526. S.q[0] ^= (K.q[0] = H->q[0]);
  527. S.q[1] ^= (K.q[1] = H->q[1]);
  528. S.q[2] ^= (K.q[2] = H->q[2]);
  529. S.q[3] ^= (K.q[3] = H->q[3]);
  530. S.q[4] ^= (K.q[4] = H->q[4]);
  531. S.q[5] ^= (K.q[5] = H->q[5]);
  532. S.q[6] ^= (K.q[6] = H->q[6]);
  533. S.q[7] ^= (K.q[7] = H->q[7]);
  534. } else
  535. # endif
  536. {
  537. const u64_aX *pa = (const u64_aX *)p;
  538. S.q[0] = (K.q[0] = H->q[0]) ^ pa[0];
  539. S.q[1] = (K.q[1] = H->q[1]) ^ pa[1];
  540. S.q[2] = (K.q[2] = H->q[2]) ^ pa[2];
  541. S.q[3] = (K.q[3] = H->q[3]) ^ pa[3];
  542. S.q[4] = (K.q[4] = H->q[4]) ^ pa[4];
  543. S.q[5] = (K.q[5] = H->q[5]) ^ pa[5];
  544. S.q[6] = (K.q[6] = H->q[6]) ^ pa[6];
  545. S.q[7] = (K.q[7] = H->q[7]) ^ pa[7];
  546. }
  547. for (r = 0; r < ROUNDS; r++) {
  548. # ifdef SMALL_REGISTER_BANK
  549. L0 = C0(K, 0) ^ C1(K, 7) ^ C2(K, 6) ^ C3(K, 5) ^
  550. C4(K, 4) ^ C5(K, 3) ^ C6(K, 2) ^ C7(K, 1) ^ RC[r];
  551. L1 = C0(K, 1) ^ C1(K, 0) ^ C2(K, 7) ^ C3(K, 6) ^
  552. C4(K, 5) ^ C5(K, 4) ^ C6(K, 3) ^ C7(K, 2);
  553. L2 = C0(K, 2) ^ C1(K, 1) ^ C2(K, 0) ^ C3(K, 7) ^
  554. C4(K, 6) ^ C5(K, 5) ^ C6(K, 4) ^ C7(K, 3);
  555. L3 = C0(K, 3) ^ C1(K, 2) ^ C2(K, 1) ^ C3(K, 0) ^
  556. C4(K, 7) ^ C5(K, 6) ^ C6(K, 5) ^ C7(K, 4);
  557. L4 = C0(K, 4) ^ C1(K, 3) ^ C2(K, 2) ^ C3(K, 1) ^
  558. C4(K, 0) ^ C5(K, 7) ^ C6(K, 6) ^ C7(K, 5);
  559. L5 = C0(K, 5) ^ C1(K, 4) ^ C2(K, 3) ^ C3(K, 2) ^
  560. C4(K, 1) ^ C5(K, 0) ^ C6(K, 7) ^ C7(K, 6);
  561. L6 = C0(K, 6) ^ C1(K, 5) ^ C2(K, 4) ^ C3(K, 3) ^
  562. C4(K, 2) ^ C5(K, 1) ^ C6(K, 0) ^ C7(K, 7);
  563. L7 = C0(K, 7) ^ C1(K, 6) ^ C2(K, 5) ^ C3(K, 4) ^
  564. C4(K, 3) ^ C5(K, 2) ^ C6(K, 1) ^ C7(K, 0);
  565. K.q[0] = L0;
  566. K.q[1] = L1;
  567. K.q[2] = L2;
  568. K.q[3] = L3;
  569. K.q[4] = L4;
  570. K.q[5] = L5;
  571. K.q[6] = L6;
  572. K.q[7] = L7;
  573. L0 ^= C0(S, 0) ^ C1(S, 7) ^ C2(S, 6) ^ C3(S, 5) ^
  574. C4(S, 4) ^ C5(S, 3) ^ C6(S, 2) ^ C7(S, 1);
  575. L1 ^= C0(S, 1) ^ C1(S, 0) ^ C2(S, 7) ^ C3(S, 6) ^
  576. C4(S, 5) ^ C5(S, 4) ^ C6(S, 3) ^ C7(S, 2);
  577. L2 ^= C0(S, 2) ^ C1(S, 1) ^ C2(S, 0) ^ C3(S, 7) ^
  578. C4(S, 6) ^ C5(S, 5) ^ C6(S, 4) ^ C7(S, 3);
  579. L3 ^= C0(S, 3) ^ C1(S, 2) ^ C2(S, 1) ^ C3(S, 0) ^
  580. C4(S, 7) ^ C5(S, 6) ^ C6(S, 5) ^ C7(S, 4);
  581. L4 ^= C0(S, 4) ^ C1(S, 3) ^ C2(S, 2) ^ C3(S, 1) ^
  582. C4(S, 0) ^ C5(S, 7) ^ C6(S, 6) ^ C7(S, 5);
  583. L5 ^= C0(S, 5) ^ C1(S, 4) ^ C2(S, 3) ^ C3(S, 2) ^
  584. C4(S, 1) ^ C5(S, 0) ^ C6(S, 7) ^ C7(S, 6);
  585. L6 ^= C0(S, 6) ^ C1(S, 5) ^ C2(S, 4) ^ C3(S, 3) ^
  586. C4(S, 2) ^ C5(S, 1) ^ C6(S, 0) ^ C7(S, 7);
  587. L7 ^= C0(S, 7) ^ C1(S, 6) ^ C2(S, 5) ^ C3(S, 4) ^
  588. C4(S, 3) ^ C5(S, 2) ^ C6(S, 1) ^ C7(S, 0);
  589. S.q[0] = L0;
  590. S.q[1] = L1;
  591. S.q[2] = L2;
  592. S.q[3] = L3;
  593. S.q[4] = L4;
  594. S.q[5] = L5;
  595. S.q[6] = L6;
  596. S.q[7] = L7;
  597. # else
  598. L0 = C0(K, 0);
  599. L1 = C1(K, 0);
  600. L2 = C2(K, 0);
  601. L3 = C3(K, 0);
  602. L4 = C4(K, 0);
  603. L5 = C5(K, 0);
  604. L6 = C6(K, 0);
  605. L7 = C7(K, 0);
  606. L0 ^= RC[r];
  607. L1 ^= C0(K, 1);
  608. L2 ^= C1(K, 1);
  609. L3 ^= C2(K, 1);
  610. L4 ^= C3(K, 1);
  611. L5 ^= C4(K, 1);
  612. L6 ^= C5(K, 1);
  613. L7 ^= C6(K, 1);
  614. L0 ^= C7(K, 1);
  615. L2 ^= C0(K, 2);
  616. L3 ^= C1(K, 2);
  617. L4 ^= C2(K, 2);
  618. L5 ^= C3(K, 2);
  619. L6 ^= C4(K, 2);
  620. L7 ^= C5(K, 2);
  621. L0 ^= C6(K, 2);
  622. L1 ^= C7(K, 2);
  623. L3 ^= C0(K, 3);
  624. L4 ^= C1(K, 3);
  625. L5 ^= C2(K, 3);
  626. L6 ^= C3(K, 3);
  627. L7 ^= C4(K, 3);
  628. L0 ^= C5(K, 3);
  629. L1 ^= C6(K, 3);
  630. L2 ^= C7(K, 3);
  631. L4 ^= C0(K, 4);
  632. L5 ^= C1(K, 4);
  633. L6 ^= C2(K, 4);
  634. L7 ^= C3(K, 4);
  635. L0 ^= C4(K, 4);
  636. L1 ^= C5(K, 4);
  637. L2 ^= C6(K, 4);
  638. L3 ^= C7(K, 4);
  639. L5 ^= C0(K, 5);
  640. L6 ^= C1(K, 5);
  641. L7 ^= C2(K, 5);
  642. L0 ^= C3(K, 5);
  643. L1 ^= C4(K, 5);
  644. L2 ^= C5(K, 5);
  645. L3 ^= C6(K, 5);
  646. L4 ^= C7(K, 5);
  647. L6 ^= C0(K, 6);
  648. L7 ^= C1(K, 6);
  649. L0 ^= C2(K, 6);
  650. L1 ^= C3(K, 6);
  651. L2 ^= C4(K, 6);
  652. L3 ^= C5(K, 6);
  653. L4 ^= C6(K, 6);
  654. L5 ^= C7(K, 6);
  655. L7 ^= C0(K, 7);
  656. L0 ^= C1(K, 7);
  657. L1 ^= C2(K, 7);
  658. L2 ^= C3(K, 7);
  659. L3 ^= C4(K, 7);
  660. L4 ^= C5(K, 7);
  661. L5 ^= C6(K, 7);
  662. L6 ^= C7(K, 7);
  663. K.q[0] = L0;
  664. K.q[1] = L1;
  665. K.q[2] = L2;
  666. K.q[3] = L3;
  667. K.q[4] = L4;
  668. K.q[5] = L5;
  669. K.q[6] = L6;
  670. K.q[7] = L7;
  671. L0 ^= C0(S, 0);
  672. L1 ^= C1(S, 0);
  673. L2 ^= C2(S, 0);
  674. L3 ^= C3(S, 0);
  675. L4 ^= C4(S, 0);
  676. L5 ^= C5(S, 0);
  677. L6 ^= C6(S, 0);
  678. L7 ^= C7(S, 0);
  679. L1 ^= C0(S, 1);
  680. L2 ^= C1(S, 1);
  681. L3 ^= C2(S, 1);
  682. L4 ^= C3(S, 1);
  683. L5 ^= C4(S, 1);
  684. L6 ^= C5(S, 1);
  685. L7 ^= C6(S, 1);
  686. L0 ^= C7(S, 1);
  687. L2 ^= C0(S, 2);
  688. L3 ^= C1(S, 2);
  689. L4 ^= C2(S, 2);
  690. L5 ^= C3(S, 2);
  691. L6 ^= C4(S, 2);
  692. L7 ^= C5(S, 2);
  693. L0 ^= C6(S, 2);
  694. L1 ^= C7(S, 2);
  695. L3 ^= C0(S, 3);
  696. L4 ^= C1(S, 3);
  697. L5 ^= C2(S, 3);
  698. L6 ^= C3(S, 3);
  699. L7 ^= C4(S, 3);
  700. L0 ^= C5(S, 3);
  701. L1 ^= C6(S, 3);
  702. L2 ^= C7(S, 3);
  703. L4 ^= C0(S, 4);
  704. L5 ^= C1(S, 4);
  705. L6 ^= C2(S, 4);
  706. L7 ^= C3(S, 4);
  707. L0 ^= C4(S, 4);
  708. L1 ^= C5(S, 4);
  709. L2 ^= C6(S, 4);
  710. L3 ^= C7(S, 4);
  711. L5 ^= C0(S, 5);
  712. L6 ^= C1(S, 5);
  713. L7 ^= C2(S, 5);
  714. L0 ^= C3(S, 5);
  715. L1 ^= C4(S, 5);
  716. L2 ^= C5(S, 5);
  717. L3 ^= C6(S, 5);
  718. L4 ^= C7(S, 5);
  719. L6 ^= C0(S, 6);
  720. L7 ^= C1(S, 6);
  721. L0 ^= C2(S, 6);
  722. L1 ^= C3(S, 6);
  723. L2 ^= C4(S, 6);
  724. L3 ^= C5(S, 6);
  725. L4 ^= C6(S, 6);
  726. L5 ^= C7(S, 6);
  727. L7 ^= C0(S, 7);
  728. L0 ^= C1(S, 7);
  729. L1 ^= C2(S, 7);
  730. L2 ^= C3(S, 7);
  731. L3 ^= C4(S, 7);
  732. L4 ^= C5(S, 7);
  733. L5 ^= C6(S, 7);
  734. L6 ^= C7(S, 7);
  735. S.q[0] = L0;
  736. S.q[1] = L1;
  737. S.q[2] = L2;
  738. S.q[3] = L3;
  739. S.q[4] = L4;
  740. S.q[5] = L5;
  741. S.q[6] = L6;
  742. S.q[7] = L7;
  743. # endif
  744. }
  745. # ifdef STRICT_ALIGNMENT
  746. if ((size_t)p & 7) {
  747. int i;
  748. for (i = 0; i < 64; i++)
  749. H->c[i] ^= S.c[i] ^ p[i];
  750. } else
  751. # endif
  752. {
  753. const u64_aX *pa = (const u64_aX *)p;
  754. H->q[0] ^= S.q[0] ^ pa[0];
  755. H->q[1] ^= S.q[1] ^ pa[1];
  756. H->q[2] ^= S.q[2] ^ pa[2];
  757. H->q[3] ^= S.q[3] ^ pa[3];
  758. H->q[4] ^= S.q[4] ^ pa[4];
  759. H->q[5] ^= S.q[5] ^ pa[5];
  760. H->q[6] ^= S.q[6] ^ pa[6];
  761. H->q[7] ^= S.q[7] ^ pa[7];
  762. }
  763. #endif
  764. p += 64;
  765. } while (--n);
  766. }