Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.96 KB | None | 0 0
  1. #ifdef VECTORS
  2. typedef uint2 u;
  3. #else
  4. typedef uint u;
  5. #endif
  6.  
  7. #ifdef OLD_STREAM
  8. #pragma OPENCL EXTENSION cl_amd_media_ops : enable
  9. #define rot(x, y) amd_bitalign(x, x, (u)(32-y))
  10. #else
  11. #define rot(x, y) rotate(x, (u)y)
  12. #endif
  13.  
  14. #define R(x) (work[x] = (rot(work[x-2],15)^rot(work[x-2],13)^((work[x-2])>>10)) + work[x-7] + (rot(work[x-15],25)^rot(work[x-15],14)^((work[x-15])>>3)) + work[x-16])
  15. #define sharound(a,b,c,d,e,f,g,h,x,K) {h=(h+(rot(e, 26)^rot(e, 21)^rot(e, 7))+(g^(e&(f^g)))+K+x); t1=(rot(a, 30)^rot(a, 19)^rot(a, 10))+((a&b)|(c&(a|b))); d+=h; h+=t1;}
  16.  
  17. #ifdef NVIDIA
  18. bool belowOrEquals(const uint x, const uint target)
  19. {
  20.     uchar* b = (uchar *)&x;
  21.     uchar* l = (uchar *)⌖
  22.     if(b[0] < l[3]) return true;
  23.     if(b[0] > l[3]) return false;
  24.     if(b[1] < l[2]) return true;
  25.     if(b[1] > l[2]) return false;
  26.     if(b[2] < l[1]) return true;
  27.     if(b[2] > l[1]) return false;
  28.     if(b[3] < l[0]) return true;
  29.     if(b[3] > l[0]) return false;
  30.     return true;
  31. }
  32. #else
  33. #define bytereverse(x) ( ((x) << 24) | (((x) << 8) & 0x00ff0000) | (((x) >> 8) & 0x0000ff00) | ((x) >> 24) )
  34. bool belowOrEquals(const uint x, const uint target)
  35. {
  36.     return bytereverse(x)<=target;
  37. }
  38. #endif
  39.  
  40. __kernel void search(   const uint block0, const uint block1, const uint block2,
  41.                         const uint state0, const uint state1, const uint state2, const uint state3,
  42.                         const uint state4, const uint state5, const uint state6, const uint state7,
  43.                         const uint B1, const uint C1, const uint D1,
  44.                         const uint F1, const uint G1, const uint H1,
  45.                         const uint target,
  46.                         const uint base,
  47.                         __global uint * output)
  48. {
  49.     u nonce;
  50. #ifdef VECTORS 
  51.     nonce.x = base + get_global_id(0);
  52.     nonce.y = nonce.x + 0x80000000;
  53. #else
  54.     nonce = base + get_global_id(0);
  55. #endif
  56.  
  57.     u work[64];
  58.     u A,B,C,D,E,F,G,H;
  59.     u t1;
  60.    
  61.     A=state0;
  62.     B=B1;
  63.     C=C1;
  64.     D=D1;
  65.     E=state4;
  66.     F=F1;
  67.     G=G1;
  68.     H=H1;
  69.  
  70. int i;
  71. for(i=0; i<1; i++) {   
  72.     work[0]=block0;
  73.     work[1]=block1;
  74.     work[2]=block2;
  75.     work[3]=nonce;
  76.     work[4]=0x80000000;
  77.     work[5]=0x00000000;
  78.     work[6]=0x00000000;
  79.     work[7]=0x00000000;
  80.     work[8]=0x00000000;
  81.     work[9]=0x00000000;
  82.     work[10]=0x00000000;
  83.     work[11]=0x00000000;
  84.     work[12]=0x00000000;
  85.     work[13]=0x00000000;
  86.     work[14]=0x00000000;
  87.     work[15]=0x00000280;
  88.  
  89.     // first 3 rounds already done
  90.     //sharound(A,B,C,D,E,F,G,H,work[0],0x428A2F98);
  91.     //sharound(H,A,B,C,D,E,F,G,work[1],0x71374491);
  92.     //sharound(G,H,A,B,C,D,E,F,work[2],0xB5C0FBCF);
  93.     sharound(F,G,H,A,B,C,D,E,work[3],0xE9B5DBA5);
  94.     sharound(E,F,G,H,A,B,C,D,work[4],0x3956C25B);
  95.     sharound(D,E,F,G,H,A,B,C,work[5],0x59F111F1);
  96.     sharound(C,D,E,F,G,H,A,B,work[6],0x923F82A4);
  97.     sharound(B,C,D,E,F,G,H,A,work[7],0xAB1C5ED5);
  98.     sharound(A,B,C,D,E,F,G,H,work[8],0xD807AA98);
  99.     sharound(H,A,B,C,D,E,F,G,work[9],0x12835B01);
  100.     sharound(G,H,A,B,C,D,E,F,work[10],0x243185BE);
  101.     sharound(F,G,H,A,B,C,D,E,work[11],0x550C7DC3);
  102.     sharound(E,F,G,H,A,B,C,D,work[12],0x72BE5D74);
  103.     sharound(D,E,F,G,H,A,B,C,work[13],0x80DEB1FE);
  104.     sharound(C,D,E,F,G,H,A,B,work[14],0x9BDC06A7);
  105.     sharound(B,C,D,E,F,G,H,A,work[15],0xC19BF174);
  106.     sharound(A,B,C,D,E,F,G,H,R(16),0xE49B69C1);
  107.     sharound(H,A,B,C,D,E,F,G,R(17),0xEFBE4786);
  108.     sharound(G,H,A,B,C,D,E,F,R(18),0x0FC19DC6);
  109.     sharound(F,G,H,A,B,C,D,E,R(19),0x240CA1CC);
  110.     sharound(E,F,G,H,A,B,C,D,R(20),0x2DE92C6F);
  111.     sharound(D,E,F,G,H,A,B,C,R(21),0x4A7484AA);
  112.     sharound(C,D,E,F,G,H,A,B,R(22),0x5CB0A9DC);
  113.     sharound(B,C,D,E,F,G,H,A,R(23),0x76F988DA);
  114.     sharound(A,B,C,D,E,F,G,H,R(24),0x983E5152);
  115.     sharound(H,A,B,C,D,E,F,G,R(25),0xA831C66D);
  116.     sharound(G,H,A,B,C,D,E,F,R(26),0xB00327C8);
  117.     sharound(F,G,H,A,B,C,D,E,R(27),0xBF597FC7);
  118.     sharound(E,F,G,H,A,B,C,D,R(28),0xC6E00BF3);
  119.     sharound(D,E,F,G,H,A,B,C,R(29),0xD5A79147);
  120.     sharound(C,D,E,F,G,H,A,B,R(30),0x06CA6351);
  121.     sharound(B,C,D,E,F,G,H,A,R(31),0x14292967);
  122.     sharound(A,B,C,D,E,F,G,H,R(32),0x27B70A85);
  123.     sharound(H,A,B,C,D,E,F,G,R(33),0x2E1B2138);
  124.     sharound(G,H,A,B,C,D,E,F,R(34),0x4D2C6DFC);
  125.     sharound(F,G,H,A,B,C,D,E,R(35),0x53380D13);
  126.     sharound(E,F,G,H,A,B,C,D,R(36),0x650A7354);
  127.     sharound(D,E,F,G,H,A,B,C,R(37),0x766A0ABB);
  128.     sharound(C,D,E,F,G,H,A,B,R(38),0x81C2C92E);
  129.     sharound(B,C,D,E,F,G,H,A,R(39),0x92722C85);
  130.     sharound(A,B,C,D,E,F,G,H,R(40),0xA2BFE8A1);
  131.     sharound(H,A,B,C,D,E,F,G,R(41),0xA81A664B);
  132.     sharound(G,H,A,B,C,D,E,F,R(42),0xC24B8B70);
  133.     sharound(F,G,H,A,B,C,D,E,R(43),0xC76C51A3);
  134.     sharound(E,F,G,H,A,B,C,D,R(44),0xD192E819);
  135.     sharound(D,E,F,G,H,A,B,C,R(45),0xD6990624);
  136.     sharound(C,D,E,F,G,H,A,B,R(46),0xF40E3585);
  137.     sharound(B,C,D,E,F,G,H,A,R(47),0x106AA070);
  138.     sharound(A,B,C,D,E,F,G,H,R(48),0x19A4C116);
  139.     sharound(H,A,B,C,D,E,F,G,R(49),0x1E376C08);
  140.     sharound(G,H,A,B,C,D,E,F,R(50),0x2748774C);
  141.     sharound(F,G,H,A,B,C,D,E,R(51),0x34B0BCB5);
  142.     sharound(E,F,G,H,A,B,C,D,R(52),0x391C0CB3);
  143.     sharound(D,E,F,G,H,A,B,C,R(53),0x4ED8AA4A);
  144.     sharound(C,D,E,F,G,H,A,B,R(54),0x5B9CCA4F);
  145.     sharound(B,C,D,E,F,G,H,A,R(55),0x682E6FF3);
  146.     sharound(A,B,C,D,E,F,G,H,R(56),0x748F82EE);
  147.     sharound(H,A,B,C,D,E,F,G,R(57),0x78A5636F);
  148.     sharound(G,H,A,B,C,D,E,F,R(58),0x84C87814);
  149.     sharound(F,G,H,A,B,C,D,E,R(59),0x8CC70208);
  150.     sharound(E,F,G,H,A,B,C,D,R(60),0x90BEFFFA);
  151.     sharound(D,E,F,G,H,A,B,C,R(61),0xA4506CEB);
  152.     sharound(C,D,E,F,G,H,A,B,R(62),0xBEF9A3F7);
  153.     sharound(B,C,D,E,F,G,H,A,R(63),0xC67178F2);
  154.  
  155.     work[0]=state0+A;
  156.     work[1]=state1+B;
  157.     work[2]=state2+C;
  158.     work[3]=state3+D;
  159.     work[4]=state4+E;
  160.     work[5]=state5+F;
  161.     work[6]=state6+G;
  162.     work[7]=state7+H;
  163.     work[8]=0x80000000;
  164.     work[9]=0x00000000;
  165.     work[10]=0x00000000;
  166.     work[11]=0x00000000;
  167.     work[12]=0x00000000;
  168.     work[13]=0x00000000;
  169.     work[14]=0x00000000;
  170.     work[15]=0x00000100;
  171.  
  172.     A=0x6a09e667;
  173.     B=0xbb67ae85;
  174.     C=0x3c6ef372;
  175.     D=0xa54ff53a;
  176.     E=0x510e527f;
  177.     F=0x9b05688c;
  178.     G=0x1f83d9ab;
  179.     H=0x5be0cd19;
  180.  
  181.     sharound(A,B,C,D,E,F,G,H,work[0],0x428A2F98);
  182.     sharound(H,A,B,C,D,E,F,G,work[1],0x71374491);
  183.     sharound(G,H,A,B,C,D,E,F,work[2],0xB5C0FBCF);
  184.     sharound(F,G,H,A,B,C,D,E,work[3],0xE9B5DBA5);
  185.     sharound(E,F,G,H,A,B,C,D,work[4],0x3956C25B);
  186.     sharound(D,E,F,G,H,A,B,C,work[5],0x59F111F1);
  187.     sharound(C,D,E,F,G,H,A,B,work[6],0x923F82A4);
  188.     sharound(B,C,D,E,F,G,H,A,work[7],0xAB1C5ED5);
  189.     sharound(A,B,C,D,E,F,G,H,work[8],0xD807AA98);
  190.     sharound(H,A,B,C,D,E,F,G,work[9],0x12835B01);
  191.     sharound(G,H,A,B,C,D,E,F,work[10],0x243185BE);
  192.     sharound(F,G,H,A,B,C,D,E,work[11],0x550C7DC3);
  193.     sharound(E,F,G,H,A,B,C,D,work[12],0x72BE5D74);
  194.     sharound(D,E,F,G,H,A,B,C,work[13],0x80DEB1FE);
  195.     sharound(C,D,E,F,G,H,A,B,work[14],0x9BDC06A7);
  196.     sharound(B,C,D,E,F,G,H,A,work[15],0xC19BF174);
  197.     sharound(A,B,C,D,E,F,G,H,R(16),0xE49B69C1);
  198.     sharound(H,A,B,C,D,E,F,G,R(17),0xEFBE4786);
  199.     sharound(G,H,A,B,C,D,E,F,R(18),0x0FC19DC6);
  200.     sharound(F,G,H,A,B,C,D,E,R(19),0x240CA1CC);
  201.     sharound(E,F,G,H,A,B,C,D,R(20),0x2DE92C6F);
  202.     sharound(D,E,F,G,H,A,B,C,R(21),0x4A7484AA);
  203.     sharound(C,D,E,F,G,H,A,B,R(22),0x5CB0A9DC);
  204.     sharound(B,C,D,E,F,G,H,A,R(23),0x76F988DA);
  205.     sharound(A,B,C,D,E,F,G,H,R(24),0x983E5152);
  206.     sharound(H,A,B,C,D,E,F,G,R(25),0xA831C66D);
  207.     sharound(G,H,A,B,C,D,E,F,R(26),0xB00327C8);
  208.     sharound(F,G,H,A,B,C,D,E,R(27),0xBF597FC7);
  209.     sharound(E,F,G,H,A,B,C,D,R(28),0xC6E00BF3);
  210.     sharound(D,E,F,G,H,A,B,C,R(29),0xD5A79147);
  211.     sharound(C,D,E,F,G,H,A,B,R(30),0x06CA6351);
  212.     sharound(B,C,D,E,F,G,H,A,R(31),0x14292967);
  213.     sharound(A,B,C,D,E,F,G,H,R(32),0x27B70A85);
  214.     sharound(H,A,B,C,D,E,F,G,R(33),0x2E1B2138);
  215.     sharound(G,H,A,B,C,D,E,F,R(34),0x4D2C6DFC);
  216.     sharound(F,G,H,A,B,C,D,E,R(35),0x53380D13);
  217.     sharound(E,F,G,H,A,B,C,D,R(36),0x650A7354);
  218.     sharound(D,E,F,G,H,A,B,C,R(37),0x766A0ABB);
  219.     sharound(C,D,E,F,G,H,A,B,R(38),0x81C2C92E);
  220.     sharound(B,C,D,E,F,G,H,A,R(39),0x92722C85);
  221.     sharound(A,B,C,D,E,F,G,H,R(40),0xA2BFE8A1);
  222.     sharound(H,A,B,C,D,E,F,G,R(41),0xA81A664B);
  223.     sharound(G,H,A,B,C,D,E,F,R(42),0xC24B8B70);
  224.     sharound(F,G,H,A,B,C,D,E,R(43),0xC76C51A3);
  225.     sharound(E,F,G,H,A,B,C,D,R(44),0xD192E819);
  226.     sharound(D,E,F,G,H,A,B,C,R(45),0xD6990624);
  227.     sharound(C,D,E,F,G,H,A,B,R(46),0xF40E3585);
  228.     sharound(B,C,D,E,F,G,H,A,R(47),0x106AA070);
  229.     sharound(A,B,C,D,E,F,G,H,R(48),0x19A4C116);
  230.     sharound(H,A,B,C,D,E,F,G,R(49),0x1E376C08);
  231.     sharound(G,H,A,B,C,D,E,F,R(50),0x2748774C);
  232.     sharound(F,G,H,A,B,C,D,E,R(51),0x34B0BCB5);
  233.     sharound(E,F,G,H,A,B,C,D,R(52),0x391C0CB3);
  234.     sharound(D,E,F,G,H,A,B,C,R(53),0x4ED8AA4A);
  235.     sharound(C,D,E,F,G,H,A,B,R(54),0x5B9CCA4F);
  236.     sharound(B,C,D,E,F,G,H,A,R(55),0x682E6FF3);
  237.     sharound(A,B,C,D,E,F,G,H,R(56),0x748F82EE);
  238.     sharound(H,A,B,C,D,E,F,G,R(57),0x78A5636F);
  239.     sharound(G,H,A,B,C,D,E,F,R(58),0x84C87814);
  240.     sharound(F,G,H,A,B,C,D,E,R(59),0x8CC70208);
  241.     sharound(E,F,G,H,A,B,C,D,R(60),0x90BEFFFA);
  242.     sharound(D,E,F,G,H,A,B,C,R(61),0xA4506CEB);
  243.     //we don't need to do these last 2 rounds as they update F, B, E and A, but we only care about G and H
  244.     //sharound(C,D,E,F,G,H,A,B,R(62),0xBEF9A3F7);
  245.     //sharound(B,C,D,E,F,G,H,A,R(63),0xC67178F2);
  246.  
  247.     G+=0x1f83d9ab;
  248.     H+=0x5be0cd19;
  249.  
  250. #ifdef VECTORS
  251.     if((H.x==0) && (belowOrEquals(G.x, target)))
  252.     {
  253.         output[0] = nonce.x;
  254.     }
  255.     if((H.y==0) && (belowOrEquals(G.y, target)))
  256.     {
  257.         output[0] = nonce.y;
  258.     }
  259. #else
  260.     if((H==0) && (belowOrEquals(G, target)))
  261.     {
  262.         output[0] = nonce;
  263.     }
  264. #endif
  265. }
  266. }
  267.  
  268. // end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement