The Advanced Encryption Standard (AES) driver provides an interface for encryption or decryption.
The driver will block (i.e. not return) until the requested data has been read. Functionality is therefore synchronous to the calling thread, i.e. the thread waits for the result to be ready.
Refer Cryptography (AES) Driver for more detailed calendar basics.
Initialize and deinitialize the driver and associated hardware
Enable or disable the driver
Configure 128/192/256 bit cryptographic keys
ECB: Electronic Code Book
CBC: Cipher Block Chaining
CFB: Cipher Feedback in 8,16,32,64,128 bits size
OFB: Output Feedback
CTR: Counter
CCM: Counter with CBC-MAC mode for authenticated encryption
GCM: Galois Counter mode encryption and authentication
The user selects which clock source the AES uses in START. No more parameters are configured when initializing the driver and underlying hardware.
The functions in the AES synchronous driver will block (i.e. not return) until operation is done.
The GCM supports data processes with known lengths only. This mean the aes_sync_gcm_update cannot be invoked multiple times. The application should assembly all data into a data buffer and then call the aes_sync_gcm_update to encrypt/decrypt data.
The following shows a simple example of using the AES. The AES must have been initialized by aes_sync_init.
The example enables AES driver and sets ac encrypt key, and then invokes the function for Electronic Code Book (ECB) mode. Finally, we can get the ciphered data. If the ciphered data isn't similar to the plain data, the project will go into an infinite loop.
static uint8_t aes_plain_text[16]
= {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};
static uint8_t aes_key[16]
= {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
static uint8_t aes_cipher_text[16]
= {0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60, 0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97};
uint8_t aes_output[16] = {0x00};
/**
* Example of using CRYPTOGRAPHY_0 to Encrypt/Decrypt datas.
*/
void CRYPTOGRAPHY_0_example(void)
{
int32_t i;
aes_sync_enable(&CRYPTOGRAPHY_0);
aes_sync_set_encrypt_key(&CRYPTOGRAPHY_0, aes_key, AES_KEY_128);
aes_sync_ecb_crypt(&CRYPTOGRAPHY_0, AES_ENCRYPT, aes_plain_text, aes_output);
for (i = 0; i < 16; i++) {
while (aes_output[i] != aes_cipher_text[i])
;
}
}
AES peripheral and its related clocks