|
SASC-NG
DVBSoftCAM
|
00001 /* FFdecsa -- fast decsa algorithm 00002 * 00003 * Copyright (C) 2003-2004 fatih89r 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 00021 struct group_t{ 00022 unsigned long long int s1; 00023 unsigned long long int s2; 00024 }; 00025 typedef struct group_t group; 00026 00027 #define GROUP_PARALLELISM 128 00028 00029 group static inline FF0(){ 00030 group res; 00031 res.s1=0x0ULL; 00032 res.s2=0x0ULL; 00033 return res; 00034 } 00035 00036 group static inline FF1(){ 00037 group res; 00038 res.s1=0xffffffffffffffffULL; 00039 res.s2=0xffffffffffffffffULL; 00040 return res; 00041 } 00042 00043 group static inline FFAND(group a,group b){ 00044 group res; 00045 res.s1=a.s1&b.s1; 00046 res.s2=a.s2&b.s2; 00047 return res; 00048 } 00049 00050 group static inline FFOR(group a,group b){ 00051 group res; 00052 res.s1=a.s1|b.s1; 00053 res.s2=a.s2|b.s2; 00054 return res; 00055 } 00056 00057 group static inline FFXOR(group a,group b){ 00058 group res; 00059 res.s1=a.s1^b.s1; 00060 res.s2=a.s2^b.s2; 00061 return res; 00062 } 00063 00064 group static inline FFNOT(group a){ 00065 group res; 00066 res.s1=~a.s1; 00067 res.s2=~a.s2; 00068 return res; 00069 } 00070 00071 00072 /* 64 rows of 128 bits */ 00073 00074 void static inline FFTABLEIN(unsigned char *tab, int g, unsigned char *data){ 00075 *(((int *)tab)+2*g)=*((int *)data); 00076 *(((int *)tab)+2*g+1)=*(((int *)data)+1); 00077 } 00078 00079 void static inline FFTABLEOUT(unsigned char *data, unsigned char *tab, int g){ 00080 *((int *)data)=*(((int *)tab)+2*g); 00081 *(((int *)data)+1)=*(((int *)tab)+2*g+1); 00082 } 00083 00084 void static inline FFTABLEOUTXORNBY(int n, unsigned char *data, unsigned char *tab, int g){ 00085 int j; 00086 for(j=0;j<n;j++){ 00087 *(data+j)^=*(tab+8*g+j); 00088 } 00089 } 00090 00091 00092 struct batch_t{ 00093 unsigned long long int s1; 00094 unsigned long long int s2; 00095 }; 00096 typedef struct batch_t batch; 00097 00098 #define BYTES_PER_BATCH 16 00099 00100 batch static inline B_FFAND(batch a,batch b){ 00101 batch res; 00102 res.s1=a.s1&b.s1; 00103 res.s2=a.s2&b.s2; 00104 return res; 00105 } 00106 00107 batch static inline B_FFOR(batch a,batch b){ 00108 batch res; 00109 res.s1=a.s1|b.s1; 00110 res.s2=a.s2|b.s2; 00111 return res; 00112 } 00113 00114 batch static inline B_FFXOR(batch a,batch b){ 00115 batch res; 00116 res.s1=a.s1^b.s1; 00117 res.s2=a.s2^b.s2; 00118 return res; 00119 } 00120 00121 00122 batch static inline B_FFN_ALL_29(){ 00123 batch res; 00124 res.s1=0x2929292929292929ULL; 00125 res.s2=0x2929292929292929ULL; 00126 return res; 00127 } 00128 00129 batch static inline B_FFN_ALL_02(){ 00130 batch res; 00131 res.s1=0x0202020202020202ULL; 00132 res.s2=0x0202020202020202ULL; 00133 return res; 00134 } 00135 batch static inline B_FFN_ALL_04(){ 00136 batch res; 00137 res.s1=0x0404040404040404ULL; 00138 res.s2=0x0404040404040404ULL; 00139 return res; 00140 } 00141 batch static inline B_FFN_ALL_10(){ 00142 batch res; 00143 res.s1=0x1010101010101010ULL; 00144 res.s2=0x1010101010101010ULL; 00145 return res; 00146 } 00147 batch static inline B_FFN_ALL_40(){ 00148 batch res; 00149 res.s1=0x4040404040404040ULL; 00150 res.s2=0x4040404040404040ULL; 00151 return res; 00152 } 00153 batch static inline B_FFN_ALL_80(){ 00154 batch res; 00155 res.s1=0x8080808080808080ULL; 00156 res.s2=0x8080808080808080ULL; 00157 return res; 00158 } 00159 batch static inline B_FFSH8L(batch a,int n){ 00160 batch res; 00161 res.s1=a.s1<<n; 00162 res.s2=a.s2<<n; 00163 return res; 00164 } 00165 00166 batch static inline B_FFSH8R(batch a,int n){ 00167 batch res; 00168 res.s1=a.s1>>n; 00169 res.s2=a.s2>>n; 00170 return res; 00171 } 00172 00173 00174 void static inline M_EMPTY(void){ 00175 }