Guest User

xform

a guest
May 16th, 2014
375
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define rotl(x,r) (x << r) | (x >> (64-r))
  2. #define r(x,s,t,u,v,r1,r2,r3,r4)\
  3.     x^=s;x=rotl(x,r1);x+=t;x=rotl(x,r2);x^=u;x=rotl(x,r3);x+=v;x=rotl(x,r4)
  4.  
  5. #define rotr(x,r) (x >> r) | (x << (64-r))
  6. #define rinv(x,s,t,u,v,r1,r2,r3,r4)\
  7.     x=rotr(x,r4);x-=v;x=rotr(x,r3);x^=u;x=rotr(x,r2);x-=t;x=rotr(x,r1);x^=s
  8.  
  9. void f(uint64_t x[8])
  10. {
  11.     uint64_t a, b, c, d, e, f, g, h;
  12.     a = 0x243F6A8885A308D3 + x[0]; a=rotl(a, 3);
  13.     b = 0x13198A2E03707344 + x[1]; b=rotl(b, 5);
  14.     c = 0xA4093822299F31D0 + x[2]; c=rotl(c, 7);
  15.     d = 0x082EFA98EC4E6C89 + x[3]; d=rotl(d,11);
  16.     e = 0x452821E638D01377 + x[4]; e=rotl(e,13);
  17.     f = 0xBE5466CF34E90C6C + x[5]; f=rotl(f,17);
  18.     g = 0xC0AC29B7C97C50DD + x[6]; g=rotl(g,19);
  19.     h = 0x3F84D5B5B5470917 + x[7]; h=rotl(h,23);
  20.  
  21.     r(e,a,b,c,d,41,21,17,29);
  22.     r(f,b,c,d,a,33,49, 1,17);
  23.     r(g,c,d,a,b,41,11,17, 3);
  24.     r(h,d,a,b,c,17, 7,33,55);
  25.  
  26.     r(a,e,f,g,h, 9,27,17,51);
  27.     r(b,f,g,h,e,25,61,49,53);
  28.     r(c,g,h,e,f,49,23,33,39);
  29.     r(d,h,e,f,g,57,51,49,27);
  30.  
  31.     e += 0x9216D5D98979FB1B; e=rotl(e,47);
  32.     f += 0xD1310BA698DFB5AC; f=rotl(f,53);
  33.     g += 0x2FFD72DBD01ADFB7; g=rotl(g,59);
  34.     h += 0xB8E1AFED6A267E96; h=rotl(h,61);
  35.  
  36.     r(e,a,b,c,d,33,15, 1,47);
  37.     r(f,b,c,d,a,57,13,49,37);
  38.     r(g,c,d,a,b,25, 3,49,11);
  39.     r(h,d,a,b,c, 9,37,17,13);
  40.    
  41.     a += 0xBA7C9045F12C7F99; a=rotl(a,29);
  42.     b += 0x24A19947B3916CF7; b=rotl(b,37);
  43.     c += 0x0801F2E2858EFC16; c=rotl(c,41);
  44.     d += 0x636920D871574E69; d=rotl(d,43);
  45.  
  46.     r(a,e,f,g,h, 9, 5,17,45);
  47.     r(b,f,g,h,e,25,29,49,21);
  48.     r(c,g,h,e,f,17,57,33, 9);
  49.     r(d,h,e,f,g,57,19,49,59);
  50.  
  51.     e += 0xA458FEA3F4933D7E; e=rotl(e, 3);
  52.     f += 0x0D95748F728EB658; f=rotl(f, 5);
  53.     g += 0x718BCD5882154AEE; g=rotl(g, 7);
  54.     h += 0x7B54A41DC25A59B5; h=rotl(h,11);
  55.  
  56.     r(e,a,b,c,d, 9,27,17,51);
  57.     r(f,b,c,d,a,25,61,49,53);
  58.     r(g,c,d,a,b,49,23,33,39);
  59.     r(h,d,a,b,c,57,51,49,28);
  60.    
  61.     a += 0x9C30D5392AF26013; a=rotl(a,13);
  62.     b += 0xC5D1B023286085F0; b=rotl(b,17);
  63.     c += 0xCA417918B8DB38EF; c=rotl(c,19);
  64.     d += 0x8E79DCB0603A180E; d=rotl(d,23);
  65.  
  66.     r(a,e,f,g,h,41,21,17,29);
  67.     r(b,f,g,h,e,33,49, 1,17);
  68.     r(c,g,h,e,f,41,11,17, 3);
  69.     r(d,h,e,f,g,17, 7,33,55);
  70.  
  71.     x[0] = a;
  72.     x[1] = b;
  73.     x[2] = c;
  74.     x[3] = d;
  75.     x[4] = e;
  76.     x[5] = f;
  77.     x[6] = g;
  78.     x[7] = h;
  79. }
  80.  
  81.  
  82. void finv(uint64_t x[8])
  83. {
  84.     uint64_t a, b, c, d, e, f, g, h;
  85.  
  86.     a = x[0];
  87.     b = x[1];
  88.     c = x[2];
  89.     d = x[3];
  90.     e = x[4];
  91.     f = x[5];
  92.     g = x[6];
  93.     h = x[7];
  94.  
  95.     rinv(a,e,f,g,h,41,21,17,29);
  96.     rinv(b,f,g,h,e,33,49, 1,17);
  97.     rinv(c,g,h,e,f,41,11,17, 3);
  98.     rinv(d,h,e,f,g,17, 7,33,55);
  99.  
  100.     a=rotr(a,13);a -= 0x9C30D5392AF26013;
  101.     b=rotr(b,17);b -= 0xC5D1B023286085F0;
  102.     c=rotr(c,19);c -= 0xCA417918B8DB38EF;
  103.     d=rotr(d,23);d -= 0x8E79DCB0603A180E;
  104.    
  105.     rinv(e,a,b,c,d, 9,27,17,51);
  106.     rinv(f,b,c,d,a,25,61,49,53);
  107.     rinv(g,c,d,a,b,49,23,33,39);
  108.     rinv(h,d,a,b,c,57,51,49,28);
  109.  
  110.     e=rotr(e, 3); e -= 0xA458FEA3F4933D7E;
  111.     f=rotr(f, 5); f -= 0x0D95748F728EB658;
  112.     g=rotr(g, 7); g -= 0x718BCD5882154AEE;
  113.     h=rotr(h,11); h -= 0x7B54A41DC25A59B5;
  114.  
  115.     rinv(a,e,f,g,h, 9, 5,17,45);
  116.     rinv(b,f,g,h,e,25,29,49,21);
  117.     rinv(c,g,h,e,f,17,57,33, 9);
  118.     rinv(d,h,e,f,g,57,19,49,59);
  119.    
  120.     a=rotr(a,29); a -= 0xBA7C9045F12C7F99;
  121.     b=rotr(b,37); b -= 0x24A19947B3916CF7;
  122.     c=rotr(c,41); c -= 0x0801F2E2858EFC16;
  123.     d=rotr(d,43); d -= 0x636920D871574E69;
  124.  
  125.     rinv(e,a,b,c,d,33,15, 1,47);
  126.     rinv(f,b,c,d,a,57,13,49,37);
  127.     rinv(g,c,d,a,b,25, 3,49,11);
  128.     rinv(h,d,a,b,c, 9,37,17,13);
  129.  
  130.     e=rotr(e,47); e -= 0x9216D5D98979FB1B;
  131.     f=rotr(f,53); f -= 0xD1310BA698DFB5AC;
  132.     g=rotr(g,59); g -= 0x2FFD72DBD01ADFB7;
  133.     h=rotr(h,61); h -= 0xB8E1AFED6A267E96;
  134.  
  135.     rinv(a,e,f,g,h, 9,27,17,51);
  136.     rinv(b,f,g,h,e,25,61,49,53);
  137.     rinv(c,g,h,e,f,49,23,33,39);
  138.     rinv(d,h,e,f,g,57,51,49,27);
  139.  
  140.     rinv(e,a,b,c,d,41,21,17,29);
  141.     rinv(f,b,c,d,a,33,49, 1,17);
  142.     rinv(g,c,d,a,b,41,11,17, 3);
  143.     rinv(h,d,a,b,c,17, 7,33,55);
  144.  
  145.     a=rotr(a, 3); x[0] = a - 0x243F6A8885A308D3;
  146.     b=rotr(b, 5); x[1] = b - 0x13198A2E03707344;
  147.     c=rotr(c, 7); x[2] = c - 0xA4093822299F31D0;
  148.     d=rotr(d,11); x[3] = d - 0x082EFA98EC4E6C89;
  149.     e=rotr(e,13); x[4] = e - 0x452821E638D01377;
  150.     f=rotr(f,17); x[5] = f - 0xBE5466CF34E90C6C;
  151.     g=rotr(g,19); x[6] = g - 0xC0AC29B7C97C50DD;
  152.     h=rotr(h,23); x[7] = h - 0x3F84D5B5B5470917;
  153. }
RAW Paste Data