comparison aes.c @ 174:263bbdc10c1e libavutil

simplify round_key generation by writing over the end but ensuring that theres some irrelevant stuff afterwards
author michael
date Sun, 14 Jan 2007 13:46:20 +0000
parents 712b0f43e8ac
children 937928db9781
comparison
equal deleted inserted replaced
173:712b0f43e8ac 174:263bbdc10c1e
21 #include "common.h" 21 #include "common.h"
22 #include "log.h" 22 #include "log.h"
23 #include "aes.h" 23 #include "aes.h"
24 24
25 typedef struct AVAES{ 25 typedef struct AVAES{
26 uint8_t round_key[15][4][4];
26 uint8_t state[4][4]; 27 uint8_t state[4][4];
27 uint8_t round_key[15][4][4];
28 int rounds; 28 int rounds;
29 }AVAES; 29 }AVAES;
30 30
31 static const uint8_t rcon[11] = { 31 static const uint8_t rcon[11] = {
32 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c 32 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c
141 a= av_malloc(sizeof(AVAES)); 141 a= av_malloc(sizeof(AVAES));
142 a->rounds= rounds; 142 a->rounds= rounds;
143 143
144 memcpy(tk, key, KC*4); 144 memcpy(tk, key, KC*4);
145 145
146 for(t= 0; t < (rounds+1)*4; ) { 146 for(t= 0; t < (rounds+1)*4;) {
147 for(j = 0; j < KC && t < (rounds+1)*4; j++, t++) 147 memcpy(a->round_key[0][t], tk, KC*4);
148 memcpy(a->round_key[0][t], tk[j], 4); 148 t+= KC;
149 149
150 for(i = 0; i < 4; i++) 150 for(i = 0; i < 4; i++)
151 tk[0][i] ^= sbox[tk[KC-1][(i+1)&3]]; 151 tk[0][i] ^= sbox[tk[KC-1][(i+1)&3]];
152 tk[0][0] ^= rcon[rconpointer++]; 152 tk[0][0] ^= rcon[rconpointer++];
153 153