InPlay API
Advanced Encryption Standard Cryptography Profile

HAL AES. More...

Data Structures

struct  aes_cfg_t
 AES cryptography configuration structure. More...
 

Enumerations

enum  aes_crypto_status {
  AES_ERR_OK = 0, AES_ERR_NOT_INIT = 1, AES_ERR_ALREADY_INIT = 2, AES_ERR_DEV_BAD_STATE = 3,
  AES_ERR_MAC_DOES_NOT_MATCH = 4, AES_ERR_HW_MEM_USED_BY_ECC = 5
}
 AES function status return. More...
 
enum  aes_crypto_type { AES_CRYPTO_TYPE_ENCRYPT = 1, AES_CRYPTO_TYPE_DECRYPT = 0 }
 AES cryptography type. More...
 
enum  aes_crypto_mode {
  AES_CRYPTO_MODE_ECB = 0, AES_CRYPTO_MODE_CBC = 1, AES_CRYPTO_MODE_CTR = 2, AES_CRYPTO_MODE_CCM = 3,
  AES_CRYPTO_MODE_CMAC = 4, AES_CRYPTO_MODE_XCBC = 6, AES_CRYPTO_MODE_F8 = 9
}
 AES cryptography mode. More...
 
enum  aes_key_size { AES_KEY_SIZE_128 = 0, AES_KEY_SIZE_192 = 1, AES_KEY_SIZE_256 = 2 }
 AES key size. More...
 

Functions

int hal_aes_open (void)
 Initialize AES driver for power management and interrupt purposes. More...
 
int hal_aes_close (void)
 De-Initialize AES driver for power management and interrupt purposes. More...
 
int hal_aes_is_open (void)
 Ecc and Aes shared the same HW memory. This is to inform Ecc that Aes currently is using the HW memory. More...
 
int hal_aes_config (aes_cfg_t *cfg)
 AES cryptography configuration function, call this function before calling hal_aes_encrypt/hal_aes_decrypt. More...
 
void hal_aes_set_aad_length (uint32_t length)
 Set the AAD data length, CCM mode only. Must be multiple of 16 bytes. More...
 
int hal_aes_encrypt (const uint8_t *input, uint32_t length, uint8_t *output, bool end)
 Do the encrypt process. More...
 
void hal_aes_get_encrypt_mac (uint8_t *mac, uint32_t buf_sz)
 Get the MAC result after encryption, only for CMAC, CCM and XCBC modes. More...
 
void hal_aes_get_iv (uint8_t iv[16])
 Get the IV result after encryption, only for CBC and F8 modes. More...
 
int hal_aes_decrypt (const uint8_t *input, uint32_t length, uint8_t *output, bool end)
 Do the decrypt process. More...
 

Detailed Description

HAL AES.

Enumeration Type Documentation

◆ aes_crypto_mode

AES cryptography mode.

Enumerator
AES_CRYPTO_MODE_ECB 

AES ECB mode (Electronic Codebook mode), as defined in NIST Special Publication 800-38A.

AES_CRYPTO_MODE_CBC 

AES CBC mode (Cipher Block Chaining mode), as defined in NIST Special Publication 800-38A.

AES_CRYPTO_MODE_CTR 

AES CTR mode (Counter mode), as defined in NIST Special Publication 800-38A.

AES_CRYPTO_MODE_CCM 

AES CCM mode (Counter with CBC-MAC mode), as defined in NIST Special Publication 800-38C.

AES_CRYPTO_MODE_CMAC 

AES CMAC mode (Cipher-based Message Authentication Code mode), as defined in NIST Special Publication 800-38B.

AES_CRYPTO_MODE_XCBC 

AES XCBC mode (3-key variant, as specified in Rogaway and BlackĄ¯s NIST submission)

AES_CRYPTO_MODE_F8 

AES F8 mode, as defined in RFC 3711.

◆ aes_crypto_status

AES function status return.

Enumerator
AES_ERR_OK 

No errors, good status.

AES_ERR_NOT_INIT 

Error, AES driver not initialized.

AES_ERR_ALREADY_INIT 

Error, AES driver already initialized.

AES_ERR_DEV_BAD_STATE 

Error, AES bad state.

AES_ERR_MAC_DOES_NOT_MATCH 

Error, MAC verification failure.

AES_ERR_HW_MEM_USED_BY_ECC 

