Ejemplo n.º 1
0
Archivo: aes.c Proyecto: 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);
}
Ejemplo n.º 2
0
Archivo: aes.c Proyecto: noahp/aes_c
// Encrypt a single 128 bit block by a 128 bit key using AES
// http://en.wikipedia.org/wiki/Advanced_Encryption_Standard
void AES_Encrypt(unsigned char *data, unsigned char *key) {
  int i; // To count the rounds

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

  // First Round
  xor_round_key(data,keys,0);

  // Middle rounds
  for(i=0; i<9; i++) {
    sub_bytes(data,16);
    shift_rows(data);
    mix_cols(data);
    xor_round_key(data, keys, i+1);
  }

  // Final Round
  sub_bytes(data,16);
  shift_rows(data);
  xor_round_key(data, keys, 10);
}
Ejemplo n.º 3
0
Archivo: c_aes.c Proyecto: 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);
}
Ejemplo n.º 4
0
Archivo: c_aes.c Proyecto: aikko/crypto
// Encrypt a single 128 bit block by a 128 bit key using AES
// http://en.wikipedia.org/wiki/Advanced_Encryption_Standard
void EncryptAES(byte *msg, byte *key, byte *c) {
  int i; // To count the rounds
  
  // Key expansion
  byte keys[176];
  expand_key(key,keys);
  
  // First Round
  memcpy(c, msg, 16);
  xor_round_key(c,keys,0);

  // Middle rounds
  for(i=0; i<9; i++) {
    sub_bytes(c,16);
    shift_rows(c);
    mix_cols(c);
    xor_round_key(c, keys, i+1);
  }

  // Final Round
  sub_bytes(c,16);
  shift_rows(c);
  xor_round_key(c, keys, 10);
}