Commit 0c5d2819 authored by Michael Niedermayer's avatar Michael Niedermayer
Browse files

merge encrypt and decrypt so the source is simpler and the compiler can choose...

merge encrypt and decrypt so the source is simpler and the compiler can choose with inlining if it wants speed or small size

Originally committed as revision 7494 to svn://
parent 28b51235
......@@ -71,40 +71,30 @@ static inline void mix(uint8_t state[4][4], uint32_t multbl[4][256]){
void av_aes_decrypt(AVAES *a){
static inline void crypt(AVAES *a, int s, uint8_t *sbox, uint32_t *multbl){
int t, r;
for(r=a->rounds; r>1; r--){
addkey(a->state, a->round_key[r]);
mix(a->state, dec_multbl);
mix(a->state, multbl);
addkey(a->state, a->round_key[1]);
SUBSHIFT0((a->state[0]+0), inv_sbox)
SUBSHIFT3((a->state[0]+1), inv_sbox)
SUBSHIFT2((a->state[0]+2), inv_sbox)
SUBSHIFT1((a->state[0]+3), inv_sbox)
SUBSHIFT0((a->state[0]+0 ), sbox)
SUBSHIFT3((a->state[0]+1+s), sbox)
SUBSHIFT2((a->state[0]+2 ), sbox)
SUBSHIFT1((a->state[0]+3-s), sbox)
addkey(a->state, a->round_key[0]);
void av_aes_encrypt(AVAES *a){
int r, t;
void av_aes_decrypt(AVAES *a){
crypt(a, 0, inv_sbox, dec_multbl);
for(r=0; r<a->rounds-1; r++){
addkey(a->state, a->round_key[r]);
mix(a->state, enc_multbl);
addkey(a->state, a->round_key[r]);
SUBSHIFT0((a->state[0]+0), sbox)
SUBSHIFT1((a->state[0]+1), sbox)
SUBSHIFT2((a->state[0]+2), sbox)
SUBSHIFT3((a->state[0]+3), sbox)
addkey(a->state, a->round_key[r+1]);
void av_aes_encrypt(AVAES *a){
crypt(a, 2, sbox, enc_multbl);
static init_multbl2(uint8_t tbl[1024], int c[4], uint8_t *log8, uint8_t *alog8, uint8_t *sbox){
......@@ -188,6 +178,11 @@ AVAES *av_aes_init(uint8_t *key, int key_bits, int decrypt) {
a->round_key[i][0][j]= sbox[a->round_key[i][0][j]];
mix(a->round_key[i], dec_multbl);
for(i=0; i<(rounds+1)/2; i++){
for(j=0; j<16; j++)
FFSWAP(int, a->round_key[i][0][j], a->round_key[rounds-i][0][j]);
return a;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment