Esempio n. 1
0
File: aes.c Progetto: noahp/aes_c
// Decrypt a single 128 bit block by a 128 bit key using AES
// http://en.wikipedia.org/wiki/Advanced_Encryption_Standard
void AES_Decrypt(unsigned char *data, unsigned char *key) {
  int i; // To count the rounds

  // Key expansion
  unsigned char keys[176];
  expand_key(key,keys);

  // Reverse the final Round
  xor_round_key(data,keys,10);
  shift_rows_inv(data);
  sub_bytes_inv(data, 16);

  // Reverse the middle rounds
  for (i=0; i<9; i++) {
    xor_round_key(data,keys,9-i);
    mix_cols_inv(data);
    shift_rows_inv(data);
    sub_bytes_inv(data, 16);
  }

  // Reverse the first Round
  xor_round_key(data, keys, 0);
}
Esempio n. 2
0
File: c_aes.c Progetto: aikko/crypto
// Decrypt a single 128 bit block by a 128 bit key using AES
// http://en.wikipedia.org/wiki/Advanced_Encryption_Standard
void DecryptAES(byte *c, byte *key, byte *m) {
  int i; // To count the rounds
  
  // Key expansion
  byte keys[176];
  expand_key(key,keys);
  
  // Reverse the final Round
  memcpy(m,c,16);
  xor_round_key(m,keys,10);
  shift_rows_inv(m);
  sub_bytes_inv(m, 16);
  
  // Reverse the middle rounds
  for (i=0; i<9; i++) {
    xor_round_key(m,keys,9-i);
    mix_cols_inv(m);
    shift_rows_inv(m);
    sub_bytes_inv(m, 16);
  }
  
  // Reverse the first Round
  xor_round_key(m, keys, 0);
}