sha256_altivec_4way.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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*thr, const unsigned char *pmidstate,
  59. unsigned char *pdata,
  60. unsigned char *phash1, unsigned char *phash,
  61. const unsigned char *ptarget,
  62. uint32_t max_nonce, uint32_t *last_nonce,
  63. uint32_t nonce)
  64. {
  65. uint32_t *hash32 = (uint32_t *)phash;
  66. unsigned int *nNonce_p = (unsigned int*)(pdata + 76);
  67. pdata += 64;
  68. for (;;)
  69. {
  70. unsigned int thash[9][NPAR] __attribute__((aligned(128)));
  71. int j;
  72. *nNonce_p = nonce;
  73. DoubleBlockSHA256(pdata, phash1, pmidstate, thash, pSHA256InitState);
  74. for (j = 0; j < NPAR; j++)
  75. {
  76. if (unlikely(thash[7][j] == 0))
  77. {
  78. int i;
  79. for (i = 0; i < 32/4; i++)
  80. ((unsigned int*)phash)[i] = thash[i][j];
  81. if (unlikely(hash32[7] == 0 && fulltest(phash, ptarget))) {
  82. nonce += j;
  83. *last_nonce = nonce;
  84. *nNonce_p = nonce;
  85. return true;
  86. }
  87. }
  88. }
  89. if ((nonce >= max_nonce) || thr->work_restart)
  90. {
  91. *last_nonce = nonce;
  92. return false;
  93. }
  94. nonce += NPAR;
  95. }
  96. }
  97. static void DoubleBlockSHA256(const void* pin, void* pad, const void *pre, unsigned int thash[9][NPAR], const void *init)
  98. {
  99. unsigned int* In = (unsigned int*)pin;
  100. unsigned int* Pad = (unsigned int*)pad;
  101. unsigned int* hPre = (unsigned int*)pre;
  102. unsigned int* hInit = (unsigned int*)init;
  103. unsigned int /* i, j, */ k;
  104. /* vectors used in calculation */
  105. vector unsigned int w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15;
  106. vector unsigned int T1;
  107. vector unsigned int a, b, c, d, e, f, g, h;
  108. vector unsigned int nonce, preNonce;
  109. /* nonce offset for vector */
  110. vector unsigned int offset = (vector unsigned int)(0, 1, 2, 3);
  111. preNonce = vec_add((vector unsigned int)(In[3],In[3],In[3],In[3]), offset);
  112. for(k = 0; k<NPAR; k+=4)
  113. {
  114. w0 = (vector unsigned int)(In[0],In[0],In[0],In[0]);
  115. w1 = (vector unsigned int)(In[1],In[1],In[1],In[1]);
  116. w2 = (vector unsigned int)(In[2],In[2],In[2],In[2]);
  117. //w3 = (vector unsigned int)(In[3],In[3],In[3],In[3]); nonce will be later hacked into the hash
  118. w4 = (vector unsigned int)(In[4],In[4],In[4],In[4]);
  119. w5 = (vector unsigned int)(In[5],In[5],In[5],In[5]);
  120. w6 = (vector unsigned int)(In[6],In[6],In[6],In[6]);
  121. w7 = (vector unsigned int)(In[7],In[7],In[7],In[7]);
  122. w8 = (vector unsigned int)(In[8],In[8],In[8],In[8]);
  123. w9 = (vector unsigned int)(In[9],In[9],In[9],In[9]);
  124. w10 = (vector unsigned int)(In[10],In[10],In[10],In[10]);
  125. w11 = (vector unsigned int)(In[11],In[11],In[11],In[11]);
  126. w12 = (vector unsigned int)(In[12],In[12],In[12],In[12]);
  127. w13 = (vector unsigned int)(In[13],In[13],In[13],In[13]);
  128. w14 = (vector unsigned int)(In[14],In[14],In[14],In[14]);
  129. w15 = (vector unsigned int)(In[15],In[15],In[15],In[15]);
  130. /* hack nonce into lowest byte of w3 */
  131. nonce = vec_add(preNonce, (vector unsigned int)(k,k,k,k));
  132. w3 = nonce;
  133. //printf ("W3: %08vlx\n", w3);
  134. a = (vector unsigned int)(hPre[0],hPre[0],hPre[0],hPre[0]);
  135. b = (vector unsigned int)(hPre[1],hPre[1],hPre[1],hPre[1]);
  136. c = (vector unsigned int)(hPre[2],hPre[2],hPre[2],hPre[2]);
  137. d = (vector unsigned int)(hPre[3],hPre[3],hPre[3],hPre[3]);
  138. e = (vector unsigned int)(hPre[4],hPre[4],hPre[4],hPre[4]);
  139. f = (vector unsigned int)(hPre[5],hPre[5],hPre[5],hPre[5]);
  140. g = (vector unsigned int)(hPre[6],hPre[6],hPre[6],hPre[6]);
  141. h = (vector unsigned int)(hPre[7],hPre[7],hPre[7],hPre[7]);
  142. SHA256ROUND(a, b, c, d, e, f, g, h, 0, w0);
  143. SHA256ROUND(h, a, b, c, d, e, f, g, 1, w1);
  144. SHA256ROUND(g, h, a, b, c, d, e, f, 2, w2);
  145. SHA256ROUND(f, g, h, a, b, c, d, e, 3, w3);
  146. SHA256ROUND(e, f, g, h, a, b, c, d, 4, w4);
  147. SHA256ROUND(d, e, f, g, h, a, b, c, 5, w5);
  148. SHA256ROUND(c, d, e, f, g, h, a, b, 6, w6);
  149. SHA256ROUND(b, c, d, e, f, g, h, a, 7, w7);
  150. SHA256ROUND(a, b, c, d, e, f, g, h, 8, w8);
  151. SHA256ROUND(h, a, b, c, d, e, f, g, 9, w9);
  152. SHA256ROUND(g, h, a, b, c, d, e, f, 10, w10);
  153. SHA256ROUND(f, g, h, a, b, c, d, e, 11, w11);
  154. SHA256ROUND(e, f, g, h, a, b, c, d, 12, w12);
  155. SHA256ROUND(d, e, f, g, h, a, b, c, 13, w13);
  156. SHA256ROUND(c, d, e, f, g, h, a, b, 14, w14);
  157. SHA256ROUND(b, c, d, e, f, g, h, a, 15, w15);
  158. w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);
  159. SHA256ROUND(a, b, c, d, e, f, g, h, 16, w0);
  160. w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);
  161. SHA256ROUND(h, a, b, c, d, e, f, g, 17, w1);
  162. w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);
  163. SHA256ROUND(g, h, a, b, c, d, e, f, 18, w2);
  164. w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);
  165. SHA256ROUND(f, g, h, a, b, c, d, e, 19, w3);
  166. w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);
  167. SHA256ROUND(e, f, g, h, a, b, c, d, 20, w4);
  168. w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);
  169. SHA256ROUND(d, e, f, g, h, a, b, c, 21, w5);
  170. w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);
  171. SHA256ROUND(c, d, e, f, g, h, a, b, 22, w6);
  172. w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);
  173. SHA256ROUND(b, c, d, e, f, g, h, a, 23, w7);
  174. w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);
  175. SHA256ROUND(a, b, c, d, e, f, g, h, 24, w8);
  176. w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);
  177. SHA256ROUND(h, a, b, c, d, e, f, g, 25, w9);
  178. w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);
  179. SHA256ROUND(g, h, a, b, c, d, e, f, 26, w10);
  180. w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);
  181. SHA256ROUND(f, g, h, a, b, c, d, e, 27, w11);
  182. w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);
  183. SHA256ROUND(e, f, g, h, a, b, c, d, 28, w12);
  184. w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);
  185. SHA256ROUND(d, e, f, g, h, a, b, c, 29, w13);
  186. w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);
  187. SHA256ROUND(c, d, e, f, g, h, a, b, 30, w14);
  188. w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);
  189. SHA256ROUND(b, c, d, e, f, g, h, a, 31, w15);
  190. w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);
  191. SHA256ROUND(a, b, c, d, e, f, g, h, 32, w0);
  192. w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);
  193. SHA256ROUND(h, a, b, c, d, e, f, g, 33, w1);
  194. w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);
  195. SHA256ROUND(g, h, a, b, c, d, e, f, 34, w2);
  196. w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);
  197. SHA256ROUND(f, g, h, a, b, c, d, e, 35, w3);
  198. w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);
  199. SHA256ROUND(e, f, g, h, a, b, c, d, 36, w4);
  200. w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);
  201. SHA256ROUND(d, e, f, g, h, a, b, c, 37, w5);
  202. w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);
  203. SHA256ROUND(c, d, e, f, g, h, a, b, 38, w6);
  204. w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);
  205. SHA256ROUND(b, c, d, e, f, g, h, a, 39, w7);
  206. w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);
  207. SHA256ROUND(a, b, c, d, e, f, g, h, 40, w8);
  208. w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);
  209. SHA256ROUND(h, a, b, c, d, e, f, g, 41, w9);
  210. w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);
  211. SHA256ROUND(g, h, a, b, c, d, e, f, 42, w10);
  212. w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);
  213. SHA256ROUND(f, g, h, a, b, c, d, e, 43, w11);
  214. w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);
  215. SHA256ROUND(e, f, g, h, a, b, c, d, 44, w12);
  216. w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);
  217. SHA256ROUND(d, e, f, g, h, a, b, c, 45, w13);
  218. w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);
  219. SHA256ROUND(c, d, e, f, g, h, a, b, 46, w14);
  220. w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);
  221. SHA256ROUND(b, c, d, e, f, g, h, a, 47, w15);
  222. w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);
  223. SHA256ROUND(a, b, c, d, e, f, g, h, 48, w0);
  224. w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);
  225. SHA256ROUND(h, a, b, c, d, e, f, g, 49, w1);
  226. w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);
  227. SHA256ROUND(g, h, a, b, c, d, e, f, 50, w2);
  228. w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);
  229. SHA256ROUND(f, g, h, a, b, c, d, e, 51, w3);
  230. w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);
  231. SHA256ROUND(e, f, g, h, a, b, c, d, 52, w4);
  232. w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);
  233. SHA256ROUND(d, e, f, g, h, a, b, c, 53, w5);
  234. w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);
  235. SHA256ROUND(c, d, e, f, g, h, a, b, 54, w6);
  236. w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);
  237. SHA256ROUND(b, c, d, e, f, g, h, a, 55, w7);
  238. w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);
  239. SHA256ROUND(a, b, c, d, e, f, g, h, 56, w8);
  240. w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);
  241. SHA256ROUND(h, a, b, c, d, e, f, g, 57, w9);
  242. w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);
  243. SHA256ROUND(g, h, a, b, c, d, e, f, 58, w10);
  244. w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);
  245. SHA256ROUND(f, g, h, a, b, c, d, e, 59, w11);
  246. w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);
  247. SHA256ROUND(e, f, g, h, a, b, c, d, 60, w12);
  248. w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);
  249. SHA256ROUND(d, e, f, g, h, a, b, c, 61, w13);
  250. w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);
  251. SHA256ROUND(c, d, e, f, g, h, a, b, 62, w14);
  252. w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);
  253. SHA256ROUND(b, c, d, e, f, g, h, a, 63, w15);
  254. #define store_load(x, i, dest) \
  255. T1 = (vector unsigned int)((hPre)[i],(hPre)[i],(hPre)[i],(hPre)[i]); \
  256. dest = vec_add(T1, x);
  257. store_load(a, 0, w0);
  258. store_load(b, 1, w1);
  259. store_load(c, 2, w2);
  260. store_load(d, 3, w3);
  261. store_load(e, 4, w4);
  262. store_load(f, 5, w5);
  263. store_load(g, 6, w6);
  264. store_load(h, 7, w7);
  265. /* end of first SHA256 round */
  266. w8 = (vector unsigned int)(Pad[8],Pad[8],Pad[8],Pad[8]);
  267. w9 = (vector unsigned int)(Pad[9],Pad[9],Pad[9],Pad[9]);
  268. w10 = (vector unsigned int)(Pad[10],Pad[10],Pad[10],Pad[10]);
  269. w11 = (vector unsigned int)(Pad[11],Pad[11],Pad[11],Pad[11]);
  270. w12 = (vector unsigned int)(Pad[12],Pad[12],Pad[12],Pad[12]);
  271. w13 = (vector unsigned int)(Pad[13],Pad[13],Pad[13],Pad[13]);
  272. w14 = (vector unsigned int)(Pad[14],Pad[14],Pad[14],Pad[14]);
  273. w15 = (vector unsigned int)(Pad[15],Pad[15],Pad[15],Pad[15]);
  274. a = (vector unsigned int)(hInit[0],hInit[0],hInit[0],hInit[0]);
  275. b = (vector unsigned int)(hInit[1],hInit[1],hInit[1],hInit[1]);
  276. c = (vector unsigned int)(hInit[2],hInit[2],hInit[2],hInit[2]);
  277. d = (vector unsigned int)(hInit[3],hInit[3],hInit[3],hInit[3]);
  278. e = (vector unsigned int)(hInit[4],hInit[4],hInit[4],hInit[4]);
  279. f = (vector unsigned int)(hInit[5],hInit[5],hInit[5],hInit[5]);
  280. g = (vector unsigned int)(hInit[6],hInit[6],hInit[6],hInit[6]);
  281. h = (vector unsigned int)(hInit[7],hInit[7],hInit[7],hInit[7]);
  282. SHA256ROUND(a, b, c, d, e, f, g, h, 0, w0);
  283. SHA256ROUND(h, a, b, c, d, e, f, g, 1, w1);
  284. SHA256ROUND(g, h, a, b, c, d, e, f, 2, w2);
  285. SHA256ROUND(f, g, h, a, b, c, d, e, 3, w3);
  286. SHA256ROUND(e, f, g, h, a, b, c, d, 4, w4);
  287. SHA256ROUND(d, e, f, g, h, a, b, c, 5, w5);
  288. SHA256ROUND(c, d, e, f, g, h, a, b, 6, w6);
  289. SHA256ROUND(b, c, d, e, f, g, h, a, 7, w7);
  290. SHA256ROUND(a, b, c, d, e, f, g, h, 8, w8);
  291. SHA256ROUND(h, a, b, c, d, e, f, g, 9, w9);
  292. SHA256ROUND(g, h, a, b, c, d, e, f, 10, w10);
  293. SHA256ROUND(f, g, h, a, b, c, d, e, 11, w11);
  294. SHA256ROUND(e, f, g, h, a, b, c, d, 12, w12);
  295. SHA256ROUND(d, e, f, g, h, a, b, c, 13, w13);
  296. SHA256ROUND(c, d, e, f, g, h, a, b, 14, w14);
  297. SHA256ROUND(b, c, d, e, f, g, h, a, 15, w15);
  298. w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);
  299. SHA256ROUND(a, b, c, d, e, f, g, h, 16, w0);
  300. w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);
  301. SHA256ROUND(h, a, b, c, d, e, f, g, 17, w1);
  302. w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);
  303. SHA256ROUND(g, h, a, b, c, d, e, f, 18, w2);
  304. w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);
  305. SHA256ROUND(f, g, h, a, b, c, d, e, 19, w3);
  306. w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);
  307. SHA256ROUND(e, f, g, h, a, b, c, d, 20, w4);
  308. w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);
  309. SHA256ROUND(d, e, f, g, h, a, b, c, 21, w5);
  310. w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);
  311. SHA256ROUND(c, d, e, f, g, h, a, b, 22, w6);
  312. w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);
  313. SHA256ROUND(b, c, d, e, f, g, h, a, 23, w7);
  314. w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);
  315. SHA256ROUND(a, b, c, d, e, f, g, h, 24, w8);
  316. w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);
  317. SHA256ROUND(h, a, b, c, d, e, f, g, 25, w9);
  318. w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);
  319. SHA256ROUND(g, h, a, b, c, d, e, f, 26, w10);
  320. w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);
  321. SHA256ROUND(f, g, h, a, b, c, d, e, 27, w11);
  322. w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);
  323. SHA256ROUND(e, f, g, h, a, b, c, d, 28, w12);
  324. w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);
  325. SHA256ROUND(d, e, f, g, h, a, b, c, 29, w13);
  326. w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);
  327. SHA256ROUND(c, d, e, f, g, h, a, b, 30, w14);
  328. w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);
  329. SHA256ROUND(b, c, d, e, f, g, h, a, 31, w15);
  330. w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);
  331. SHA256ROUND(a, b, c, d, e, f, g, h, 32, w0);
  332. w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);
  333. SHA256ROUND(h, a, b, c, d, e, f, g, 33, w1);
  334. w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);
  335. SHA256ROUND(g, h, a, b, c, d, e, f, 34, w2);
  336. w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);
  337. SHA256ROUND(f, g, h, a, b, c, d, e, 35, w3);
  338. w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);
  339. SHA256ROUND(e, f, g, h, a, b, c, d, 36, w4);
  340. w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);
  341. SHA256ROUND(d, e, f, g, h, a, b, c, 37, w5);
  342. w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);
  343. SHA256ROUND(c, d, e, f, g, h, a, b, 38, w6);
  344. w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);
  345. SHA256ROUND(b, c, d, e, f, g, h, a, 39, w7);
  346. w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);
  347. SHA256ROUND(a, b, c, d, e, f, g, h, 40, w8);
  348. w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);
  349. SHA256ROUND(h, a, b, c, d, e, f, g, 41, w9);
  350. w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);
  351. SHA256ROUND(g, h, a, b, c, d, e, f, 42, w10);
  352. w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);
  353. SHA256ROUND(f, g, h, a, b, c, d, e, 43, w11);
  354. w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);
  355. SHA256ROUND(e, f, g, h, a, b, c, d, 44, w12);
  356. w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);
  357. SHA256ROUND(d, e, f, g, h, a, b, c, 45, w13);
  358. w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);
  359. SHA256ROUND(c, d, e, f, g, h, a, b, 46, w14);
  360. w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);
  361. SHA256ROUND(b, c, d, e, f, g, h, a, 47, w15);
  362. w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);
  363. SHA256ROUND(a, b, c, d, e, f, g, h, 48, w0);
  364. w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);
  365. SHA256ROUND(h, a, b, c, d, e, f, g, 49, w1);
  366. w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);
  367. SHA256ROUND(g, h, a, b, c, d, e, f, 50, w2);
  368. w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);
  369. SHA256ROUND(f, g, h, a, b, c, d, e, 51, w3);
  370. w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);
  371. SHA256ROUND(e, f, g, h, a, b, c, d, 52, w4);
  372. w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);
  373. SHA256ROUND(d, e, f, g, h, a, b, c, 53, w5);
  374. w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);
  375. SHA256ROUND(c, d, e, f, g, h, a, b, 54, w6);
  376. w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);
  377. SHA256ROUND(b, c, d, e, f, g, h, a, 55, w7);
  378. w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);
  379. SHA256ROUND(a, b, c, d, e, f, g, h, 56, w8);
  380. w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);
  381. SHA256ROUND(h, a, b, c, d, e, f, g, 57, w9);
  382. w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);
  383. SHA256ROUND(g, h, a, b, c, d, e, f, 58, w10);
  384. w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);
  385. SHA256ROUND(f, g, h, a, b, c, d, e, 59, w11);
  386. w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);
  387. SHA256ROUND(e, f, g, h, a, b, c, d, 60, w12);
  388. /* Skip last 3-rounds; not necessary for H==0 */
  389. /*#if 0
  390. w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);
  391. SHA256ROUND(d, e, f, g, h, a, b, c, 61, w13);
  392. w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);
  393. SHA256ROUND(c, d, e, f, g, h, a, b, 62, w14);
  394. w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);
  395. SHA256ROUND(b, c, d, e, f, g, h, a, 63, w15);
  396. #endif*/
  397. /* store resulsts directly in thash */
  398. #define store_2(x,i) \
  399. w0 = (vector unsigned int)(hInit[i],hInit[i],hInit[i],hInit[i]); \
  400. vec_st(vec_add(w0, x), 0 ,&thash[i][k]);
  401. store_2(a, 0);
  402. store_2(b, 1);
  403. store_2(c, 2);
  404. store_2(d, 3);
  405. store_2(e, 4);
  406. store_2(f, 5);
  407. store_2(g, 6);
  408. store_2(h, 7);
  409. vec_st(nonce, 0 ,&thash[8][k]);
  410. /* writing the results into the array is time intensive */
  411. /* -> try if it´s faster to compare the results with the target inside this function */
  412. }
  413. }
  414. #endif /* WANT_ALTIVEC_4WAY */