|
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 int s1; 00023 unsigned int s2; 00024 }; 00025 typedef struct group_t group; 00026 00027 #define GROUP_PARALLELISM 64 00028 00029 group static inline FF0(){ 00030 group res; 00031 res.s1=0x0; 00032 res.s2=0x0; 00033 return res; 00034 } 00035 00036 group static inline FF1(){ 00037 group res; 00038 res.s1=0xffffffff; 00039 res.s2=0xffffffff; 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 64 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 struct batch_t{ 00092 unsigned int s1; 00093 unsigned int s2; 00094 }; 00095 typedef struct batch_t batch; 00096 00097 #define BYTES_PER_BATCH 8 00098 00099 batch static inline B_FFAND(batch a,batch b){ 00100 batch res; 00101 res.s1=a.s1&b.s1; 00102 res.s2=a.s2&b.s2; 00103 return res; 00104 } 00105 00106 batch static inline B_FFOR(batch a,batch b){ 00107 batch res; 00108 res.s1=a.s1|b.s1; 00109 res.s2=a.s2|b.s2; 00110 return res; 00111 } 00112 00113 batch static inline B_FFXOR(batch a,batch b){ 00114 batch res; 00115 res.s1=a.s1^b.s1; 00116 res.s2=a.s2^b.s2; 00117 return res; 00118 } 00119 00120 00121 batch static inline B_FFN_ALL_29(){ 00122 batch res; 00123 res.s1=0x29292929; 00124 res.s2=0x29292929; 00125 return res; 00126 } 00127 batch static inline B_FFN_ALL_02(){ 00128 batch res; 00129 res.s1=0x02020202; 00130 res.s2=0x02020202; 00131 return res; 00132 } 00133 batch static inline B_FFN_ALL_04(){ 00134 batch res; 00135 res.s1=0x04040404; 00136 res.s2=0x04040404; 00137 return res; 00138 } 00139 batch static inline B_FFN_ALL_10(){ 00140 batch res; 00141 res.s1=0x10101010; 00142 res.s2=0x10101010; 00143 return res; 00144 } 00145 batch static inline B_FFN_ALL_40(){ 00146 batch res; 00147 res.s1=0x40404040; 00148 res.s2=0x40404040; 00149 return res; 00150 } 00151 batch static inline B_FFN_ALL_80(){ 00152 batch res; 00153 res.s1=0x80808080; 00154 res.s2=0x80808080; 00155 return res; 00156 } 00157 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 }