|
SASC
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 char s1,s2,s3,s4; 00023 }; 00024 typedef struct group_t group; 00025 00026 #define GROUP_PARALLELISM 32 00027 00028 group static inline FF0(){ 00029 group res; 00030 res.s1=0x0; 00031 res.s2=0x0; 00032 res.s3=0x0; 00033 res.s4=0x0; 00034 return res; 00035 } 00036 00037 group static inline FF1(){ 00038 group res; 00039 res.s1=0xff; 00040 res.s2=0xff; 00041 res.s3=0xff; 00042 res.s4=0xff; 00043 return res; 00044 } 00045 00046 group static inline FFAND(group a,group b){ 00047 group res; 00048 res.s1=a.s1&b.s1; 00049 res.s2=a.s2&b.s2; 00050 res.s3=a.s3&b.s3; 00051 res.s4=a.s4&b.s4; 00052 return res; 00053 } 00054 00055 group static inline FFOR(group a,group b){ 00056 group res; 00057 res.s1=a.s1|b.s1; 00058 res.s2=a.s2|b.s2; 00059 res.s3=a.s3|b.s3; 00060 res.s4=a.s4|b.s4; 00061 return res; 00062 } 00063 00064 group static inline FFXOR(group a,group b){ 00065 group res; 00066 res.s1=a.s1^b.s1; 00067 res.s2=a.s2^b.s2; 00068 res.s3=a.s3^b.s3; 00069 res.s4=a.s4^b.s4; 00070 return res; 00071 } 00072 00073 group static inline FFNOT(group a){ 00074 group res; 00075 res.s1=~a.s1; 00076 res.s2=~a.s2; 00077 res.s3=~a.s3; 00078 res.s4=~a.s4; 00079 return res; 00080 } 00081 00082 00083 /* 64 rows of 32 bits */ 00084 00085 void static inline FFTABLEIN(unsigned char *tab, int g, unsigned char *data){ 00086 *(((int *)tab)+g)=*((int *)data); 00087 *(((int *)tab)+32+g)=*(((int *)data)+1); 00088 } 00089 00090 void static inline FFTABLEOUT(unsigned char *data, unsigned char *tab, int g){ 00091 *((int *)data)=*(((int *)tab)+g); 00092 *(((int *)data)+1)=*(((int *)tab)+32+g); 00093 } 00094 00095 void static inline FFTABLEOUTXORNBY(int n, unsigned char *data, unsigned char *tab, int g){ 00096 int j; 00097 for(j=0;j<n;j++){ 00098 *(data+j)^=*(tab+4*(g+(j>=4?32-1:0))+j); 00099 } 00100 } 00101 00102 struct batch_t{ 00103 unsigned char s1,s2,s3,s4; 00104 }; 00105 typedef struct batch_t batch; 00106 00107 #define BYTES_PER_BATCH 4 00108 00109 batch static inline B_FFAND(batch a,batch b){ 00110 batch res; 00111 res.s1=a.s1&b.s1; 00112 res.s2=a.s2&b.s2; 00113 res.s3=a.s3&b.s3; 00114 res.s4=a.s4&b.s4; 00115 return res; 00116 } 00117 00118 batch static inline B_FFOR(batch a,batch b){ 00119 batch res; 00120 res.s1=a.s1|b.s1; 00121 res.s2=a.s2|b.s2; 00122 res.s3=a.s3|b.s3; 00123 res.s4=a.s4|b.s4; 00124 return res; 00125 } 00126 00127 batch static inline B_FFXOR(batch a,batch b){ 00128 batch res; 00129 res.s1=a.s1^b.s1; 00130 res.s2=a.s2^b.s2; 00131 res.s3=a.s3^b.s3; 00132 res.s4=a.s4^b.s4; 00133 return res; 00134 } 00135 00136 00137 batch static inline B_FFN_ALL_29(){ 00138 batch res; 00139 res.s1=0x29; 00140 res.s2=0x29; 00141 res.s3=0x29; 00142 res.s4=0x29; 00143 return res; 00144 } 00145 batch static inline B_FFN_ALL_02(){ 00146 batch res; 00147 res.s1=0x02; 00148 res.s2=0x02; 00149 res.s3=0x02; 00150 res.s4=0x02; 00151 return res; 00152 } 00153 batch static inline B_FFN_ALL_04(){ 00154 batch res; 00155 res.s1=0x04; 00156 res.s2=0x04; 00157 res.s3=0x04; 00158 res.s4=0x04; 00159 return res; 00160 } 00161 batch static inline B_FFN_ALL_10(){ 00162 batch res; 00163 res.s1=0x10; 00164 res.s2=0x10; 00165 res.s3=0x10; 00166 res.s4=0x10; 00167 return res; 00168 } 00169 batch static inline B_FFN_ALL_40(){ 00170 batch res; 00171 res.s1=0x40; 00172 res.s2=0x40; 00173 res.s3=0x40; 00174 res.s4=0x40; 00175 return res; 00176 } 00177 batch static inline B_FFN_ALL_80(){ 00178 batch res; 00179 res.s1=0x80; 00180 res.s2=0x80; 00181 res.s3=0x80; 00182 res.s4=0x80; 00183 return res; 00184 } 00185 00186 batch static inline B_FFSH8L(batch a,int n){ 00187 batch res; 00188 res.s1=a.s1<<n; 00189 res.s2=a.s2<<n; 00190 res.s3=a.s3<<n; 00191 res.s4=a.s4<<n; 00192 return res; 00193 } 00194 00195 batch static inline B_FFSH8R(batch a,int n){ 00196 batch res; 00197 res.s1=a.s1>>n; 00198 res.s2=a.s2>>n; 00199 res.s3=a.s3>>n; 00200 res.s4=a.s4>>n; 00201 return res; 00202 } 00203 00204 00205 void static inline M_EMPTY(void){ 00206 }