<<

AES user guide

AES (Rijndael) encryption and decryption is performed using the functions below. Typically, a key is first expanded using the appropriate function (depending on whether one decrypts or encrypts) and then the stream is encoded/decoded using AESEncryptBlock() or AESDecryptBlock(). A convenience function calls both of these for streams that comprise just a single block. The AES interface assumes that all data is word-aligned. Character streams have to be aligned to fit on word boundaries.

Encryption of a single block is performed by calling the funciton AESEncrypt(). If multiple blocks are to be encrypted with an identical key, the funciton AESEncryptKey() should be called once followed by multiple calls to AESEncryptBlock()

Decryption of a single block is performed by calling the funciton AESDecrypt(). If multiple blocks are to be decrypted with an identical key, the funciton AESDecryptKey() should be called once followed by multiple calls to AESDecryptBlock()

API

void AESEncryptBlock(unsigned int plainText[], unsigned int expanded[], unsigned int cipherText[])

This function encrypts a block of plaintext into a block of ciphertext, given an expanded key.

Use AESEncryptExpandKey() to expand a 128-bit key. All are supplied as arrays of integers.

Parameters:
  • plainText – array of integers holding the input message
  • expanded – array of integers holding the expanded key
  • cipherText – array of integers where the encrypted message is stored
void AESEncryptExpandKey(unsigned int key[], unsigned int expanded[])

This function expands a 128-bit key into a format suitable for efficient encryption The output array needs to be at least 44 (that is Nb*(Nr+1)) words long.

Parameters:
  • key – array of integers holding the key
  • expanded – array of integers where the expanded key is stored
void AESEncrypt(unsigned int plainText[], unsigned int key[], unsigned int cipherText[])

This function encrypts a block of plaintext into a block of ciphertext, given a key.

All are supplied as arrays of integers. Calling this function is equivalent to first calling AESEncryptExpandKey() and then AESEncryptBlock().

Parameters:
  • plainText – array of integers holding the input message
  • key – array of integers holding the key
  • cipherText – array of integers where the encrypted message is stored
void AESDecryptBlock(unsigned int cipherText[], unsigned int expanded[], unsigned int decipheredText[])

This function encrypts a block of plaintext into a block of ciphertext, given an expanded key.

Use AESEncryptExpandKey() to expand a 128-bit key. All are supplied as arrays of integers.

Parameters:
  • cipherText – array of integers holding the encrypted input message
  • expanded – array of integers holding the expanded key
  • decipheredText – array of integers where the decrypted message is stored
void AESDecryptExpandKey(unsigned int key[], unsigned int expanded[])

This function expands a 128-bit key into a format suitable for efficient decryption The output array needs to be at least 44 (that is Nb*(Nr+1)) words long.

Parameters:
  • key – array of integers holding the key
  • expanded – array of integers where the expanded key is stored
void AESDecrypt(unsigned int cipherText[], unsigned int key[], unsigned int decipheredText[])

This function encrypts a block of plaintext into a block of ciphertext, given a key.

All are supplied as arrays of integers. Calling this function is equivalent to first calling AESDecryptExpandKey() and then AESDecryptBlock().

Parameters:
  • cipherText – array of integers holding the encrypted input message
  • key – array of integers holding the key
  • decipheredText – array of integers where the decrypted message is stored

Example

An example program is shown below:

unsigned int plain[4] = {1,2,3,4};
unsigned int key[4] = {12314241,4367465,1231244,1234569};
unsigned int cipher[4];
main() {
  AESEncrypt(input, key, cipher);
  AESDecrypt(cipher, key, output);
  return 0;
}