Error, ECC using the HW memory, ECC and AES share the same HW memory.

◆ aes_crypto_type

AES cryptography type.

Enumerator
AES_CRYPTO_TYPE_ENCRYPT 

AES encryption.

AES_CRYPTO_TYPE_DECRYPT 

AES decryption.

◆ aes_key_size

AES key size.

Enumerator
AES_KEY_SIZE_128 

AES 128-bit key size.

AES_KEY_SIZE_192 

AES 192-bit key size.

AES_KEY_SIZE_256 

AES 256-bit key size.

Function Documentation

◆ hal_aes_close()

int hal_aes_close ( void  )

De-Initialize AES driver for power management and interrupt purposes.

Returns
AES_ERR_OK if aes uninitializes successfully, error otherwise.
See also
enum aes_crypto_status.

◆ hal_aes_config()

int hal_aes_config ( aes_cfg_t cfg)

AES cryptography configuration function, call this function before calling hal_aes_encrypt/hal_aes_decrypt.

Parameters
[in]cfg
See also
struct aes_cfg_t for detailed description
Returns
AES_ERR_OK if aes configured successfully, error otherwise.
See also
enum aes_crypto_status.

◆ hal_aes_decrypt()

int hal_aes_decrypt ( const uint8_t *  input,
uint32_t  length,
uint8_t *  output,
bool  end 
)

Do the decrypt process.

Parameters
[in]InputThe ciphertext to be decrypted. For CCM mode, AAD data is included and before ciphertext
[in]LengthNumber of bytes in message, should be <= 128bytes (CCM mode requires the total number of bytes in formatted input data, see "r" in NIST Special Publication 800-38C)
[out]OutputThe plaintext decrypted, for CCM mode, AAD is not included, only plaintext
[in]endSet to "true" if this is the last data segment to be decrypted. This function can be called many times to decrypt multi data segments after AES is configured if the data length exceeds 128 bytes.
Returns
AES_ERR_OK if decryption completes and MAC is verified, error otherwise.
See also
enum aes_crypto_status.

◆ hal_aes_encrypt()

int hal_aes_encrypt ( const uint8_t *  input,
uint32_t  length,
uint8_t *  output,
bool  end 
)

Do the encrypt process.

Parameters
[in]InputPointer to the plain text to be encrypted, For CCM mode, AAD data is included(see "B" in NIST Special Publication 800-38C).
[in]LengthNumber of bytes in message, should <= 128bytes. (CCM mode requires the total number of bytes in formatted input data, see "r" in NIST Special Publication 800-38C)
[out]OutputPointer to the output ciphertext
[in]endSet to "true" if this is the last data segment to be encrypted. This function can be called many times to encrypt multi data segments if the data length exceeds 128 bytes.
Returns
AES_ERR_OK if encryption is completed successfully, error otherwise.
See also
enum aes_crypto_status.

◆ hal_aes_get_encrypt_mac()

void hal_aes_get_encrypt_mac ( uint8_t *  mac,
uint32_t  buf_sz 
)

Get the MAC result after encryption, only for CMAC, CCM and XCBC modes.

Parameters
[out]macPointer to the buffer to save message authentication code
[in]buf_szBuffer size of the message authentication code

◆ hal_aes_get_iv()

void hal_aes_get_iv ( uint8_t  iv[16])

Get the IV result after encryption, only for CBC and F8 modes.

Parameters
[out]iv[16]Pointer to the buffer to save Initialization Value

◆ hal_aes_is_open()

int hal_aes_is_open ( void  )

Ecc and Aes shared the same HW memory. This is to inform Ecc that Aes currently is using the HW memory.

Returns
1 if Aes is using the HW memory, 0 otherwise.

◆ hal_aes_open()

int hal_aes_open ( void  )

Initialize AES driver for power management and interrupt purposes.

Returns
AES_ERR_OK if aes initializes successfully, error otherwise.
See also
enum aes_crypto_status.

◆ hal_aes_set_aad_length()

void hal_aes_set_aad_length ( uint32_t  length)

Set the AAD data length, CCM mode only. Must be multiple of 16 bytes.

Parameters
length[in]: Number of bytes in formatted input data minus bytes in formatted payload ("r" - "m" in NIST Special Publication 800-38C)
Note
For CCM mode, this function must be called before hal_aes_encrypt/hal_aes_decrypt