Exemple #1
0
// 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);
}
Exemple #2
0
// 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);
}