sha256.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /* sha256.c - Functions to compute SHA256 and SHA224 message digest of files or
  2. memory blocks according to the NIST specification FIPS-180-2.
  3. Copyright (C) 2005-2006, 2008-2011 Free Software Foundation, Inc.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. /* Written by David Madore, considerably copypasting from
  15. Scott G. Miller's sha1.c
  16. */
  17. #include <config.h>
  18. #include "sha256.h"
  19. #include <stddef.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #if USE_UNLOCKED_IO
  23. # include "unlocked-io.h"
  24. #endif
  25. #ifdef WORDS_BIGENDIAN
  26. # define SWAP(n) (n)
  27. #else
  28. # define SWAP(n) \
  29. (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
  30. #endif
  31. #define BLOCKSIZE 32768
  32. #if BLOCKSIZE % 64 != 0
  33. # error "invalid BLOCKSIZE"
  34. #endif
  35. /* This array contains the bytes used to pad the buffer to the next
  36. 64-byte boundary. */
  37. static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
  38. /*
  39. Takes a pointer to a 256 bit block of data (eight 32 bit ints) and
  40. initializes it to the start constants of the SHA256 algorithm. This
  41. must be called before using hash in the call to sha256_hash
  42. */
  43. void
  44. sha256_init_ctx (struct sha256_ctx *ctx)
  45. {
  46. ctx->state[0] = 0x6a09e667UL;
  47. ctx->state[1] = 0xbb67ae85UL;
  48. ctx->state[2] = 0x3c6ef372UL;
  49. ctx->state[3] = 0xa54ff53aUL;
  50. ctx->state[4] = 0x510e527fUL;
  51. ctx->state[5] = 0x9b05688cUL;
  52. ctx->state[6] = 0x1f83d9abUL;
  53. ctx->state[7] = 0x5be0cd19UL;
  54. ctx->total[0] = ctx->total[1] = 0;
  55. ctx->buflen = 0;
  56. }
  57. void
  58. sha224_init_ctx (struct sha256_ctx *ctx)
  59. {
  60. ctx->state[0] = 0xc1059ed8UL;
  61. ctx->state[1] = 0x367cd507UL;
  62. ctx->state[2] = 0x3070dd17UL;
  63. ctx->state[3] = 0xf70e5939UL;
  64. ctx->state[4] = 0xffc00b31UL;
  65. ctx->state[5] = 0x68581511UL;
  66. ctx->state[6] = 0x64f98fa7UL;
  67. ctx->state[7] = 0xbefa4fa4UL;
  68. ctx->total[0] = ctx->total[1] = 0;
  69. ctx->buflen = 0;
  70. }
  71. /* Copy the value from v into the memory location pointed to by *cp,
  72. If your architecture allows unaligned access this is equivalent to
  73. * (uint32_t *) cp = v */
  74. static inline void
  75. set_uint32 (char *cp, uint32_t v)
  76. {
  77. memcpy (cp, &v, sizeof v);
  78. }
  79. /* Put result from CTX in first 32 bytes following RESBUF. The result
  80. must be in little endian byte order. */
  81. void *
  82. sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf)
  83. {
  84. int i;
  85. char *r = resbuf;
  86. for (i = 0; i < 8; i++)
  87. set_uint32 (r + i * sizeof ctx->state[0], SWAP (ctx->state[i]));
  88. return resbuf;
  89. }
  90. void *
  91. sha224_read_ctx (const struct sha256_ctx *ctx, void *resbuf)
  92. {
  93. int i;
  94. char *r = resbuf;
  95. for (i = 0; i < 7; i++)
  96. set_uint32 (r + i * sizeof ctx->state[0], SWAP (ctx->state[i]));
  97. return resbuf;
  98. }
  99. /* Process the remaining bytes in the internal buffer and the usual
  100. prolog according to the standard and write the result to RESBUF. */
  101. static void
  102. sha256_conclude_ctx (struct sha256_ctx *ctx)
  103. {
  104. /* Take yet unprocessed bytes into account. */
  105. size_t bytes = ctx->buflen;
  106. size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;
  107. /* Now count remaining bytes. */
  108. ctx->total[0] += bytes;
  109. if (ctx->total[0] < bytes)
  110. ++ctx->total[1];
  111. /* Put the 64-bit file length in *bits* at the end of the buffer.
  112. Use set_uint32 rather than a simple assignment, to avoid risk of
  113. unaligned access. */
  114. set_uint32 ((char *) &ctx->buffer[size - 2],
  115. SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29)));
  116. set_uint32 ((char *) &ctx->buffer[size - 1],
  117. SWAP (ctx->total[0] << 3));
  118. memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes);
  119. /* Process last bytes. */
  120. sha256_process_block (ctx->buffer, size * 4, ctx);
  121. }
  122. void *
  123. sha256_finish_ctx (struct sha256_ctx *ctx, void *resbuf)
  124. {
  125. sha256_conclude_ctx (ctx);
  126. return sha256_read_ctx (ctx, resbuf);
  127. }
  128. void *
  129. sha224_finish_ctx (struct sha256_ctx *ctx, void *resbuf)
  130. {
  131. sha256_conclude_ctx (ctx);
  132. return sha224_read_ctx (ctx, resbuf);
  133. }
  134. /* Compute SHA256 message digest for bytes read from STREAM. The
  135. resulting message digest number will be written into the 32 bytes
  136. beginning at RESBLOCK. */
  137. int
  138. sha256_stream (FILE *stream, void *resblock)
  139. {
  140. struct sha256_ctx ctx;
  141. size_t sum;
  142. char *buffer = malloc (BLOCKSIZE + 72);
  143. if (!buffer)
  144. return 1;
  145. /* Initialize the computation context. */
  146. sha256_init_ctx (&ctx);
  147. /* Iterate over full file contents. */
  148. while (1)
  149. {
  150. /* We read the file in blocks of BLOCKSIZE bytes. One call of the
  151. computation function processes the whole buffer so that with the
  152. next round of the loop another block can be read. */
  153. size_t n;
  154. sum = 0;
  155. /* Read block. Take care for partial reads. */
  156. while (1)
  157. {
  158. n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
  159. sum += n;
  160. if (sum == BLOCKSIZE)
  161. break;
  162. if (n == 0)
  163. {
  164. /* Check for the error flag IFF N == 0, so that we don't
  165. exit the loop after a partial read due to e.g., EAGAIN
  166. or EWOULDBLOCK. */
  167. if (ferror (stream))
  168. {
  169. free (buffer);
  170. return 1;
  171. }
  172. goto process_partial_block;
  173. }
  174. /* We've read at least one byte, so ignore errors. But always
  175. check for EOF, since feof may be true even though N > 0.
  176. Otherwise, we could end up calling fread after EOF. */
  177. if (feof (stream))
  178. goto process_partial_block;
  179. }
  180. /* Process buffer with BLOCKSIZE bytes. Note that
  181. BLOCKSIZE % 64 == 0
  182. */
  183. sha256_process_block (buffer, BLOCKSIZE, &ctx);
  184. }
  185. process_partial_block:;
  186. /* Process any remaining bytes. */
  187. if (sum > 0)
  188. sha256_process_bytes (buffer, sum, &ctx);
  189. /* Construct result in desired memory. */
  190. sha256_finish_ctx (&ctx, resblock);
  191. free (buffer);
  192. return 0;
  193. }
  194. /* FIXME: Avoid code duplication */
  195. int
  196. sha224_stream (FILE *stream, void *resblock)
  197. {
  198. struct sha256_ctx ctx;
  199. size_t sum;
  200. char *buffer = malloc (BLOCKSIZE + 72);
  201. if (!buffer)
  202. return 1;
  203. /* Initialize the computation context. */
  204. sha224_init_ctx (&ctx);
  205. /* Iterate over full file contents. */
  206. while (1)
  207. {
  208. /* We read the file in blocks of BLOCKSIZE bytes. One call of the
  209. computation function processes the whole buffer so that with the
  210. next round of the loop another block can be read. */
  211. size_t n;
  212. sum = 0;
  213. /* Read block. Take care for partial reads. */
  214. while (1)
  215. {
  216. n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
  217. sum += n;
  218. if (sum == BLOCKSIZE)
  219. break;
  220. if (n == 0)
  221. {
  222. /* Check for the error flag IFF N == 0, so that we don't
  223. exit the loop after a partial read due to e.g., EAGAIN
  224. or EWOULDBLOCK. */
  225. if (ferror (stream))
  226. {
  227. free (buffer);
  228. return 1;
  229. }
  230. goto process_partial_block;
  231. }
  232. /* We've read at least one byte, so ignore errors. But always
  233. check for EOF, since feof may be true even though N > 0.
  234. Otherwise, we could end up calling fread after EOF. */
  235. if (feof (stream))
  236. goto process_partial_block;
  237. }
  238. /* Process buffer with BLOCKSIZE bytes. Note that
  239. BLOCKSIZE % 64 == 0
  240. */
  241. sha256_process_block (buffer, BLOCKSIZE, &ctx);
  242. }
  243. process_partial_block:;
  244. /* Process any remaining bytes. */
  245. if (sum > 0)
  246. sha256_process_bytes (buffer, sum, &ctx);
  247. /* Construct result in desired memory. */
  248. sha224_finish_ctx (&ctx, resblock);
  249. free (buffer);
  250. return 0;
  251. }
  252. /* Compute SHA512 message digest for LEN bytes beginning at BUFFER. The
  253. result is always in little endian byte order, so that a byte-wise
  254. output yields to the wanted ASCII representation of the message
  255. digest. */
  256. void *
  257. sha256_buffer (const char *buffer, size_t len, void *resblock)
  258. {
  259. struct sha256_ctx ctx;
  260. /* Initialize the computation context. */
  261. sha256_init_ctx (&ctx);
  262. /* Process whole buffer but last len % 64 bytes. */
  263. sha256_process_bytes (buffer, len, &ctx);
  264. /* Put result in desired memory area. */
  265. return sha256_finish_ctx (&ctx, resblock);
  266. }
  267. void *
  268. sha224_buffer (const char *buffer, size_t len, void *resblock)
  269. {
  270. struct sha256_ctx ctx;
  271. /* Initialize the computation context. */
  272. sha224_init_ctx (&ctx);
  273. /* Process whole buffer but last len % 64 bytes. */
  274. sha256_process_bytes (buffer, len, &ctx);
  275. /* Put result in desired memory area. */
  276. return sha224_finish_ctx (&ctx, resblock);
  277. }
  278. void
  279. sha256_process_bytes (const void *buffer, size_t len, struct sha256_ctx *ctx)
  280. {
  281. /* When we already have some bits in our internal buffer concatenate
  282. both inputs first. */
  283. if (ctx->buflen != 0)
  284. {
  285. size_t left_over = ctx->buflen;
  286. size_t add = 128 - left_over > len ? len : 128 - left_over;
  287. memcpy (&((char *) ctx->buffer)[left_over], buffer, add);
  288. ctx->buflen += add;
  289. if (ctx->buflen > 64)
  290. {
  291. sha256_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
  292. ctx->buflen &= 63;
  293. /* The regions in the following copy operation cannot overlap. */
  294. memcpy (ctx->buffer,
  295. &((char *) ctx->buffer)[(left_over + add) & ~63],
  296. ctx->buflen);
  297. }
  298. buffer = (const char *) buffer + add;
  299. len -= add;
  300. }
  301. /* Process available complete blocks. */
  302. if (len >= 64)
  303. {
  304. #if !_STRING_ARCH_unaligned
  305. # define alignof(type) offsetof (struct { char c; type x; }, x)
  306. # define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
  307. if (UNALIGNED_P (buffer))
  308. while (len > 64)
  309. {
  310. sha256_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
  311. buffer = (const char *) buffer + 64;
  312. len -= 64;
  313. }
  314. else
  315. #endif
  316. {
  317. sha256_process_block (buffer, len & ~63, ctx);
  318. buffer = (const char *) buffer + (len & ~63);
  319. len &= 63;
  320. }
  321. }
  322. /* Move remaining bytes in internal buffer. */
  323. if (len > 0)
  324. {
  325. size_t left_over = ctx->buflen;
  326. memcpy (&((char *) ctx->buffer)[left_over], buffer, len);
  327. left_over += len;
  328. if (left_over >= 64)
  329. {
  330. sha256_process_block (ctx->buffer, 64, ctx);
  331. left_over -= 64;
  332. memcpy (ctx->buffer, &ctx->buffer[16], left_over);
  333. }
  334. ctx->buflen = left_over;
  335. }
  336. }
  337. /* --- Code below is the primary difference between sha1.c and sha256.c --- */
  338. /* SHA256 round constants */
  339. #define K(I) sha256_round_constants[I]
  340. static const uint32_t sha256_round_constants[64] = {
  341. 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL,
  342. 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL,
  343. 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL,
  344. 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL,
  345. 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
  346. 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL,
  347. 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL,
  348. 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL,
  349. 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL,
  350. 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
  351. 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL,
  352. 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL,
  353. 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL,
  354. 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL,
  355. 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
  356. 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL,
  357. };
  358. /* Round functions. */
  359. #define F2(A,B,C) ( ( A & B ) | ( C & ( A | B ) ) )
  360. #define F1(E,F,G) ( G ^ ( E & ( F ^ G ) ) )
  361. /* Process LEN bytes of BUFFER, accumulating context into CTX.
  362. It is assumed that LEN % 64 == 0.
  363. Most of this code comes from GnuPG's cipher/sha1.c. */
  364. void
  365. sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx)
  366. {
  367. const uint32_t *words = buffer;
  368. size_t nwords = len / sizeof (uint32_t);
  369. const uint32_t *endp = words + nwords;
  370. uint32_t x[16];
  371. uint32_t a = ctx->state[0];
  372. uint32_t b = ctx->state[1];
  373. uint32_t c = ctx->state[2];
  374. uint32_t d = ctx->state[3];
  375. uint32_t e = ctx->state[4];
  376. uint32_t f = ctx->state[5];
  377. uint32_t g = ctx->state[6];
  378. uint32_t h = ctx->state[7];
  379. /* First increment the byte count. FIPS PUB 180-2 specifies the possible
  380. length of the file up to 2^64 bits. Here we only compute the
  381. number of bytes. Do a double word increment. */
  382. ctx->total[0] += len;
  383. if (ctx->total[0] < len)
  384. ++ctx->total[1];
  385. #define rol(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
  386. #define S0(x) (rol(x,25)^rol(x,14)^(x>>3))
  387. #define S1(x) (rol(x,15)^rol(x,13)^(x>>10))
  388. #define SS0(x) (rol(x,30)^rol(x,19)^rol(x,10))
  389. #define SS1(x) (rol(x,26)^rol(x,21)^rol(x,7))
  390. #define M(I) ( tm = S1(x[(I-2)&0x0f]) + x[(I-7)&0x0f] \
  391. + S0(x[(I-15)&0x0f]) + x[I&0x0f] \
  392. , x[I&0x0f] = tm )
  393. #define R(A,B,C,D,E,F,G,H,K,M) do { t0 = SS0(A) + F2(A,B,C); \
  394. t1 = H + SS1(E) \
  395. + F1(E,F,G) \
  396. + K \
  397. + M; \
  398. D += t1; H = t0 + t1; \
  399. } while(0)
  400. while (words < endp)
  401. {
  402. uint32_t tm;
  403. uint32_t t0, t1;
  404. int t;
  405. /* FIXME: see sha1.c for a better implementation. */
  406. for (t = 0; t < 16; t++)
  407. {
  408. x[t] = SWAP (*words);
  409. words++;
  410. }
  411. R( a, b, c, d, e, f, g, h, K( 0), x[ 0] );
  412. R( h, a, b, c, d, e, f, g, K( 1), x[ 1] );
  413. R( g, h, a, b, c, d, e, f, K( 2), x[ 2] );
  414. R( f, g, h, a, b, c, d, e, K( 3), x[ 3] );
  415. R( e, f, g, h, a, b, c, d, K( 4), x[ 4] );
  416. R( d, e, f, g, h, a, b, c, K( 5), x[ 5] );
  417. R( c, d, e, f, g, h, a, b, K( 6), x[ 6] );
  418. R( b, c, d, e, f, g, h, a, K( 7), x[ 7] );
  419. R( a, b, c, d, e, f, g, h, K( 8), x[ 8] );
  420. R( h, a, b, c, d, e, f, g, K( 9), x[ 9] );
  421. R( g, h, a, b, c, d, e, f, K(10), x[10] );
  422. R( f, g, h, a, b, c, d, e, K(11), x[11] );
  423. R( e, f, g, h, a, b, c, d, K(12), x[12] );
  424. R( d, e, f, g, h, a, b, c, K(13), x[13] );
  425. R( c, d, e, f, g, h, a, b, K(14), x[14] );
  426. R( b, c, d, e, f, g, h, a, K(15), x[15] );
  427. R( a, b, c, d, e, f, g, h, K(16), M(16) );
  428. R( h, a, b, c, d, e, f, g, K(17), M(17) );
  429. R( g, h, a, b, c, d, e, f, K(18), M(18) );
  430. R( f, g, h, a, b, c, d, e, K(19), M(19) );
  431. R( e, f, g, h, a, b, c, d, K(20), M(20) );
  432. R( d, e, f, g, h, a, b, c, K(21), M(21) );
  433. R( c, d, e, f, g, h, a, b, K(22), M(22) );
  434. R( b, c, d, e, f, g, h, a, K(23), M(23) );
  435. R( a, b, c, d, e, f, g, h, K(24), M(24) );
  436. R( h, a, b, c, d, e, f, g, K(25), M(25) );
  437. R( g, h, a, b, c, d, e, f, K(26), M(26) );
  438. R( f, g, h, a, b, c, d, e, K(27), M(27) );
  439. R( e, f, g, h, a, b, c, d, K(28), M(28) );
  440. R( d, e, f, g, h, a, b, c, K(29), M(29) );
  441. R( c, d, e, f, g, h, a, b, K(30), M(30) );
  442. R( b, c, d, e, f, g, h, a, K(31), M(31) );
  443. R( a, b, c, d, e, f, g, h, K(32), M(32) );
  444. R( h, a, b, c, d, e, f, g, K(33), M(33) );
  445. R( g, h, a, b, c, d, e, f, K(34), M(34) );
  446. R( f, g, h, a, b, c, d, e, K(35), M(35) );
  447. R( e, f, g, h, a, b, c, d, K(36), M(36) );
  448. R( d, e, f, g, h, a, b, c, K(37), M(37) );
  449. R( c, d, e, f, g, h, a, b, K(38), M(38) );
  450. R( b, c, d, e, f, g, h, a, K(39), M(39) );
  451. R( a, b, c, d, e, f, g, h, K(40), M(40) );
  452. R( h, a, b, c, d, e, f, g, K(41), M(41) );
  453. R( g, h, a, b, c, d, e, f, K(42), M(42) );
  454. R( f, g, h, a, b, c, d, e, K(43), M(43) );
  455. R( e, f, g, h, a, b, c, d, K(44), M(44) );
  456. R( d, e, f, g, h, a, b, c, K(45), M(45) );
  457. R( c, d, e, f, g, h, a, b, K(46), M(46) );
  458. R( b, c, d, e, f, g, h, a, K(47), M(47) );
  459. R( a, b, c, d, e, f, g, h, K(48), M(48) );
  460. R( h, a, b, c, d, e, f, g, K(49), M(49) );
  461. R( g, h, a, b, c, d, e, f, K(50), M(50) );
  462. R( f, g, h, a, b, c, d, e, K(51), M(51) );
  463. R( e, f, g, h, a, b, c, d, K(52), M(52) );
  464. R( d, e, f, g, h, a, b, c, K(53), M(53) );
  465. R( c, d, e, f, g, h, a, b, K(54), M(54) );
  466. R( b, c, d, e, f, g, h, a, K(55), M(55) );
  467. R( a, b, c, d, e, f, g, h, K(56), M(56) );
  468. R( h, a, b, c, d, e, f, g, K(57), M(57) );
  469. R( g, h, a, b, c, d, e, f, K(58), M(58) );
  470. R( f, g, h, a, b, c, d, e, K(59), M(59) );
  471. R( e, f, g, h, a, b, c, d, K(60), M(60) );
  472. R( d, e, f, g, h, a, b, c, K(61), M(61) );
  473. R( c, d, e, f, g, h, a, b, K(62), M(62) );
  474. R( b, c, d, e, f, g, h, a, K(63), M(63) );
  475. a = ctx->state[0] += a;
  476. b = ctx->state[1] += b;
  477. c = ctx->state[2] += c;
  478. d = ctx->state[3] += d;
  479. e = ctx->state[4] += e;
  480. f = ctx->state[5] += f;
  481. g = ctx->state[6] += g;
  482. h = ctx->state[7] += h;
  483. }
  484. }