Advertisement
Guest User

Untitled

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