SmartSnippets DA1459x SDK
Files | Data Structures | Enumerations | Functions

AES Engine LLD API. More...

Files

file  hw_aes.h
 Definition of API for the AES Engine Low Level Driver.
 

Data Structures

struct  hw_aes_config_t
 AES engine configuration structure. More...
 

Enumerations

enum  HW_AES_ERROR
 AES engine error codes.
 
enum  HW_AES_MODE { HW_AES_MODE_ECB = 0, HW_AES_MODE_CTR = 2, HW_AES_MODE_CBC = 3 }
 AES Mode. More...
 
enum  HW_AES_OPERATION { HW_AES_OPERATION_DECRYPT = 0, HW_AES_OPERATION_ENCRYPT = 1 }
 AES operation. More...
 
enum  HW_AES_KEY_SIZE { HW_AES_KEY_SIZE_128 = 0, HW_AES_KEY_SIZE_192 = 1, HW_AES_KEY_SIZE_256 = 2 }
 AES key size. More...
 
enum  HW_AES_KEY_EXPAND { HW_AES_KEY_EXPAND_BY_SW = 0, HW_AES_KEY_EXPAND_BY_HW = 1 }
 AES key expansion modes. More...
 
enum  HW_AES_OUTPUT_DATA_MODE { HW_AES_OUTPUT_DATA_MODE_ALL = 0, HW_AES_OUTPUT_DATA_MODE_FINAL_BLOCK = 1 }
 AES Output Mode. More...
 

Functions

__STATIC_INLINE void hw_aes_set_mode (HW_AES_MODE aes_mode)
 Set AES Mode. More...
 
__STATIC_INLINE HW_AES_MODE hw_aes_get_mode (void)
 Get AES Mode. More...
 
__STATIC_INLINE void hw_aes_set_operation (HW_AES_OPERATION operation)
 Set AES operation, e.g. encryption or decryption. More...
 
__STATIC_INLINE void hw_aes_set_key_size (HW_AES_KEY_SIZE key_size)
 Set AES key size. More...
 
__STATIC_INLINE void hw_aes_set_key_expansion (HW_AES_KEY_EXPAND key_expand)
 Set AES key expansion mode. More...
 
__STATIC_INLINE void hw_aes_set_output_data_mode (HW_AES_OUTPUT_DATA_MODE output_data_mode)
 Set AES engine output data mode. More...
 
__STATIC_INLINE void hw_aes_start_operation (HW_AES_OPERATION aes_operation)
 Start AES operation (Encryption/Decryption). More...
 
bool hw_aes_check_input_data_len_restrictions (void)
 Check if the restrictions of the input data length are fulfilled. More...
 
void hw_aes_set_init_vector (const uint8_t *iv_cnt_ptr)
 Set the Initialization Vector in CBC Mode or the Counter in CTR Mode. More...
 
bool hw_aes_is_key_valid (uint8_t idx)
 Check whether the Encryption Key is revoked or not. More...
 
uint32_t hw_aes_key_address_get (uint8_t key_idx)
 Get User Data Encryption Key memory address. More...
 
void hw_aes_load_keys (uint32_t key_src_addr, HW_AES_KEY_SIZE key_size, HW_AES_KEY_EXPAND key_exp)
 Load the AES keys from OTP/RAM to Crypto Engine. More...
 
HW_AES_ERROR hw_aes_init (const hw_aes_config_t *aes_cfg)
 AES engine initialization function. More...
 

Detailed Description

AES Engine LLD API.

Enumeration Type Documentation

◆ HW_AES_KEY_EXPAND

AES key expansion modes.

Enumerator
HW_AES_KEY_EXPAND_BY_SW 

The key expansion is performed by the software

HW_AES_KEY_EXPAND_BY_HW 

The key expansion is performed by the hardware accelerator

◆ HW_AES_KEY_SIZE

AES key size.

Enumerator
HW_AES_KEY_SIZE_128 

AES Key 128-bit

HW_AES_KEY_SIZE_192 

AES Key 192-bit

HW_AES_KEY_SIZE_256 

AES Key 256-bit

◆ HW_AES_MODE

AES Mode.

Enumerator
HW_AES_MODE_ECB 

AES Mode ECB

HW_AES_MODE_CTR 

AES Mode CTR

HW_AES_MODE_CBC 

AES Mode CBC

◆ HW_AES_OPERATION

AES operation.

Enumerator
HW_AES_OPERATION_DECRYPT 

Perform AES Decryption

HW_AES_OPERATION_ENCRYPT 

Perform AES Encryption

◆ HW_AES_OUTPUT_DATA_MODE

AES Output Mode.

Enumerator
HW_AES_OUTPUT_DATA_MODE_ALL 

Write back to the memory all the output data

HW_AES_OUTPUT_DATA_MODE_FINAL_BLOCK 

Write back to the memory only the final block of the output data

Function Documentation

◆ hw_aes_check_input_data_len_restrictions()

bool hw_aes_check_input_data_len_restrictions ( void  )

Check if the restrictions of the input data length are fulfilled.

There are some restrictions in terms of the acceptable values of the data_len with regards to the AES mode and the Input Data Mode (wait_more_input). If the rules indicated by the next table are NOT fulfilled the function returns false, otherwise true.

