sha256_altivec_4way.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. // Copyright 2010 Satoshi Nakamoto
  2. // Copyright 2011 Gilles Risch
  3. // Copyright 2012-2013 Luke Dashjr
  4. // Distributed under the MIT/X11 software license, see the accompanying
  5. // file license.txt or http://www.opensource.org/licenses/mit-license.php.
  6. // 4-way 128-bit Altivec SHA-256,
  7. // based on tcatm's 4-way 128-bit SSE2 SHA-256
  8. //
  9. #include "config.h"
  10. #include "driver-cpu.h"
  11. #ifdef WANT_ALTIVEC_4WAY
  12. #include <stdbool.h>
  13. #include <string.h>
  14. #include <assert.h>
  15. //#include <altivec.h>
  16. #include <stdint.h>
  17. #include <stdio.h>
  18. #define NPAR 32
  19. static void DoubleBlockSHA256(const void* pin, void* pout, const void* pinit, unsigned int hash[8][NPAR], const void* init2);
  20. static const unsigned int sha256_consts[] = {
  21. 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, /* 0 */
  22. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  23. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, /* 8 */
  24. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  25. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, /* 16 */
  26. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  27. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, /* 24 */
  28. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  29. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, /* 32 */
  30. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  31. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, /* 40 */
  32. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  33. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, /* 48 */
  34. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  35. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, /* 56 */
  36. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
  37. };
  38. static inline vector unsigned int Ch(const vector unsigned int b, const vector unsigned int c, const vector unsigned int d) {
  39. return vec_sel(d,c,b);
  40. }
  41. static inline vector unsigned int Maj(const vector unsigned int b, const vector unsigned int c, const vector unsigned int d) {
  42. return vec_sel(b,c, vec_xor(b,d));
  43. }
  44. /* RotateRight(x, n) := RotateLeft(x, 32-n) */
  45. /* SHA256 Functions */
  46. #define BIGSIGMA0_256(x) (vec_xor(vec_xor(vec_rl((x), (vector unsigned int)(32-2)),vec_rl((x), (vector unsigned int)(32-13))),vec_rl((x), (vector unsigned int)(32-22))))
  47. #define BIGSIGMA1_256(x) (vec_xor(vec_xor(vec_rl((x), (vector unsigned int)(32-6)),vec_rl((x), (vector unsigned int)(32-11))),vec_rl((x), (vector unsigned int)(32-25))))
  48. #define SIGMA0_256(x) (vec_xor(vec_xor(vec_rl((x), (vector unsigned int)(32- 7)),vec_rl((x), (vector unsigned int)(32-18))), vec_sr((x), (vector unsigned int)(3 ))))
  49. #define SIGMA1_256(x) (vec_xor(vec_xor(vec_rl((x), (vector unsigned int)(32-17)),vec_rl((x), (vector unsigned int)(32-19))), vec_sr((x), (vector unsigned int)(10))))
  50. #define add4(x0, x1, x2, x3) vec_add(vec_add(x0, x1),vec_add( x2,x3))
  51. #define add5(x0, x1, x2, x3, x4) vec_add(add4(x0, x1, x2, x3), x4)
  52. #define SHA256ROUND(a, b, c, d, e, f, g, h, i, w) \
  53. T1 = add5(h, BIGSIGMA1_256(e), Ch(e, f, g), (vector unsigned int)(sha256_consts[i],sha256_consts[i],sha256_consts[i],sha256_consts[i]), w); \
  54. d = vec_add(d, T1); \
  55. h = vec_add(T1, vec_add(BIGSIGMA0_256(a), Maj(a, b, c)));
  56. static const unsigned int pSHA256InitState[8] =
  57. {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};
  58. bool ScanHash_altivec_4way(struct thr_info * const thr, struct work * const work,
  59. uint32_t max_nonce, uint32_t *last_nonce,
  60. uint32_t nonce)
  61. {
  62. const uint8_t * const pmidstate = work->midstate;
  63. uint8_t *pdata = work->data;
  64. uint8_t hash1[0x40];
  65. memcpy(hash1, hash1_init, sizeof(hash1));
  66. uint8_t * const phash = work->hash;
  67. const uint8_t * const ptarget = work->target;
  68. uint32_t *hash32 = (uint32_t *)phash;
  69. unsigned int *nNonce_p = (unsigned int*)(pdata + 76);
  70. pdata += 64;
  71. for (;;)
  72. {
  73. unsigned int thash[9][NPAR] __attribute__((aligned(128)));
  74. int j;
  75. *nNonce_p = nonce;
  76. DoubleBlockSHA256(pdata, phash1, pmidstate, thash, pSHA256InitState);
  77. for (j = 0; j < NPAR; j++)
  78. {
  79. if (unlikely(thash[7][j] == 0))
  80. {
  81. int i;
  82. for (i = 0; i < 32/4; i++)
  83. ((unsigned int*)phash)[i] = thash[i][j];
  84. if (unlikely(hash32[7] == 0 && fulltest(phash, ptarget))) {
  85. nonce += j;
  86. *last_nonce = nonce;
  87. *nNonce_p = nonce;
  88. return true;
  89. }
  90. }
  91. }
  92. if ((nonce >= max_nonce) || thr->work_restart)
  93. {
  94. *last_nonce = nonce;
  95. return false;
  96. }
  97. nonce += NPAR;
  98. }
  99. }
  100. static void DoubleBlockSHA256(const void* pin, void* pad, const void *pre, unsigned int thash[9][NPAR], const void *init)
  101. {
  102. unsigned int* In = (unsigned int*)pin;
  103. unsigned int* Pad = (unsigned int*)pad;
  104. unsigned int* hPre = (unsigned int*)pre;
  105. unsigned int* hInit = (unsigned int*)init;
  106. unsigned int /* i, j, */ k;
  107. /* vectors used in calculation */
  108. vector unsigned int w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15;
  109. vector unsigned int T1;
  110. vector unsigned int a, b, c, d, e, f, g, h;
  111. vector unsigned int nonce, preNonce;
  112. /* nonce offset for vector */
  113. vector unsigned int offset = (vector unsigned int)(0, 1, 2, 3);
  114. preNonce = vec_add((vector unsigned int)(In[3],In[3],In[3],In[3]), offset);
  115. for(k = 0; k<NPAR; k+=4)
  116. {
  117. w0 = (vector unsigned int)(In[0],In[0],In[0],In[0]);
  118. w1 = (vector unsigned int)(In[1],In[1],In[1],In[1]);
  119. w2 = (vector unsigned int)(In[2],In[2],In[2],In[2]);
  120. //w3 = (vector unsigned int)(In[3],In[3],In[3],In[3]); nonce will be later hacked into the hash
  121. w4 = (vector unsigned int)(In[4],In[4],In[4],In[4]);
  122. w5 = (vector unsigned int)(In[5],In[5],In[5],In[5]);
  123. w6 = (vector unsigned int)(In[6],In[6],In[6],In[6]);
  124. w7 = (vector unsigned int)(In[7],In[7],In[7],In[7]);
  125. w8 = (vector unsigned int)(In[8],In[8],In[8],In[8]);
  126. w9 = (vector unsigned int)(In[9],In[9],In[9],In[9]);
  127. w10 = (vector unsigned int)(In[10],In[10],In[10],In[10]);
  128. w11 = (vector unsigned int)(In[11],In[11],In[11],In[11]);
  129. w12 = (vector unsigned int)(In[12],In[12],In[12],In[12]);
  130. w13 = (vector unsigned int)(In[13],In[13],In[13],In[13]);
  131. w14 = (vector unsigned int)(In[14],In[14],In[14],In[14]);
  132. w15 = (vector unsigned int)(In[15],In[15],In[15],In[15]);
  133. /* hack nonce into lowest byte of w3 */
  134. nonce = vec_add(preNonce, (vector unsigned int)(k,k,k,k));
  135. w3 = nonce;
  136. //printf ("W3: %08vlx\n", w3);
  137. a = (vector unsigned int)(hPre[0],hPre[0],hPre[0],hPre[0]);
  138. b = (vector unsigned int)(hPre[1],hPre[1],hPre[1],hPre[1]);
  139. c = (vector unsigned int)(hPre[2],hPre[2],hPre[2],hPre[2]);
  140. d = (vector unsigned int)(hPre[3],hPre[3],hPre[3],hPre[3]);
  141. e = (vector unsigned int)(hPre[4],hPre[4],hPre[4],hPre[4]);
  142. f = (vector unsigned int)(hPre[5],hPre[5],hPre[5],hPre[5]);
  143. g = (vector unsigned int)(hPre[6],hPre[6],hPre[6],hPre[6]);
  144. h = (vector unsigned int)(hPre[7],hPre[7],hPre[7],hPre[7]);
  145. SHA256ROUND(a, b, c, d, e, f, g, h, 0, w0);
  146. SHA256ROUND(h, a, b, c, d, e, f, g, 1, w1);
  147. SHA256ROUND(g, h, a, b, c, d, e, f, 2, w2);
  148. SHA256ROUND(f, g, h, a, b, c, d, e, 3, w3);
  149. SHA256ROUND(e, f, g, h, a, b, c, d, 4, w4);
  150. SHA256ROUND(d, e, f, g, h, a, b, c, 5, w5);
  151. SHA256ROUND(c, d, e, f, g, h, a, b, 6, w6);
  152. SHA256ROUND(b, c, d, e, f, g, h, a, 7, w7);
  153. SHA256ROUND(a, b, c, d, e, f, g, h, 8, w8);
  154. SHA256ROUND(h, a, b, c, d, e, f, g, 9, w9);
  155. SHA256ROUND(g, h, a, b, c, d, e, f, 10, w10);
  156. SHA256ROUND(f, g, h, a, b, c, d, e, 11, w11);
  157. SHA256ROUND(e, f, g, h, a, b, c, d, 12, w12);
  158. SHA256ROUND(d, e, f, g, h, a, b, c, 13, w13);
  159. SHA256ROUND(c, d, e, f, g, h, a, b, 14, w14);
  160. SHA256ROUND(b, c, d, e, f, g, h, a, 15, w15);
  161. w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);
  162. SHA256ROUND(a, b, c, d, e, f, g, h, 16, w0);
  163. w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);
  164. SHA256ROUND(h, a, b, c, d, e, f, g, 17, w1);
  165. w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);
  166. SHA256ROUND(g, h, a, b, c, d, e, f, 18, w2);
  167. w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);
  168. SHA256ROUND(f, g, h, a, b, c, d, e, 19, w3);
  169. w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);
  170. SHA256ROUND(e, f, g, h, a, b, c, d, 20, w4);
  171. w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);
  172. SHA256ROUND(d, e, f, g, h, a, b, c, 21, w5);
  173. w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);
  174. SHA256ROUND(c, d, e, f, g, h, a, b, 22, w6);
  175. w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);
  176. SHA256ROUND(b, c, d, e, f, g, h, a, 23, w7);
  177. w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);
  178. SHA256ROUND(a, b, c, d, e, f, g, h, 24, w8);
  179. w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);
  180. SHA256ROUND(h, a, b, c, d, e, f, g, 25, w9);
  181. w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);
  182. SHA256ROUND(g, h, a, b, c, d, e, f, 26, w10);
  183. w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);
  184. SHA256ROUND(f, g, h, a, b, c, d, e, 27, w11);
  185. w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);
  186. SHA256ROUND(e, f, g, h, a, b, c, d, 28, w12);
  187. w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);
  188. SHA256ROUND(d, e, f, g, h, a, b, c, 29, w13);
  189. w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);
  190. SHA256ROUND(c, d, e, f, g, h, a, b, 30, w14);
  191. w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);
  192. SHA256ROUND(b, c, d, e, f, g, h, a, 31, w15);
  193. w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);
  194. SHA256ROUND(a, b, c, d, e, f, g, h, 32, w0);
  195. w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);
  196. SHA256ROUND(h, a, b, c, d, e, f, g, 33, w1);
  197. w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);
  198. SHA256ROUND(g, h, a, b, c, d, e, f, 34, w2);
  199. w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);
  200. SHA256ROUND(f, g, h, a, b, c, d, e, 35, w3);
  201. w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);
  202. SHA256ROUND(e, f, g, h, a, b, c, d, 36, w4);
  203. w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);
  204. SHA256ROUND(d, e, f, g, h, a, b, c, 37, w5);
  205. w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);
  206. SHA256ROUND(c, d, e, f, g, h, a, b, 38, w6);
  207. w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);
  208. SHA256ROUND(b, c, d, e, f, g, h, a, 39, w7);
  209. w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);
  210. SHA256ROUND(a, b, c, d, e, f, g, h, 40, w8);
  211. w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);
  212. SHA256ROUND(h, a, b, c, d, e, f, g, 41, w9);
  213. w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);
  214. SHA256ROUND(g, h, a, b, c, d, e, f, 42, w10);
  215. w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);
  216. SHA256ROUND(f, g, h, a, b, c, d, e, 43, w11);
  217. w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);
  218. SHA256ROUND(e, f, g, h, a, b, c, d, 44, w12);
  219. w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);
  220. SHA256ROUND(d, e, f, g, h, a, b, c, 45, w13);
  221. w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);
  222. SHA256ROUND(c, d, e, f, g, h, a, b, 46, w14);
  223. w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);
  224. SHA256ROUND(b, c, d, e, f, g, h, a, 47, w15);
  225. w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);
  226. SHA256ROUND(a, b, c, d, e, f, g, h, 48, w0);
  227. w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);
  228. SHA256ROUND(h, a, b, c, d, e, f, g, 49, w1);
  229. w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);
  230. SHA256ROUND(g, h, a, b, c, d, e, f, 50, w2);
  231. w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);
  232. SHA256ROUND(f, g, h, a, b, c, d, e, 51, w3);
  233. w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);
  234. SHA256ROUND(e, f, g, h, a, b, c, d, 52, w4);
  235. w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);
  236. SHA256ROUND(d, e, f, g, h, a, b, c, 53, w5);
  237. w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);
  238. SHA256ROUND(c, d, e, f, g, h, a, b, 54, w6);
  239. w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);
  240. SHA256ROUND(b, c, d, e, f, g, h, a, 55, w7);
  241. w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);
  242. SHA256ROUND(a, b, c, d, e, f, g, h, 56, w8);
  243. w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);
  244. SHA256ROUND(h, a, b, c, d, e, f, g, 57, w9);
  245. w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);
  246. SHA256ROUND(g, h, a, b, c, d, e, f, 58, w10);
  247. w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);
  248. SHA256ROUND(f, g, h, a, b, c, d, e, 59, w11);
  249. w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);
  250. SHA256ROUND(e, f, g, h, a, b, c, d, 60, w12);
  251. w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);
  252. SHA256ROUND(d, e, f, g, h, a, b, c, 61, w13);
  253. w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);
  254. SHA256ROUND(c, d, e, f, g, h, a, b, 62, w14);
  255. w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);
  256. SHA256ROUND(b, c, d, e, f, g, h, a, 63, w15);
  257. #define store_load(x, i, dest) \
  258. T1 = (vector unsigned int)((hPre)[i],(hPre)[i],(hPre)[i],(hPre)[i]); \
  259. dest = vec_add(T1, x);
  260. store_load(a, 0, w0);
  261. store_load(b, 1, w1);
  262. store_load(c, 2, w2);
  263. store_load(d, 3, w3);
  264. store_load(e, 4, w4);
  265. store_load(f, 5, w5);
  266. store_load(g, 6, w6);
  267. store_load(h, 7, w7);
  268. /* end of first SHA256 round */
  269. w8 = (vector unsigned int)(Pad[8],Pad[8],Pad[8],Pad[8]);
  270. w9 = (vector unsigned int)(Pad[9],Pad[9],Pad[9],Pad[9]);
  271. w10 = (vector unsigned int)(Pad[10],Pad[10],Pad[10],Pad[10]);
  272. w11 = (vector unsigned int)(Pad[11],Pad[11],Pad[11],Pad[11]);
  273. w12 = (vector unsigned int)(Pad[12],Pad[12],Pad[12],Pad[12]);
  274. w13 = (vector unsigned int)(Pad[13],Pad[13],Pad[13],Pad[13]);
  275. w14 = (vector unsigned int)(Pad[14],Pad[14],Pad[14],Pad[14]);
  276. w15 = (vector unsigned int)(Pad[15],Pad[15],Pad[15],Pad[15]);
  277. a = (vector unsigned int)(hInit[0],hInit[0],hInit[0],hInit[0]);
  278. b = (vector unsigned int)(hInit[1],hInit[1],hInit[1],hInit[1]);
  279. c = (vector unsigned int)(hInit[2],hInit[2],hInit[2],hInit[2]);
  280. d = (vector unsigned int)(hInit[3],hInit[3],hInit[3],hInit[3]);
  281. e = (vector unsigned int)(hInit[4],hInit[4],hInit[4],hInit[4]);
  282. f = (vector unsigned int)(hInit[5],hInit[5],hInit[5],hInit[5]);
  283. g = (vector unsigned int)(hInit[6],hInit[6],hInit[6],hInit[6]);
  284. h = (vector unsigned int)(hInit[7],hInit[7],hInit[7],hInit[7]);
  285. SHA256ROUND(a, b, c, d, e, f, g, h, 0, w0);
  286. SHA256ROUND(h, a, b, c, d, e, f, g, 1, w1);
  287. SHA256ROUND(g, h, a, b, c, d, e, f, 2, w2);
  288. SHA256ROUND(f, g, h, a, b, c, d, e, 3, w3);
  289. SHA256ROUND(e, f, g, h, a, b, c, d, 4, w4);
  290. SHA256ROUND(d, e, f, g, h, a, b, c, 5, w5);
  291. SHA256ROUND(c, d, e, f, g, h, a, b, 6, w6);
  292. SHA256ROUND(b, c, d, e, f, g, h, a, 7, w7);
  293. SHA256ROUND(a, b, c, d, e, f, g, h, 8, w8);
  294. SHA256ROUND(h, a, b, c, d, e, f, g, 9, w9);
  295. SHA256ROUND(g, h, a, b, c, d, e, f, 10, w10);
  296. SHA256ROUND(f, g, h, a, b, c, d, e, 11, w11);
  297. SHA256ROUND(e, f, g, h, a, b, c, d, 12, w12);
  298. SHA256ROUND(d, e, f, g, h, a, b, c, 13, w13);
  299. SHA256ROUND(c, d, e, f, g, h, a, b, 14, w14);
  300. SHA256ROUND(b, c, d, e, f, g, h, a, 15, w15);
  301. w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);
  302. SHA256ROUND(a, b, c, d, e, f, g, h, 16, w0);
  303. w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);
  304. SHA256ROUND(h, a, b, c, d, e, f, g, 17, w1);
  305. w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);
  306. SHA256ROUND(g, h, a, b, c, d, e, f, 18, w2);
  307. w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);
  308. SHA256ROUND(f, g, h, a, b, c, d, e, 19, w3);
  309. w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);
  310. SHA256ROUND(e, f, g, h, a, b, c, d, 20, w4);
  311. w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);
  312. SHA256ROUND(d, e, f, g, h, a, b, c, 21, w5);
  313. w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);
  314. SHA256ROUND(c, d, e, f, g, h, a, b, 22, w6);
  315. w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);
  316. SHA256ROUND(b, c, d, e, f, g, h, a, 23, w7);
  317. w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);
  318. SHA256ROUND(a, b, c, d, e, f, g, h, 24, w8);
  319. w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);
  320. SHA256ROUND(h, a, b, c, d, e, f, g, 25, w9);
  321. w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);
  322. SHA256ROUND(g, h, a, b, c, d, e, f, 26, w10);
  323. w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);
  324. SHA256ROUND(f, g, h, a, b, c, d, e, 27, w11);
  325. w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);
  326. SHA256ROUND(e, f, g, h, a, b, c, d, 28, w12);
  327. w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);
  328. SHA256ROUND(d, e, f, g, h, a, b, c, 29, w13);
  329. w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);
  330. SHA256ROUND(c, d, e, f, g, h, a, b, 30, w14);
  331. w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);
  332. SHA256ROUND(b, c, d, e, f, g, h, a, 31, w15);
  333. w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);
  334. SHA256ROUND(a, b, c, d, e, f, g, h, 32, w0);
  335. w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);
  336. SHA256ROUND(h, a, b, c, d, e, f, g, 33, w1);
  337. w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);
  338. SHA256ROUND(g, h, a, b, c, d, e, f, 34, w2);
  339. w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);
  340. SHA256ROUND(f, g, h, a, b, c, d, e, 35, w3);
  341. w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);
  342. SHA256ROUND(e, f, g, h, a, b, c, d, 36, w4);
  343. w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);
  344. SHA256ROUND(d, e, f, g, h, a, b, c, 37, w5);
  345. w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);
  346. SHA256ROUND(c, d, e, f, g, h, a, b, 38, w6);
  347. w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);
  348. SHA256ROUND(b, c, d, e, f, g, h, a, 39, w7);
  349. w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);
  350. SHA256ROUND(a, b, c, d, e, f, g, h, 40, w8);
  351. w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);
  352. SHA256ROUND(h, a, b, c, d, e, f, g, 41, w9);
  353. w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);
  354. SHA256ROUND(g, h, a, b, c, d, e, f, 42, w10);
  355. w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);
  356. SHA256ROUND(f, g, h, a, b, c, d, e, 43, w11);
  357. w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);
  358. SHA256ROUND(e, f, g, h, a, b, c, d, 44, w12);
  359. w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);
  360. SHA256ROUND(d, e, f, g, h, a, b, c, 45, w13);
  361. w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);
  362. SHA256ROUND(c, d, e, f, g, h, a, b, 46, w14);
  363. w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);
  364. SHA256ROUND(b, c, d, e, f, g, h, a, 47, w15);
  365. w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);
  366. SHA256ROUND(a, b, c, d, e, f, g, h, 48, w0);
  367. w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);
  368. SHA256ROUND(h, a, b, c, d, e, f, g, 49, w1);
  369. w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);
  370. SHA256ROUND(g, h, a, b, c, d, e, f, 50, w2);
  371. w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);
  372. SHA256ROUND(f, g, h, a, b, c, d, e, 51, w3);
  373. w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);
  374. SHA256ROUND(e, f, g, h, a, b, c, d, 52, w4);
  375. w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);
  376. SHA256ROUND(d, e, f, g, h, a, b, c, 53, w5);
  377. w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);
  378. SHA256ROUND(c, d, e, f, g, h, a, b, 54, w6);
  379. w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);
  380. SHA256ROUND(b, c, d, e, f, g, h, a, 55, w7);
  381. w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);
  382. SHA256ROUND(a, b, c, d, e, f, g, h, 56, w8);
  383. w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);
  384. SHA256ROUND(h, a, b, c, d, e, f, g, 57, w9);
  385. w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);
  386. SHA256ROUND(g, h, a, b, c, d, e, f, 58, w10);
  387. w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);
  388. SHA256ROUND(f, g, h, a, b, c, d, e, 59, w11);
  389. w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);
  390. SHA256ROUND(e, f, g, h, a, b, c, d, 60, w12);
  391. /* Skip last 3-rounds; not necessary for H==0 */
  392. /*#if 0
  393. w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);
  394. SHA256ROUND(d, e, f, g, h, a, b, c, 61, w13);
  395. w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);
  396. SHA256ROUND(c, d, e, f, g, h, a, b, 62, w14);
  397. w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);
  398. SHA256ROUND(b, c, d, e, f, g, h, a, 63, w15);
  399. #endif*/
  400. /* store resulsts directly in thash */
  401. #define store_2(x,i) \
  402. w0 = (vector unsigned int)(hInit[i],hInit[i],hInit[i],hInit[i]); \
  403. vec_st(vec_add(w0, x), 0 ,&thash[i][k]);
  404. store_2(a, 0);
  405. store_2(b, 1);
  406. store_2(c, 2);
  407. store_2(d, 3);
  408. store_2(e, 4);
  409. store_2(f, 5);
  410. store_2(g, 6);
  411. store_2(h, 7);
  412. vec_st(nonce, 0 ,&thash[8][k]);
  413. /* writing the results into the array is time intensive */
  414. /* -> try if it´s faster to compare the results with the target inside this function */
  415. }
  416. }
  417. #endif /* WANT_ALTIVEC_4WAY */