22 #include "../gf256mul/gf256mul.h"
39 void aes_invshiftcol(
void *data, uint8_t shift){
41 tmp[0] = ((uint8_t*)data)[ 0];
42 tmp[1] = ((uint8_t*)data)[ 4];
43 tmp[2] = ((uint8_t*)data)[ 8];
44 tmp[3] = ((uint8_t*)data)[12];
45 ((uint8_t*)data)[ 0] = tmp[(4-shift+0)&3];
46 ((uint8_t*)data)[ 4] = tmp[(4-shift+1)&3];
47 ((uint8_t*)data)[ 8] = tmp[(4-shift+2)&3];
48 ((uint8_t*)data)[12] = tmp[(4-shift+3)&3];
57 tmp[i] = state->s[i] ^ k->ks[i];
61 t = tmp[4*i+3] ^ tmp[4*i+2];
62 u = tmp[4*i+1] ^ tmp[4*i+0];
64 v = gf256mul(0x09, v, 0x1b);
65 w = v ^ gf256mul(0x04, tmp[4*i+2] ^ tmp[4*i+0], 0x1b);
66 v = v ^ gf256mul(0x04, tmp[4*i+3] ^ tmp[4*i+1], 0x1b);
67 state->s[4*i+3] = tmp[4*i+3] ^ v ^ gf256mul(0x02, tmp[4*i+0] ^ tmp[4*i+3], 0x1b);
68 state->s[4*i+2] = tmp[4*i+2] ^ w ^ gf256mul(0x02, t, 0x1b);
69 state->s[4*i+1] = tmp[4*i+1] ^ v ^ gf256mul(0x02, tmp[4*i+2] ^ tmp[4*i+1], 0x1b);
70 state->s[4*i+0] = tmp[4*i+0] ^ w ^ gf256mul(0x02, u, 0x1b);
96 aes_invshiftcol(state->s+1, 1);
97 aes_invshiftcol(state->s+2, 2);
98 aes_invshiftcol(state->s+3, 3);
101 state->s[i] = ROMEM_READ_BYTE(aes_invsbox_T_p + state->s[i]);
111 state->s[i] ^= k->ks[i];
114 aes_invshiftcol(state->s+1, 1);
115 aes_invshiftcol(state->s+2, 2);
116 aes_invshiftcol(state->s+3, 3);
119 state->s[i] = ROMEM_READ_BYTE(aes_invsbox_T_p + state->s[i]);
125 aes_dec_firstround(state, &(ks->key[i=rounds]));
126 for(;rounds>1;--rounds){
128 aes_dec_round(state, &(ks->key[i]));
131 state->s[i] ^= ks->key[0].ks[i];
void aes128_dec(void *buffer, aes128_ctx_t *ctx)
decrypt with 128 bit key.
void aes256_dec(void *buffer, aes256_ctx_t *ctx)
decrypt with 256 bit key.
void aes192_dec(void *buffer, aes192_ctx_t *ctx)
decrypt with 192 bit key.