1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
/* 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.
*/
struct group_t{
unsigned int s1;
unsigned int s2;
};
typedef struct group_t group;
#define GROUP_PARALLELISM 64
group static inline FF0(){
group res;
res.s1=0x0;
res.s2=0x0;
return res;
}
group static inline FF1(){
group res;
res.s1=0xffffffff;
res.s2=0xffffffff;
return res;
}
group static inline FFAND(group a,group b){
group res;
res.s1=a.s1&b.s1;
res.s2=a.s2&b.s2;
return res;
}
group static inline FFOR(group a,group b){
group res;
res.s1=a.s1|b.s1;
res.s2=a.s2|b.s2;
return res;
}
group static inline FFXOR(group a,group b){
group res;
res.s1=a.s1^b.s1;
res.s2=a.s2^b.s2;
return res;
}
group static inline FFNOT(group a){
group res;
res.s1=~a.s1;
res.s2=~a.s2;
return res;
}
/* 64 rows of 64 bits */
void static inline FFTABLEIN(unsigned char *tab, int g, unsigned char *data){
*(((int *)tab)+2*g)=*((int *)data);
*(((int *)tab)+2*g+1)=*(((int *)data)+1);
}
void static inline FFTABLEOUT(unsigned char *data, unsigned char *tab, int g){
*((int *)data)=*(((int *)tab)+2*g);
*(((int *)data)+1)=*(((int *)tab)+2*g+1);
}
void static inline FFTABLEOUTXORNBY(int n, unsigned char *data, unsigned char *tab, int g){
int j;
for(j=0;j<n;j++){
*(data+j)^=*(tab+8*g+j);
}
}
struct batch_t{
unsigned int s1;
unsigned int s2;
};
typedef struct batch_t batch;
#define BYTES_PER_BATCH 8
batch static inline B_FFAND(batch a,batch b){
batch res;
res.s1=a.s1&b.s1;
res.s2=a.s2&b.s2;
return res;
}
batch static inline B_FFOR(batch a,batch b){
batch res;
res.s1=a.s1|b.s1;
res.s2=a.s2|b.s2;
return res;
}
batch static inline B_FFXOR(batch a,batch b){
batch res;
res.s1=a.s1^b.s1;
res.s2=a.s2^b.s2;
return res;
}
batch static inline B_FFN_ALL_29(){
batch res;
res.s1=0x29292929;
res.s2=0x29292929;
return res;
}
batch static inline B_FFN_ALL_02(){
batch res;
res.s1=0x02020202;
res.s2=0x02020202;
return res;
}
batch static inline B_FFN_ALL_04(){
batch res;
res.s1=0x04040404;
res.s2=0x04040404;
return res;
}
batch static inline B_FFN_ALL_10(){
batch res;
res.s1=0x10101010;
res.s2=0x10101010;
return res;
}
batch static inline B_FFN_ALL_40(){
batch res;
res.s1=0x40404040;
res.s2=0x40404040;
return res;
}
batch static inline B_FFN_ALL_80(){
batch res;
res.s1=0x80808080;
res.s2=0x80808080;
return res;
}
batch static inline B_FFSH8L(batch a,int n){
batch res;
res.s1=a.s1<<n;
res.s2=a.s2<<n;
return res;
}
batch static inline B_FFSH8R(batch a,int n){
batch res;
res.s1=a.s1>>n;
res.s2=a.s2>>n;
return res;
}
void static inline M_EMPTY(void){
}
|