mode wait_more_input = true wait_more_input = false
HW_AES_ECB multiple of 16 multiple of 16
HW_AES_CBC multiple of 16 no restrictions
HW_AES_CTR multiple of 16 no restrictions
Returns
True if the restrictions are fulfilled, otherwise false.

◆ hw_aes_get_mode()

__STATIC_INLINE HW_AES_MODE hw_aes_get_mode ( void  )

Get AES Mode.

Returns
AES mode.
See also
HW_AES_MODE

◆ hw_aes_init()

HW_AES_ERROR hw_aes_init ( const hw_aes_config_t aes_cfg)

AES engine initialization function.

Configure the AES engine provided that the crypto engine is NOT locked by the HASH engine. If the function returns HW_AES_ERROR_NONE, the operation can be started by calling the hw_aes_start_operation().

Parameters
[in]aes_cfgAES engine configuration structure
Returns
HW_AES_ERROR_NONE if the AES engine has been successfully initialized, otherwise an error code.
Warning
When AES operation has been completed, the hw_aes_hash_deinit() should be called in order for the crypto engine to be unlocked from AES. This is mandatory in case that both AES and HASH are used by the same application. The two blocks make use of the same hardware accelerator, thus they are mutually exclusive and cannot be used simultaneously. The functions hw_aes_init(), hw_hash_init() and hw_aes_hash_deinit() incorporate a mechanism which ensures mutual exclusion and prevents race condition, provided that the user doesn't call the functions hw_aes_hash_disable_clock(), hw_aes_hash_enable_clock(), hw_aes_set_mode() and hw_hash_set_type(). The aforementioned functions affect some AES/HASH register fields which are used by this mechanism and might violate it. Therefore, it is highly recommended to use the corresponding init/deinit functions instead.
See also
hw_aes_config_t
HW_AES_ERROR

◆ hw_aes_is_key_valid()

bool hw_aes_is_key_valid ( uint8_t  idx)

Check whether the Encryption Key is revoked or not.

Parameters
[in]idxeFlash memory cell_offset where the key is located
Precondition
Make sure that eFlash is available for reading
Warning
The acceptable idx range is from 0 to 15
Returns
true if key is valid, otherwise false

◆ hw_aes_key_address_get()

uint32_t hw_aes_key_address_get ( uint8_t  key_idx)

Get User Data Encryption Key memory address.

Returns address of User Data Encryption Key for given key index within the memory that the keys are stored

Parameters
[in]key_idxkey index
Warning
The acceptable range for the key_idx is 0 - 7.
Returns
key memory address or 0 if key has been revoked

◆ hw_aes_load_keys()

void hw_aes_load_keys ( uint32_t  key_src_addr,
HW_AES_KEY_SIZE  key_size,
HW_AES_KEY_EXPAND  key_exp 
)

Load the AES keys from OTP/RAM to Crypto Engine.

Parameters
[in]key_src_addrThe address of the AES Keys which can reside either in OTP or in RAM. In the former case use the hw_otpc_get_aes_key_address() to get their address.
[in]key_sizeThe AES Key size.
[in]key_expSelect whether the keys will be expanded by software or by hardware.
See also
HW_AES_KEY_SIZE
HW_AES_KEY_EXPAND

◆ hw_aes_set_init_vector()

void hw_aes_set_init_vector ( const uint8_t *  iv_cnt_ptr)

Set the Initialization Vector in CBC Mode or the Counter in CTR Mode.

Parameters
[in]iv_cnt_ptrPointer of the Initialization Vector in CBC Mode or the Initialization Counter in CTR Mode.
Note
Only applicable to AES CBC/CTR modes.

◆ hw_aes_set_key_expansion()

__STATIC_INLINE void hw_aes_set_key_expansion ( HW_AES_KEY_EXPAND  key_expand)

Set AES key expansion mode.

Parameters
[in]key_expandAES key expansion mode.
See also
HW_AES_KEY_EXPAND

◆ hw_aes_set_key_size()

__STATIC_INLINE void hw_aes_set_key_size ( HW_AES_KEY_SIZE  key_size)

Set AES key size.

Parameters
[in]key_sizeAES key size.
See also
HW_AES_KEY_SIZE

◆ hw_aes_set_mode()

__STATIC_INLINE void hw_aes_set_mode ( HW_AES_MODE  aes_mode)

Set AES Mode.

Parameters
[in]aes_modeAES Mode.
See also
HW_AES_MODE

◆ hw_aes_set_operation()

__STATIC_INLINE void hw_aes_set_operation ( HW_AES_OPERATION  operation)

Set AES operation, e.g. encryption or decryption.

Parameters
[in]operationAES operation.
See also
HW_AES_OPERATION

◆ hw_aes_set_output_data_mode()

__STATIC_INLINE void hw_aes_set_output_data_mode ( HW_AES_OUTPUT_DATA_MODE  output_data_mode)

Set AES engine output data mode.

Parameters
[in]output_data_modeAES output data mode.
See also
HW_AES_OUTPUT_DATA_MODE

◆ hw_aes_start_operation()

__STATIC_INLINE void hw_aes_start_operation ( HW_AES_OPERATION  aes_operation)

Start AES operation (Encryption/Decryption).

Parameters
[in]aes_operationAES operation (Encryption or Decryption).
See also
HW_AES_OPERATION