Microchip® Advanced Software Framework

sam0/applications/aes_software_library_demo/aes.h File Reference
#include "crypt.h"
#include <compiler.h>

Macros

#define AES_BLOCK_SIZE   16
 Support and FAQ: visit Microchip Support More...
 
#define AES_KEY_SCHEDULE_SIZE   ((AES_BLOCK_SIZE) * (AES_NUM_OF_ROUNDS + 1))
 
#define AES_NUM_OF_ROUNDS   10
 

Enumerations

enum  aes_ret_status_t {
  STATUS_OKAY = 0,
  ERR_NO_KEY
}
 

Functions

void AddRoundKey (uint8_t *state, uint8_t round)
 Performs Add RoundKey operation. More...
 
aes_ret_status_t aes_cipher (uint8_t *plainText, uint8_t *state)
 Performs AES-128 Encryption. More...
 
void aes_init (uint8_t *key)
 Performs Key Expansion. More...
 
aes_ret_status_t aes_inverse_cipher (uint8_t *cipherText, uint8_t *state)
 Performs AES-128 Decryption. More...
 
void Inv_AddRoundKey (uint8_t *state, uint8_t round)
 Performs AddRound Key. More...
 
void Inv_MixColumns (uint8_t *state, uint8_t round)
 Performs Inverse Mix Columns operation. More...
 
void Inv_ShiftRows_SubBytes (uint8_t *state)
 Performs Inverse of sub bytes and shift rows operation. More...
 
void KeyExpansion (uint8_t *round_key, uint8_t *key)
 Performs key expansion to generate key schedule from initial set of Key of 4 words. More...
 
void MixColumnns (uint8_t *state)
 Performs Mix Columns Operation. More...
 
void SubBytes_ShiftRows (uint8_t *state)
 Performs Sub Byte and Shift rows operation. More...
 
uint8_t xtime (uint8_t value)
 xtime calculation The value is multiplied by 0x02. This is implemented at the byte level as a left shift and XOR with 0x1b if the MSB of the value (before) shifting is 1. More...
 

#define AES_BLOCK_SIZE   16

Support and FAQ: visit Microchip Support

#define AES_KEY_SCHEDULE_SIZE   ((AES_BLOCK_SIZE) * (AES_NUM_OF_ROUNDS + 1))
#define AES_NUM_OF_ROUNDS   10

Referenced by KeyExpansion().

Enumerator
STATUS_OKAY 
ERR_NO_KEY 

void AddRoundKey ( uint8_t *  state,
uint8_t  round 
)

Performs Add RoundKey operation.

Parameters
statevariable to store the intermediate result of the algorithm

References key_schedule.

Referenced by aes_cipher().

aes_ret_status_t aes_cipher ( uint8_t *  plainText,
uint8_t *  state 
)

Performs AES-128 Encryption.

Parameters
plainTextInput plain text block
stateVariable to store the intermediate result
Return values
ERR_NO_KEYif key expansion is not done vis aes_init()
STATUS_OKAYif aes_init() is called before this function.
Parameters
plainTextInput plain text block
stateVariable to store the intermediate result
Return values
ERR_NO_KEYif key expansion is not done via aes_init()
STATUS_OKAYif aes_init() is called before this function.

References AddRoundKey(), AES_BLOCK_SIZE, aes_key_ready, ERR_NO_KEY, key_schedule, MixColumnns(), STATUS_OKAY, and SubBytes_ShiftRows().

Referenced by cbc_encrypt(), cfb_decrypt(), cfb_encrypt(), ctr_encrypt_decrypt(), ecb_encrypt(), ofb_decrypt(), and ofb_encrypt().

void aes_init ( uint8_t *  key)

Performs Key Expansion.

Parameters
keyInitial Key vectors received from user

References aes_key_ready, key_schedule, and KeyExpansion().

Referenced by main().

aes_ret_status_t aes_inverse_cipher ( uint8_t *  cipherText,
uint8_t *  state 
)

Performs AES-128 Decryption.

Parameters
cipherTextInput cipher text block
stateVariable to store the intermediate result
Return values
ERR_NO_KEYif key expansion is not done vis aes_init()
STATUS_OKAYif aes_init() is called before this function.

References AES_BLOCK_SIZE, aes_key_ready, ERR_NO_KEY, Inv_AddRoundKey(), Inv_MixColumns(), Inv_ShiftRows_SubBytes(), key_schedule, and STATUS_OKAY.

Referenced by cbc_decrypt(), and ecb_decrypt().

void Inv_AddRoundKey ( uint8_t *  state,
uint8_t  round 
)

Performs AddRound Key.

Parameters
statevariable to store the intermediate result of the algorithm
Note
inverse of Add round key and Add round key are same.Two separate functions are defined for ease of understanding the encryption and decryption process.

References key_schedule.

Referenced by aes_inverse_cipher().

void Inv_MixColumns ( uint8_t *  state,
uint8_t  round 
)

Performs Inverse Mix Columns operation.

Parameters
statevariable to store the intermediate result of the algorithm
Numberof current ongoing round in AES algorithm

References xtime().

Referenced by aes_inverse_cipher().

void Inv_ShiftRows_SubBytes ( uint8_t *  state)

Performs Inverse of sub bytes and shift rows operation.

Parameters
statevariable to store the intermediate result of the algorithm

Performs Inverse of sub bytes and shift rows operation.

Parameters
statevariable to store the intermediate result of the algorithm

References inv_sbox.

Referenced by aes_inverse_cipher().

void KeyExpansion ( uint8_t *  round_key,
uint8_t *  key 
)

Performs key expansion to generate key schedule from initial set of Key of 4 words.

Parameters
round_keyHolds the pointer to store key schedule
keyInitial Key received from the user

References AES_NUM_OF_ROUNDS, i, RCon, and sbox.

Referenced by aes_init().

void MixColumnns ( uint8_t *  state)

Performs Mix Columns Operation.

Parameters
statevariable to store the intermediate result of the algorithm

References xtime().

Referenced by aes_cipher().

void SubBytes_ShiftRows ( uint8_t *  state)

Performs Sub Byte and Shift rows operation.

Parameters
statevariable to store the intermediate result of the algorithm

Performs Sub Byte and Shift rows operation.

Parameters
statevariable to store the intermediate result of the algorithm

References sbox.

Referenced by aes_cipher().

uint8_t xtime ( uint8_t  value)

xtime calculation The value is multiplied by 0x02. This is implemented at the byte level as a left shift and XOR with 0x1b if the MSB of the value (before) shifting is 1.

Parameters
valueValue for which multiplication to be done

Referenced by Inv_MixColumns(), and MixColumnns().