Microchip® Advanced Software Framework

sal.h File Reference

Declarations for low-level security API.

Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.

#include "sal_types.h"
#include "sal_generic.h"
#include "stdbool.h"
#include <stdint.h>

Macros

#define AES_BASE_ADDR   (0x80)
 Base address for Transceiver AES address space. More...
 
#define AES_DIR_DECRYPT   (1)
 AES core operation direction: Decryption (ECB) More...
 
#define AES_DIR_ENCRYPT   (0)
 AES core operation direction: Encryption (ECB, CBC) More...
 
#define AES_DONE   (1)
 AES core operation status: AES module finished. More...
 
#define AES_MODE_CBC   (2)
 Set CBC mode. More...
 
#define AES_MODE_ECB   (0)
 Set ECB mode. More...
 
#define AES_MODE_KEY   (1)
 Set key mode. More...
 
#define AES_NOT_DONE   (0)
 AES core operation status: AES module did not finish. More...
 
#define AES_REQUEST   (1)
 Initiate an AES operation. More...
 
#define RG_AES_CTRL   (0x03)
 Offset for register AES_CTRL. More...
 
#define RG_AES_STATE_KEY_0   (0x04)
 Offset for register AES_STATE_KEY_0. More...
 
#define RG_AES_STATUS   (0x02)
 Offset for register AES_STATUS. More...
 
#define sal_aes_clean_up()   _sal_aes_clean_up()
 Route function macro to the corresponding function. More...
 
#define SR_AES_DIR   0x03, 0x08, 3
 Access parameters for sub-register AES_DIR in register RG_AES_CTRL. More...
 
#define SR_AES_MODE   0x03, 0x70, 4
 Access parameters for sub-register AES_MODE in register RG_AES_CTRL. More...
 
#define SR_AES_REQUEST   0x03, 0x80, 7
 Access parameters for sub-register AES_REQUEST in register RG_AES_CTRL. More...
 

Functions

void _sal_aes_clean_up (void)
 Cleans up the SAL/AES after STB has been completed. More...
 
void sal_aes_exec (uint8_t *data)
 En/decrypt one AES block. 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...
 

#define AES_BASE_ADDR   (0x80)

Base address for Transceiver AES address space.

#define AES_DIR_DECRYPT   (1)

AES core operation direction: Decryption (ECB)

#define AES_DIR_ENCRYPT   (0)

AES core operation direction: Encryption (ECB, CBC)

#define AES_DONE   (1)

AES core operation status: AES module finished.

#define AES_MODE_CBC   (2)

Set CBC mode.

#define AES_MODE_ECB   (0)

Set ECB mode.

#define AES_MODE_KEY   (1)

Set key mode.

#define AES_NOT_DONE   (0)

AES core operation status: AES module did not finish.

#define AES_REQUEST   (1)

Initiate an AES operation.

#define RG_AES_CTRL   (0x03)

Offset for register AES_CTRL.

#define RG_AES_STATE_KEY_0   (0x04)

Offset for register AES_STATE_KEY_0.

#define RG_AES_STATUS   (0x02)

Offset for register AES_STATUS.

#define sal_aes_clean_up ( )    _sal_aes_clean_up()

Route function macro to the corresponding function.

Referenced by stb_ccm_secure().

#define SR_AES_DIR   0x03, 0x08, 3

Access parameters for sub-register AES_DIR in register RG_AES_CTRL.

#define SR_AES_MODE   0x03, 0x70, 4

Access parameters for sub-register AES_MODE in register RG_AES_CTRL.

#define SR_AES_REQUEST   0x03, 0x80, 7

Access parameters for sub-register AES_REQUEST in register RG_AES_CTRL.

void _sal_aes_clean_up ( void  )

Cleans up the SAL/AES after STB has been completed.

This function puts the radio to SLEEP if it has been in SLEEP before sal_aes_restart().

Cleans up the SAL/AES after STB has been completed.

void sal_aes_exec ( uint8_t *  data)

En/decrypt one AES block.

The function returns after the AES operation is finished.

Parameters
[in]dataAES block to be en/decrypted

Referenced by compute_mic(), encrypt_with_padding(), and PHY_EncryptReq().

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.

Parameters
[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 register AES_CON is restored, the next AES operation started with sal_aes_exec() will be executed correctly.

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!

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 mode.

Parameters
[in]keyAES key or NULL (NULL: use last key)
[in]enc_modeAES_MODE_ECB or AES_MODE_CBC
[in]dirmust be AES_DIR_ENCRYPT
Returns
False if some parameter was illegal, true else

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.

Parameters
[in]keyAES key or NULL (NULL: use last key)
[in]enc_modeAES_MODE_ECB or AES_MODE_CBC
[in]dirAES_DIR_ENCRYPT or AES_DIR_DECRYPT
Returns
False if some parameter was illegal, true else

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.

Parameters
[in]idataAES block to be en/decrypted
[out]odataResult 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().