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_DIR_DECRYPT   (1)
 Defines AES direction as decryption. More...
 
#define AES_DIR_ENCRYPT   (0)
 Defines AES direction as encryption. More...
 
#define AES_MODE_CBC   (2)
 Defines AES mode as CBC. More...
 
#define AES_MODE_ECB   (0)
 Defines AES mode as ECB. More...
 
#define sal_aes_clean_up()   _sal_aes_clean_up()
 Route function macro to the corresponding function. 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_DIR_DECRYPT   (1)

Defines AES direction as decryption.

#define AES_DIR_ENCRYPT   (0)

Defines AES direction as encryption.

#define AES_MODE_CBC   (2)

Defines AES mode as CBC.

#define AES_MODE_ECB   (0)

Defines AES mode as ECB.

#define sal_aes_clean_up ( )    _sal_aes_clean_up()

Route function macro to the corresponding function.

Referenced by stb_ccm_secure().

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().

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

References AES_BLOCKSIZE, and keyp.

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

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

This function returns the result of the previous AES operation.

Parameters
[out]data- result of previous operation

References AES_BLOCKSIZE.

Referenced by compute_mic(), and encrypt_pldmic().

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.

Re-inits key and state after a sleep or TRX reset.

This function is void for ATxmega since the key must be re-initialized before every block encryption anyway.

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 performs 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_AUTO, AES_BLOCKSIZE, AES_DECRYPT, AES_DIR_DECRYPT, AES_DIR_ENCRYPT, AES_DIR_VOID, AES_KEYSIZE, AES_MODE_CBC, AES_MODE_ECB, COMP_SR, dec_initialized, dec_key, enc_key, keyp, last_dir, mode_byte, and sal_aes_exec().

Referenced by compute_mic(), encrypt_pldmic(), 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)

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

void sal_init ( void  )

Initialization of SAL.

This functions initializes the SAL.

References COMP_SR, SYSCLK_AES, sysclk_enable_module(), and SYSCLK_PORT_GEN.

Referenced by stb_init().