Professional Documents
Culture Documents
Code C Aes
Code C Aes
*
* author : Vincent Ri j men ,
* Thi s c ode is based on the o f f i c i al ref erence c ode
* by Paulo Barret o and Vincent Rijmen
*
* Thi s c ode is placed in the publ i c domain .
* Without any warranty of f itne s s f or any purpo se .
*/
#include < stdi o . h>
typedef uns igned char word8 ;
typedef uns igned int word32 ;
/* The tables Logtable and Alogtable are used to perf orm
* mult ipl i cat i ons in GF (256)
*/
word8 Logt able [256] = {
0 , 0 , 25 , 1 , 50 , 2 , 26 , 1 98 , 75 , 1 99 , 27 , 104 , 5 1 , 238 , 223 , 3 ,
100 , 4 , 224 , 14 , 5 2 , 141 , 129 , 239 , 76 , 1 1 3 , 8 , 200 , 248 , 105 , 28 , 1 93 ,
125 , 1 94 , 29 , 18 1 , 249 , 1 85 , 39 , 1 06 , 77 , 228 , 166 , 1 1 4 , 154 , 201 , 9 ,
120 ,
1 0 1 , 47 , 138 , 5 , 33 , 1 5 , 225 , 36 , 18 , 240 , 1 30 , 69 , 53 , 147 , 2 1 8 , 142 ,
150 , 143 , 2 19 , 189 , 54 , 208 , 206 , 148 , 1 9 , 92 , 2 1 0 , 241 , 64 , 70 , 13 1 ,
56 ,
if (a && b) return Alogt able [ (Logt able [aJ + Logtable [bJ ) %255J ;
e l s e return 0 ;
}
void AddRoundKey (word8 a [4J [MAXBCJ , word8 rk [4J [MAXBCJ ) {
/* XOR c orre sponding t ext input and round key input byt e s
*/
int i , j ;
f or ( i = 0 ; i < 4 ; i++)
f or C j = 0 ; j < BC ; j ++) a [iJ [j J rk [iJ [j J ;
}
void SubByt e s (word8 a [4J [MAXBCl , word8 box [256J ) {
}
/* Replace every byt e of the input by the byt e at that place
* in the non-l inear S-box
*/
int i , j ;
f or ( i = O J i < 4 ; i++)
f or (j = 0 ; j < BC ; j ++) a [iJ J = box[a [i][j]]
}