static void mix_columns(uint8_t *state, int mode) { int i, j; uint8_t column[4]; for(i = 0; i < NB; i++) { for(j = 0; j < 4; j++) column[j] = state[4 * j + i]; if(mode == FOR_MIX) mix_column(column); else inv_mix_column(column); for(j = 0; j < 4; j++) state[4 * j + i] = column[j]; } }
static void aes_dec_round(aes_cipher_state_t* state, const aes_roundkey_t* k) { uint8_t tmp[16]; uint8_t i; uint8_t t,u,v,w; /// *** STEP 1: keyAdd *** for(i=0; i<16; ++i) { tmp[i] = state->s[i] ^ k->ks[i]; } #ifdef ENCRYPTION_DEBUG beginSerial(115200, 0); digitalWrite(23,0x01); digitalWrite(11,0x00); printString("\n\n*** STEP 1: keyAdd --> ", 0); for(i=0; i<16; ++i) { puthex((char)tmp[i],0); _delay_ms(3); } #endif /// *** STEP 2: mixColums *** inv_mix_column(&tmp[0]); inv_mix_column(&tmp[4]); inv_mix_column(&tmp[8]); inv_mix_column(&tmp[12]); // copy result for(i=0; i<16; ++i) { state->s[i] = tmp[i]; } #ifdef ENCRYPTION_DEBUG printString("\n*** STEP 2: mixColums --> ", 0); _delay_ms(3); for(i=0; i<16; ++i) { puthex((char)state->s[i],0); _delay_ms(3); } #endif /// *** STEP 3: shiftRows *** aes_invshiftcol(state->s+1, 1); aes_invshiftcol(state->s+2, 2); aes_invshiftcol(state->s+3, 3); #ifdef ENCRYPTION_DEBUG printString("\n*** STEP 3: shiftRows --> ", 0); _delay_ms(3); for(i=0; i<16; ++i) { puthex((char)state->s[i],0); _delay_ms(3); } #endif /// *** STEP 4: subBytes *** for(i=0; i<16; ++i) { state->s[i] = pgm_read_byte(aes_invsbox+state->s[i]); } #ifdef ENCRYPTION_DEBUG printString("\n*** STEP 4: subBytes --> ", 0); _delay_ms(3); for(i=0; i<16; ++i) { puthex((char)state->s[i],0); _delay_ms(3); } printString("\n", 0); #endif }