comparison aes.c @ 167:6104bbdb757b libavutil

cosmetic
author michael
date Sun, 14 Jan 2007 09:27:11 +0000
parents c7ea70dea191
children 8ebd419dcff9
comparison
equal deleted inserted replaced
166:c7ea70dea191 167:6104bbdb757b
102 mix(a->state, log8[2], log8[3], 0, 0); //FIXME replace log8 by const / optimze mix as this can be simplified alot 102 mix(a->state, log8[2], log8[3], 0, 0); //FIXME replace log8 by const / optimze mix as this can be simplified alot
103 } 103 }
104 } 104 }
105 105
106 // this is based on the reference AES code by Paulo Barreto and Vincent Rijmen 106 // this is based on the reference AES code by Paulo Barreto and Vincent Rijmen
107 AVAES *av_aes_init(uint8_t *key, int keyBits) { 107 AVAES *av_aes_init(uint8_t *key, int key_bits) {
108 AVAES *a; 108 AVAES *a;
109 int i, j, t, rconpointer = 0; 109 int i, j, t, rconpointer = 0;
110 uint8_t tk[8][4]; 110 uint8_t tk[8][4];
111 int KC= keyBits/32; 111 int KC= key_bits/32;
112 int ROUNDS= KC + 6; 112 int rounds= KC + 6;
113 113
114 if(!sbox[255]){ 114 if(!sbox[255]){
115 j=1; 115 j=1;
116 for(i=0; i<255; i++){ 116 for(i=0; i<255; i++){
117 alog8[i]= 117 alog8[i]=
129 sbox [i]= j; 129 sbox [i]= j;
130 // av_log(NULL, AV_LOG_ERROR, "%d, ", log8[i]); 130 // av_log(NULL, AV_LOG_ERROR, "%d, ", log8[i]);
131 } 131 }
132 } 132 }
133 133
134 if(keyBits!=128 && keyBits!=192 && keyBits!=256) 134 if(key_bits!=128 && key_bits!=192 && key_bits!=256)
135 return NULL; 135 return NULL;
136 136
137 a= av_malloc(sizeof(AVAES)); 137 a= av_malloc(sizeof(AVAES));
138 a->rounds= ROUNDS; 138 a->rounds= rounds;
139 139
140 memcpy(tk, key, KC*4); 140 memcpy(tk, key, KC*4);
141 141
142 for(t= 0; t < (ROUNDS+1)*4; ) { 142 for(t= 0; t < (rounds+1)*4; ) {
143 for(j = 0; (j < KC) && (t < (ROUNDS+1)*4); j++, t++) 143 for(j = 0; (j < KC) && (t < (rounds+1)*4); j++, t++)
144 for(i = 0; i < 4; i++) 144 for(i = 0; i < 4; i++)
145 a->round_key[0][t][i] = tk[j][i]; 145 a->round_key[0][t][i] = tk[j][i];
146 146
147 for(i = 0; i < 4; i++) 147 for(i = 0; i < 4; i++)
148 tk[0][i] ^= sbox[tk[KC-1][(i+1)&3]]; 148 tk[0][i] ^= sbox[tk[KC-1][(i+1)&3]];