⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stream.c

📁 这是一个LINUX环境的 VDR 插件源代码,可支持Irdeto, Seca, Viaccess, Nagra, Conax & Cryptoworks等CA系统的读卡、共享等操作。
💻 C
📖 第 1 页 / 共 3 页
字号:
/* FFdecsa -- fast decsa algorithm * * Copyright (C) 2003-2004  fatih89r * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */// define statics only once, when STREAM_INIT#ifdef STREAM_INITstruct stream_regs {  group A[32+10][4]; // 32 because we will move back (virtual shift register)  group B[32+10][4]; // 32 because we will move back (virtual shift register)  group X[4];  group Y[4];  group Z[4];  group D[4];  group E[4];  group F[4];  group p;  group q;  group r;  };static inline void trasp64_32_88ccw(unsigned char *data){/* 64 rows of 32 bits transposition (bytes transp. - 8x8 rotate counterclockwise)*/#define row ((unsigned int *)data)  int i,j;  for(j=0;j<64;j+=32){    unsigned int t,b;    for(i=0;i<16;i++){      t=row[j+i];      b=row[j+16+i];      row[j+i]   = (t&0x0000ffff)      | ((b           )<<16);      row[j+16+i]=((t           )>>16) |  (b&0xffff0000) ;    }  }  for(j=0;j<64;j+=16){    unsigned int t,b;    for(i=0;i<8;i++){      t=row[j+i];      b=row[j+8+i];      row[j+i]   = (t&0x00ff00ff)     | ((b&0x00ff00ff)<<8);      row[j+8+i] =((t&0xff00ff00)>>8) |  (b&0xff00ff00);    }  }  for(j=0;j<64;j+=8){    unsigned int t,b;    for(i=0;i<4;i++){      t=row[j+i];      b=row[j+4+i];      row[j+i]   =((t&0x0f0f0f0f)<<4) |  (b&0x0f0f0f0f);      row[j+4+i] = (t&0xf0f0f0f0)     | ((b&0xf0f0f0f0)>>4);    }  }  for(j=0;j<64;j+=4){    unsigned int t,b;    for(i=0;i<2;i++){      t=row[j+i];      b=row[j+2+i];      row[j+i]   =((t&0x33333333)<<2) |  (b&0x33333333);      row[j+2+i] = (t&0xcccccccc)     | ((b&0xcccccccc)>>2);    }  }  for(j=0;j<64;j+=2){    unsigned int t,b;    for(i=0;i<1;i++){      t=row[j+i];      b=row[j+1+i];      row[j+i]   =((t&0x55555555)<<1) |  (b&0x55555555);      row[j+1+i] = (t&0xaaaaaaaa)     | ((b&0xaaaaaaaa)>>1);    }  }#undef row}static inline void trasp64_32_88cw(unsigned char *data){/* 64 rows of 32 bits transposition (bytes transp. - 8x8 rotate clockwise)*/#define row ((unsigned int *)data)  int i,j;  for(j=0;j<64;j+=32){    unsigned int t,b;    for(i=0;i<16;i++){      t=row[j+i];      b=row[j+16+i];      row[j+i]   = (t&0x0000ffff)      | ((b           )<<16);      row[j+16+i]=((t           )>>16) |  (b&0xffff0000) ;    }  }  for(j=0;j<64;j+=16){    unsigned int t,b;    for(i=0;i<8;i++){      t=row[j+i];      b=row[j+8+i];      row[j+i]   = (t&0x00ff00ff)     | ((b&0x00ff00ff)<<8);      row[j+8+i] =((t&0xff00ff00)>>8) |  (b&0xff00ff00);    }  }  for(j=0;j<64;j+=8){    unsigned int t,b;    for(i=0;i<4;i++){      t=row[j+i];      b=row[j+4+i];      row[j+i]  =((t&0xf0f0f0f0)>>4) |   (b&0xf0f0f0f0);      row[j+4+i]= (t&0x0f0f0f0f)     |  ((b&0x0f0f0f0f)<<4);    }  }  for(j=0;j<64;j+=4){    unsigned int t,b;    for(i=0;i<2;i++){      t=row[j+i];      b=row[j+2+i];      row[j+i]  =((t&0xcccccccc)>>2) |  (b&0xcccccccc);      row[j+2+i]= (t&0x33333333)     | ((b&0x33333333)<<2);    }  }  for(j=0;j<64;j+=2){    unsigned int t,b;    for(i=0;i<1;i++){      t=row[j+i];      b=row[j+1+i];      row[j+i]  =((t&0xaaaaaaaa)>>1) |  (b&0xaaaaaaaa);      row[j+1+i]= (t&0x55555555)     | ((b&0x55555555)<<1);    }  }#undef row}//64-64----------------------------------------------------------static inline void trasp64_64_88ccw(unsigned char *data){/* 64 rows of 64 bits transposition (bytes transp. - 8x8 rotate counterclockwise)*/#define row ((unsigned long long int *)data)  int i,j;  for(j=0;j<64;j+=64){    unsigned long long int t,b;    for(i=0;i<32;i++){      t=row[j+i];      b=row[j+32+i];      row[j+i]   = (t&0x00000000ffffffffULL)      | ((b                      )<<32);      row[j+32+i]=((t                      )>>32) |  (b&0xffffffff00000000ULL) ;    }  }  for(j=0;j<64;j+=32){    unsigned long long int t,b;    for(i=0;i<16;i++){      t=row[j+i];      b=row[j+16+i];      row[j+i]   = (t&0x0000ffff0000ffffULL)      | ((b&0x0000ffff0000ffffULL)<<16);      row[j+16+i]=((t&0xffff0000ffff0000ULL)>>16) |  (b&0xffff0000ffff0000ULL) ;    }  }  for(j=0;j<64;j+=16){    unsigned long long int t,b;    for(i=0;i<8;i++){      t=row[j+i];      b=row[j+8+i];      row[j+i]   = (t&0x00ff00ff00ff00ffULL)     | ((b&0x00ff00ff00ff00ffULL)<<8);      row[j+8+i] =((t&0xff00ff00ff00ff00ULL)>>8) |  (b&0xff00ff00ff00ff00ULL);    }  }  for(j=0;j<64;j+=8){    unsigned long long int t,b;    for(i=0;i<4;i++){      t=row[j+i];      b=row[j+4+i];      row[j+i]   =((t&0x0f0f0f0f0f0f0f0fULL)<<4) |  (b&0x0f0f0f0f0f0f0f0fULL);      row[j+4+i] = (t&0xf0f0f0f0f0f0f0f0ULL)     | ((b&0xf0f0f0f0f0f0f0f0ULL)>>4);    }  }  for(j=0;j<64;j+=4){    unsigned long long int t,b;    for(i=0;i<2;i++){      t=row[j+i];      b=row[j+2+i];      row[j+i]   =((t&0x3333333333333333ULL)<<2) |  (b&0x3333333333333333ULL);      row[j+2+i] = (t&0xccccccccccccccccULL)     | ((b&0xccccccccccccccccULL)>>2);    }  }  for(j=0;j<64;j+=2){    unsigned long long int t,b;    for(i=0;i<1;i++){      t=row[j+i];      b=row[j+1+i];      row[j+i]   =((t&0x5555555555555555ULL)<<1) |  (b&0x5555555555555555ULL);      row[j+1+i] = (t&0xaaaaaaaaaaaaaaaaULL)     | ((b&0xaaaaaaaaaaaaaaaaULL)>>1);    }  }#undef row}static inline void trasp64_64_88cw(unsigned char *data){/* 64 rows of 64 bits transposition (bytes transp. - 8x8 rotate clockwise)*/#define row ((unsigned long long int *)data)  int i,j;  for(j=0;j<64;j+=64){    unsigned long long int t,b;    for(i=0;i<32;i++){      t=row[j+i];      b=row[j+32+i];      row[j+i]   = (t&0x00000000ffffffffULL)      | ((b                      )<<32);      row[j+32+i]=((t                      )>>32) |  (b&0xffffffff00000000ULL) ;    }  }  for(j=0;j<64;j+=32){    unsigned long long int t,b;    for(i=0;i<16;i++){      t=row[j+i];      b=row[j+16+i];      row[j+i]   = (t&0x0000ffff0000ffffULL)      | ((b&0x0000ffff0000ffffULL)<<16);      row[j+16+i]=((t&0xffff0000ffff0000ULL)>>16) |  (b&0xffff0000ffff0000ULL) ;    }  }  for(j=0;j<64;j+=16){    unsigned long long int t,b;    for(i=0;i<8;i++){      t=row[j+i];      b=row[j+8+i];      row[j+i]   = (t&0x00ff00ff00ff00ffULL)     | ((b&0x00ff00ff00ff00ffULL)<<8);      row[j+8+i] =((t&0xff00ff00ff00ff00ULL)>>8) |  (b&0xff00ff00ff00ff00ULL);    }  }  for(j=0;j<64;j+=8){    unsigned long long int t,b;    for(i=0;i<4;i++){      t=row[j+i];      b=row[j+4+i];      row[j+i]   =((t&0xf0f0f0f0f0f0f0f0ULL)>>4) |   (b&0xf0f0f0f0f0f0f0f0ULL);      row[j+4+i] = (t&0x0f0f0f0f0f0f0f0fULL)     |  ((b&0x0f0f0f0f0f0f0f0fULL)<<4);    }  }  for(j=0;j<64;j+=4){    unsigned long long int t,b;    for(i=0;i<2;i++){      t=row[j+i];      b=row[j+2+i];      row[j+i]   =((t&0xccccccccccccccccULL)>>2) |  (b&0xccccccccccccccccULL);      row[j+2+i] = (t&0x3333333333333333ULL)     | ((b&0x3333333333333333ULL)<<2);    }  }  for(j=0;j<64;j+=2){    unsigned long long int t,b;    for(i=0;i<1;i++){      t=row[j+i];      b=row[j+1+i];      row[j+i]   =((t&0xaaaaaaaaaaaaaaaaULL)>>1) |  (b&0xaaaaaaaaaaaaaaaaULL);      row[j+1+i] = (t&0x5555555555555555ULL)     | ((b&0x5555555555555555ULL)<<1);    }  }#undef row}//64-128----------------------------------------------------------static inline void trasp64_128_88ccw(unsigned char *data){/* 64 rows of 128 bits transposition (bytes transp. - 8x8 rotate counterclockwise)*/#define halfrow ((unsigned long long int *)data)  int i,j;  for(j=0;j<64;j+=64){    unsigned long long int t,b;    for(i=0;i<32;i++){      t=halfrow[2*(j+i)];      b=halfrow[2*(j+32+i)];      halfrow[2*(j+i)]   = (t&0x00000000ffffffffULL)      | ((b                      )<<32);      halfrow[2*(j+32+i)]=((t                      )>>32) |  (b&0xffffffff00000000ULL) ;      t=halfrow[2*(j+i)+1];      b=halfrow[2*(j+32+i)+1];      halfrow[2*(j+i)+1]   = (t&0x00000000ffffffffULL)      | ((b                      )<<32);      halfrow[2*(j+32+i)+1]=((t                      )>>32) |  (b&0xffffffff00000000ULL) ;    }  }  for(j=0;j<64;j+=32){    unsigned long long int t,b;    for(i=0;i<16;i++){      t=halfrow[2*(j+i)];      b=halfrow[2*(j+16+i)];      halfrow[2*(j+i)]   = (t&0x0000ffff0000ffffULL)      | ((b&0x0000ffff0000ffffULL)<<16);      halfrow[2*(j+16+i)]=((t&0xffff0000ffff0000ULL)>>16) |  (b&0xffff0000ffff0000ULL) ;      t=halfrow[2*(j+i)+1];      b=halfrow[2*(j+16+i)+1];      halfrow[2*(j+i)+1]   = (t&0x0000ffff0000ffffULL)      | ((b&0x0000ffff0000ffffULL)<<16);      halfrow[2*(j+16+i)+1]=((t&0xffff0000ffff0000ULL)>>16) |  (b&0xffff0000ffff0000ULL) ;    }  }  for(j=0;j<64;j+=16){    unsigned long long int t,b;    for(i=0;i<8;i++){      t=halfrow[2*(j+i)];      b=halfrow[2*(j+8+i)];      halfrow[2*(j+i)]   = (t&0x00ff00ff00ff00ffULL)     | ((b&0x00ff00ff00ff00ffULL)<<8);      halfrow[2*(j+8+i)] =((t&0xff00ff00ff00ff00ULL)>>8) |  (b&0xff00ff00ff00ff00ULL);      t=halfrow[2*(j+i)+1];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -