Low-level crypto API for an AES unit implemented in AT86RF2xx.
Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
#include "trx_access.h"
#include "sal_types.h"
#include <string.h>
#include "sal.h"
#include "delay.h"
Macros | |
#define | _SR_MASK(addr, mask, pos, val) (((uint8_t)val << pos) & mask) |
#define | AES_DIR_VOID (AES_DIR_ENCRYPT + AES_DIR_DECRYPT + 1) |
#define | AES_RY_BIT (1) /* AES_RY: poll on finished op */ |
#define | SR_MASK(SR, val) _SR_MASK(SR, val) |
Functions | |
void | _sal_aes_clean_up (void) |
Cleans up the SAL/AES after STB has been finished. More... | |
void | sal_aes_read (uint8_t *data) |
Reads the result of previous AES en/decryption. More... | |
void | sal_aes_restart (void) |
Re-inits key and state after a sleep or TRX reset. More... | |
bool | sal_aes_setup (uint8_t *key, uint8_t enc_mode, uint8_t dir) |
Setup AES unit. More... | |
void | sal_aes_wrrd (uint8_t *idata, uint8_t *odata) |
Writes data, reads previous result and does the AES en/decryption. More... | |
void | sal_init (void) |
Initialization of SAL. More... | |
Variables | |
static uint8_t | aes_buf [AES_BLOCKSIZE+2] |
static bool | dec_initialized = false |
static uint8_t | dec_key [AES_KEYSIZE] |
static uint8_t | enc_key [AES_KEYSIZE] |
static uint8_t | last_dir = AES_DIR_VOID |
static bool | setup_flag |
#define _SR_MASK | ( | addr, | |
mask, | |||
pos, | |||
val | |||
) | (((uint8_t)val << pos) & mask) |
#define AES_DIR_VOID (AES_DIR_ENCRYPT + AES_DIR_DECRYPT + 1) |
Referenced by sal_aes_setup().
#define AES_RY_BIT (1) /* AES_RY: poll on finished op */ |
#define SR_MASK | ( | SR, | |
val | |||
) | _SR_MASK(SR, val) |
Referenced by sal_aes_restart(), and sal_aes_setup().
void _sal_aes_clean_up | ( | void | ) |
Cleans up the SAL/AES after STB has been finished.
Cleans up the SAL/AES after STB has been completed.
void sal_aes_read | ( | uint8_t * | data | ) |
Reads the result of previous AES en/decryption.
This function returns the result of the previous AES operation, so this function is needed in order to get the last result of a series of sal_aes_wrrd() calls.
[out] | data | - result of previous operation |
References AES_BASE_ADDR, AES_BLOCKSIZE, RG_AES_STATE_KEY_0, and trx_sram_read().
Referenced by compute_mic(), encrypt_pldmic(), and PHY_EncryptReq().
void sal_aes_restart | ( | void | ) |
Re-inits key and state after a sleep or TRX reset.
This function re-initializes the AES key and the state of the AES engine after TRX sleep or reset. The contents of AES registers AES_CON and AES_CON_MIRROR are restored, the next AES operation started with sal_aes_wrrd() will be executed correctly. However, the contents of SRAM buffers is destroyed, in general. When using sal_aes_wrrd(), call sal_aes_read() to get the result of the last AES operation BEFORE you put the transceiver unit to sleep state!
References AES_BASE_ADDR, AES_BLOCKSIZE, aes_buf, AES_DIR_ENCRYPT, AES_KEYSIZE, AES_MODE_KEY, dec_key, enc_key, last_dir, RG_AES_CTRL, setup_flag, SR_AES_MODE, SR_MASK, and trx_sram_write().
Referenced by stb_ccm_secure().
bool sal_aes_setup | ( | uint8_t * | key, |
uint8_t | enc_mode, | ||
uint8_t | dir | ||
) |
Setup AES unit.
This function perform the following tasks as part of the setup of the AES unit: key initialization, set encryption direction and encryption mode.
In general, the contents of SRAM buffer is destroyed. When using sal_aes_wrrd(), sal_aes_read() needs to be called in order to get the result of the last AES operation before you may call sal_aes_setup() again.
[in] | key | AES key or NULL (NULL: use last key) |
[in] | enc_mode | AES_MODE_ECB or AES_MODE_CBC |
[in] | dir | AES_DIR_ENCRYPT or AES_DIR_DECRYPT |
References AES_BASE_ADDR, AES_BLOCKSIZE, aes_buf, AES_DIR_DECRYPT, AES_DIR_ENCRYPT, AES_DIR_VOID, AES_KEYSIZE, AES_MODE_CBC, AES_MODE_ECB, AES_MODE_KEY, AES_REQUEST, dec_initialized, dec_key, enc_key, last_dir, NULL, RG_AES_CTRL, RG_AES_STATE_KEY_0, sal_aes_wrrd(), setup_flag, SR_AES_DIR, SR_AES_MODE, SR_AES_REQUEST, SR_MASK, trx_sram_read(), and trx_sram_write().
Referenced by compute_mic(), encrypt_pldmic(), PHY_EncryptReq(), and stb_ccm_secure().
void sal_aes_wrrd | ( | uint8_t * | idata, |
uint8_t * | odata | ||
) |
Writes data, reads previous result and does the AES en/decryption.
The function returns after the AES operation is finished.
When sal_aes_wrrd() is called several times in sequence, from the second call onwards, odata contains the result of the previous operation. To obtain the last result, you must call sal_aes_read() at the end. Please note that any call of sal_aes_setup() as well as putting the transceiver to sleep state destroys the SRAM contents, i.e. the next call of sal_aes_wrrd() yields no meaningful result.
[in] | idata | AES block to be en/decrypted |
[out] | odata | Result of previous operation (odata may be NULL or equal to idata) |
References AES_BASE_ADDR, AES_BLOCKSIZE, aes_buf, delay_us, NULL, RG_AES_CTRL, RG_AES_STATE_KEY_0, setup_flag, and trx_aes_wrrd().
Referenced by compute_mic(), encrypt_pldmic(), encrypt_with_padding(), PHY_EncryptReq(), and sal_aes_setup().
void sal_init | ( | void | ) |
Initialization of SAL.
This functions initializes the SAL.
Referenced by stb_init(), and SYS_Init().
|
static |
Referenced by sal_aes_restart(), sal_aes_setup(), and sal_aes_wrrd().
Referenced by sal_aes_setup().
|
static |
Referenced by sal_aes_restart(), and sal_aes_setup().
|
static |
Referenced by sal_aes_restart(), and sal_aes_setup().
|
static |
Referenced by sal_aes_restart(), and sal_aes_setup().
|
static |
Referenced by sal_aes_restart(), sal_aes_setup(), and sal_aes_wrrd().