EFM32 Leopard Gecko Software Documentation  efm32lg-doc-4.2.1

Advanced Encryption Standard Accelerator (AES) Peripheral API. More...

Typedefs

typedef void(* AES_CtrFuncPtr_TypeDef) (uint8_t *ctr)
 AES counter modification function pointer. More...
 

Functions

void AES_CBC128 (uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt)
 Cipher-block chaining (CBC) cipher mode encryption/decryption, 128 bit key. More...
 
void AES_CBC256 (uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt)
 Cipher-block chaining (CBC) cipher mode encryption/decryption, 256 bit key. More...
 
void AES_CFB128 (uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt)
 Cipher feedback (CFB) cipher mode encryption/decryption, 128 bit key. More...
 
void AES_CFB256 (uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt)
 Cipher feedback (CFB) cipher mode encryption/decryption, 256 bit key. More...
 
void AES_CTR128 (uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, uint8_t *ctr, AES_CtrFuncPtr_TypeDef ctrFunc)
 Counter (CTR) cipher mode encryption/decryption, 128 bit key. More...
 
void AES_CTR256 (uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, uint8_t *ctr, AES_CtrFuncPtr_TypeDef ctrFunc)
 Counter (CTR) cipher mode encryption/decryption, 256 bit key. More...
 
void AES_CTRUpdate32Bit (uint8_t *ctr)
 Update last 32 bits of 128 bit counter, by incrementing with 1. More...
 
void AES_DecryptKey128 (uint8_t *out, const uint8_t *in)
 Generate 128 bit decryption key from 128 bit encryption key. The decryption key is used for some cipher modes when decrypting. More...
 
void AES_DecryptKey256 (uint8_t *out, const uint8_t *in)
 Generate 256 bit decryption key from 256 bit encryption key. The decryption key is used for some cipher modes when decrypting. More...
 
void AES_ECB128 (uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, bool encrypt)
 Electronic Codebook (ECB) cipher mode encryption/decryption, 128 bit key. More...
 
void AES_ECB256 (uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, bool encrypt)
 Electronic Codebook (ECB) cipher mode encryption/decryption, 256 bit key. More...
 
__STATIC_INLINE void AES_IntClear (uint32_t flags)
 Clear one or more pending AES interrupts. More...
 
__STATIC_INLINE void AES_IntDisable (uint32_t flags)
 Disable one or more AES interrupts. More...
 
__STATIC_INLINE void AES_IntEnable (uint32_t flags)
 Enable one or more AES interrupts. More...
 
__STATIC_INLINE uint32_t AES_IntGet (void)
 Get pending AES interrupt flags. More...
 
__STATIC_INLINE uint32_t AES_IntGetEnabled (void)
 Get enabled and pending AES interrupt flags. Useful for handling more interrupt sources in the same interrupt handler. More...
 
__STATIC_INLINE void AES_IntSet (uint32_t flags)
 Set one or more pending AES interrupts from SW. More...
 
void AES_OFB128 (uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv)
 Output feedback (OFB) cipher mode encryption/decryption, 128 bit key. More...
 
void AES_OFB256 (uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv)
 Output feedback (OFB) cipher mode encryption/decryption, 256 bit key. More...
 

Detailed Description

This API is intended for use on Silicon Labs target devices, and the following input/output notations should be noted:

It is up to the user to use a cipher mode according to its requirements in order to not break security. Please refer to specific cipher mode theory for details.

References:

Typedef Documentation

typedef void(* AES_CtrFuncPtr_TypeDef) (uint8_t *ctr)

Parameters:

  • ctr - Ptr to byte array (16 bytes) holding counter to be modified.

Definition at line 66 of file em_aes.h.

Function Documentation

void AES_CBC128 ( uint8_t *  out,
const uint8_t *  in,
unsigned int  len,
const uint8_t *  key,
const uint8_t *  iv,
bool  encrypt 
)

Encryption:

*           Plaintext                  Plaintext
*               |                          |
*               V                          V
* InitVector ->XOR        +-------------->XOR
*               |         |                |
*               V         |                V
*       +--------------+  |        +--------------+
* Key ->| Block cipher |  |  Key ->| Block cipher |
*       |  encryption  |  |        |  encryption  |
*       +--------------+  |        +--------------+
*               |---------+                |
*               V                          V
*           Ciphertext                 Ciphertext
* 

Decryption:

*         Ciphertext                 Ciphertext
*              |----------+                |
*              V          |                V
*       +--------------+  |        +--------------+
* Key ->| Block cipher |  |  Key ->| Block cipher |
*       |  decryption  |  |        |  decryption  |
*       +--------------+  |        +--------------+
*               |         |                |
*               V         |                V
* InitVector ->XOR        +-------------->XOR
*               |                          |
*               V                          V
*           Plaintext                  Plaintext
* 

Please refer to general comments on layout and byte ordering of parameters.

Parameters
[out]outBuffer to place encrypted/decrypted data. Must be at least len long. It may be set equal to in, in which case the input buffer is overwritten.
[in]inBuffer holding data to encrypt/decrypt. Must be at least len long.
[in]lenNumber of bytes to encrypt/decrypt. Must be a multiple of 16.
[in]keyWhen doing encryption, this is the 128 bit encryption key. When doing decryption, this is the 128 bit decryption key. The decryption key may be generated from the encryption key with AES_DecryptKey128(). On devices supporting key buffering this argument can be null, if so, the key will not be loaded, as it is assumed the key has been loaded into KEYHA previously.
[in]iv128 bit initalization vector to use.
[in]encryptSet to true to encrypt, false to decrypt.

Definition at line 157 of file em_aes.c.

References AES, AES_CTRL_DATASTART, AES_CTRL_DECRYPT, AES_CTRL_KEYBUFEN, AES_CTRL_XORSTART, and AES_STATUS_RUNNING.

void AES_CBC256 ( uint8_t *  out,
const uint8_t *  in,
unsigned int  len,
const uint8_t *  key,
const uint8_t *  iv,
bool  encrypt 
)

Please see AES_CBC128() for CBC figure.

Please refer to general comments on layout and byte ordering of parameters.

Parameters
[out]outBuffer to place encrypted/decrypted data. Must be at least len long. It may be set equal to in, in which case the input buffer is overwritten.
[in]inBuffer holding data to encrypt/decrypt. Must be at least len long.
[in]lenNumber of bytes to encrypt/decrypt. Must be a multiple of 16.
[in]keyWhen doing encryption, this is the 256 bit encryption key. When doing decryption, this is the 256 bit decryption key. The decryption key may be generated from the encryption key with AES_DecryptKey256().
[in]iv128 bit initalization vector to use.
[in]encryptSet to true to encrypt, false to decrypt.

Definition at line 322 of file em_aes.c.

References AES, AES_CTRL_AES256, AES_CTRL_DATASTART, AES_CTRL_DECRYPT, AES_CTRL_XORSTART, and AES_STATUS_RUNNING.

void AES_CFB128 ( uint8_t *  out,
const uint8_t *  in,
unsigned int  len,
const uint8_t *  key,
const uint8_t *  iv,
bool  encrypt 
)

Encryption:

*           InitVector    +----------------+
*               |         |                |
*               V         |                V
*       +--------------+  |        +--------------+
* Key ->| Block cipher |  |  Key ->| Block cipher |
*       |  encryption  |  |        |  encryption  |
*       +--------------+  |        +--------------+
*               |         |                |
*               V         |                V
*  Plaintext ->XOR        |   Plaintext ->XOR
*               |---------+                |
*               V                          V
*           Ciphertext                 Ciphertext
* 

Decryption:

*          InitVector     +----------------+
*               |         |                |
*               V         |                V
*       +--------------+  |        +--------------+
* Key ->| Block cipher |  |  Key ->| Block cipher |
*       |  encryption  |  |        |  encryption  |
*       +--------------+  |        +--------------+
*               |         |                |
*               V         |                V
*              XOR<- Ciphertext           XOR<- Ciphertext
*               |                          |
*               V                          V
*           Plaintext                  Plaintext
* 

Please refer to general comments on layout and byte ordering of parameters.

Parameters
[out]outBuffer to place encrypted/decrypted data. Must be at least len long. It may be set equal to in, in which case the input buffer is overwritten.
[in]inBuffer holding data to encrypt/decrypt. Must be at least len long.
[in]lenNumber of bytes to encrypt/decrypt. Must be a multiple of 16.
[in]key128 bit encryption key is used for both encryption and decryption modes.
[in]iv128 bit initalization vector to use.
[in]encryptSet to true to encrypt, false to decrypt.

Definition at line 486 of file em_aes.c.

References AES, AES_CTRL_DATASTART, AES_CTRL_KEYBUFEN, and AES_STATUS_RUNNING.

void AES_CFB256 ( uint8_t *  out,
const uint8_t *  in,
unsigned int  len,
const uint8_t *  key,
const uint8_t *  iv,
bool  encrypt 
)

Please see AES_CFB128() for CFB figure.

Please refer to general comments on layout and byte ordering of parameters.

Parameters
[out]outBuffer to place encrypted/decrypted data. Must be at least len long. It may be set equal to in, in which case the input buffer is overwritten.
[in]inBuffer holding data to encrypt/decrypt. Must be at least len long.
[in]lenNumber of bytes to encrypt/decrypt. Must be a multiple of 16.
[in]key256 bit encryption key is used for both encryption and decryption modes.
[in]iv128 bit initalization vector to use.
[in]encryptSet to true to encrypt, false to decrypt.

Definition at line 595 of file em_aes.c.

References AES, AES_CTRL_AES256, AES_CTRL_DATASTART, and AES_STATUS_RUNNING.

void AES_CTR128 ( uint8_t *  out,
const uint8_t *  in,
unsigned int  len,
const uint8_t *  key,
uint8_t *  ctr,
AES_CtrFuncPtr_TypeDef  ctrFunc 
)

Encryption:

*           Counter                    Counter
*              |                          |
*              V                          V
*       +--------------+           +--------------+
* Key ->| Block cipher |     Key ->| Block cipher |
*       |  encryption  |           |  encryption  |
*       +--------------+           +--------------+
*              |                          |
* Plaintext ->XOR            Plaintext ->XOR
*              |                          |
*              V                          V
*         Ciphertext                 Ciphertext
* 

Decryption:

*           Counter                    Counter
*              |                          |
*              V                          V
*       +--------------+           +--------------+
* Key ->| Block cipher |     Key ->| Block cipher |
*       |  encryption  |           |  encryption  |
*       +--------------+           +--------------+
*               |                          |
* Ciphertext ->XOR           Ciphertext ->XOR
*               |                          |
*               V                          V
*           Plaintext                  Plaintext
* 

Please refer to general comments on layout and byte ordering of parameters.

Parameters
[out]outBuffer to place encrypted/decrypted data. Must be at least len long. It may be set equal to in, in which case the input buffer is overwritten.
[in]inBuffer holding data to encrypt/decrypt. Must be at least len long.
[in]lenNumber of bytes to encrypt/decrypt. Must be a multiple of 16.
[in]key128 bit encryption key. On devices supporting key buffering this argument can be null, if so, the key will not be loaded, as it is assumed the key has been loaded into KEYHA previously.
[in,out]ctr128 bit initial counter value. The counter is updated after each AES block encoding through use of ctrFunc.
[in]ctrFuncFunction used to update counter value.

Definition at line 720 of file em_aes.c.

References AES, AES_CTRL_DATASTART, AES_CTRL_KEYBUFEN, and AES_STATUS_RUNNING.

void AES_CTR256 ( uint8_t *  out,
const uint8_t *  in,
unsigned int  len,
const uint8_t *  key,
uint8_t *  ctr,
AES_CtrFuncPtr_TypeDef  ctrFunc 
)

Please see AES_CTR128() for CTR figure.

Please refer to general comments on layout and byte ordering of parameters.

Parameters
[out]outBuffer to place encrypted/decrypted data. Must be at least len long. It may be set equal to in, in which case the input buffer is overwritten.
[in]inBuffer holding data to encrypt/decrypt. Must be at least len long.
[in]lenNumber of bytes to encrypt/decrypt. Must be a multiple of 16.
[in]key256 bit encryption key.
[in,out]ctr128 bit initial counter value. The counter is updated after each AES block encoding through use of ctrFunc.
[in]ctrFuncFunction used to update counter value.

Definition at line 818 of file em_aes.c.

References AES, AES_CTRL_AES256, AES_CTRL_DATASTART, and AES_STATUS_RUNNING.

void AES_CTRUpdate32Bit ( uint8_t *  ctr)

Notice that no special consideration is given to possible wrap around. If 32 least significant bits are 0xFFFFFFFF, they will be updated to 0x00000000, ignoring overflow.

Please refer to general comments on layout and byte ordering of parameters.

Parameters
[in,out]ctrBuffer holding 128 bit counter to be updated.

Definition at line 883 of file em_aes.c.

void AES_DecryptKey128 ( uint8_t *  out,
const uint8_t *  in 
)

Please refer to general comments on layout and byte ordering of parameters.

Parameters
[out]outBuffer to place 128 bit decryption key. Must be at least 16 bytes long. It may be set equal to in, in which case the input buffer is overwritten.
[in]inBuffer holding 128 bit encryption key. Must be at least 16 bytes long.

Definition at line 906 of file em_aes.c.

References AES, AES_CMD_START, AES_IF_DONE, AES_IntClear(), and AES_STATUS_RUNNING.

void AES_DecryptKey256 ( uint8_t *  out,
const uint8_t *  in 
)

Please refer to general comments on layout and byte ordering of parameters.

Parameters
[out]outBuffer to place 256 bit decryption key. Must be at least 32 bytes long. It may be set equal to in, in which case the input buffer is overwritten.
[in]inBuffer holding 256 bit encryption key. Must be at least 32 bytes long.

Definition at line 951 of file em_aes.c.

References AES, AES_CMD_START, AES_CTRL_AES256, and AES_STATUS_RUNNING.

void AES_ECB128 ( uint8_t *  out,
const uint8_t *  in,
unsigned int  len,
const uint8_t *  key,
bool  encrypt 
)

Encryption:

*          Plaintext                  Plaintext
*              |                          |
*              V                          V
*       +--------------+           +--------------+
* Key ->| Block cipher |     Key ->| Block cipher |
*       |  encryption  |           |  encryption  |
*       +--------------+           +--------------+
*              |                          |
*              V                          V
*         Ciphertext                 Ciphertext
* 

Decryption:

*         Ciphertext                 Ciphertext
*              |                          |
*              V                          V
*       +--------------+           +--------------+
* Key ->| Block cipher |     Key ->| Block cipher |
*       |  decryption  |           |  decryption  |
*       +--------------+           +--------------+
*              |                          |
*              V                          V
*          Plaintext                  Plaintext
* 

Please refer to general comments on layout and byte ordering of parameters.

Parameters
[out]outBuffer to place encrypted/decrypted data. Must be at least len long. It may be set equal to in, in which case the input buffer is overwritten.
[in]inBuffer holding data to encrypt/decrypt. Must be at least len long.
[in]lenNumber of bytes to encrypt/decrypt. Must be a multiple of 16.
[in]keyWhen doing encryption, this is the 128 bit encryption key. When doing decryption, this is the 128 bit decryption key. The decryption key may be generated from the encryption key with AES_DecryptKey128().
[in]encryptSet to true to encrypt, false to decrypt.

Definition at line 1034 of file em_aes.c.

References AES, AES_CTRL_DATASTART, AES_CTRL_DECRYPT, AES_CTRL_KEYBUFEN, and AES_STATUS_RUNNING.

void AES_ECB256 ( uint8_t *  out,
const uint8_t *  in,
unsigned int  len,
const uint8_t *  key,
bool  encrypt 
)

Please see AES_ECB128() for ECB figure.

Please refer to general comments on layout and byte ordering of parameters.

Parameters
[out]outBuffer to place encrypted/decrypted data. Must be at least len long. It may be set equal to in, in which case the input buffer is overwritten.
[in]inBuffer holding data to encrypt/decrypt. Must be at least len long.
[in]lenNumber of bytes to encrypt/decrypt. Must be a multiple of 16.
[in]keyWhen doing encryption, this is the 256 bit encryption key. When doing decryption, this is the 256 bit decryption key. The decryption key may be generated from the encryption key with AES_DecryptKey256().
[in]encryptSet to true to encrypt, false to decrypt.

Definition at line 1135 of file em_aes.c.

References AES, AES_CTRL_AES256, AES_CTRL_DATASTART, AES_CTRL_DECRYPT, and AES_STATUS_RUNNING.

__STATIC_INLINE void AES_IntClear ( uint32_t  flags)
Parameters
[in]flagsPending AES interrupt source to clear. Use a bitwise logic OR combination of valid interrupt flags for the AES module (AES_IF_nnn).

Definition at line 150 of file em_aes.h.

References AES.

Referenced by AES_DecryptKey128().

__STATIC_INLINE void AES_IntDisable ( uint32_t  flags)
Parameters
[in]flagsAES interrupt sources to disable. Use a bitwise logic OR combination of valid interrupt flags for the AES module (AES_IF_nnn).

Definition at line 164 of file em_aes.h.

References AES.

__STATIC_INLINE void AES_IntEnable ( uint32_t  flags)
Note
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. Consider using AES_IntClear() prior to enabling if such a pending interrupt should be ignored.
Parameters
[in]flagsAES interrupt sources to enable. Use a bitwise logic OR combination of valid interrupt flags for the AES module (AES_IF_nnn).

Definition at line 183 of file em_aes.h.

References AES.

__STATIC_INLINE uint32_t AES_IntGet ( void  )
Note
The event bits are not cleared by the use of this function.
Returns
AES interrupt sources pending. A bitwise logic OR combination of valid interrupt flags for the AES module (AES_IF_nnn).

Definition at line 200 of file em_aes.h.

References AES.

__STATIC_INLINE uint32_t AES_IntGetEnabled ( void  )
Note
Interrupt flags are not cleared by the use of this function.
Returns
Pending and enabled AES interrupt sources The return value is the bitwise AND of
  • the enabled interrupt sources in AES_IEN and
  • the pending interrupt flags AES_IF

Definition at line 220 of file em_aes.h.

References AES.

__STATIC_INLINE void AES_IntSet ( uint32_t  flags)
Parameters
[in]flagsAES interrupt sources to set to pending. Use a bitwise logic OR combination of valid interrupt flags for the AES module (AES_IF_nnn).

Definition at line 237 of file em_aes.h.

References AES.

void AES_OFB128 ( uint8_t *  out,
const uint8_t *  in,
unsigned int  len,
const uint8_t *  key,
const uint8_t *  iv 
)

Encryption:

*          InitVector    +----------------+
*              |         |                |
*              V         |                V
*       +--------------+ |        +--------------+
* Key ->| Block cipher | |  Key ->| Block cipher |
*       |  encryption  | |        |  encryption  |
*       +--------------+ |        +--------------+
*              |         |                |
*              |---------+                |
*              V                          V
* Plaintext ->XOR            Plaintext ->XOR
*              |                          |
*              V                          V
*         Ciphertext                 Ciphertext
* 

Decryption:

*          InitVector    +----------------+
*              |         |                |
*              V         |                V
*       +--------------+ |        +--------------+
* Key ->| Block cipher | |  Key ->| Block cipher |
*       |  encryption  | |        |  encryption  |
*       +--------------+ |        +--------------+
*              |         |                |
*              |---------+                |
*              V                          V
* Ciphertext ->XOR           Ciphertext ->XOR
*              |                          |
*              V                          V
*          Plaintext                  Plaintext
* 

Please refer to general comments on layout and byte ordering of parameters.

Parameters
[out]outBuffer to place encrypted/decrypted data. Must be at least len long. It may be set equal to in, in which case the input buffer is overwritten.
[in]inBuffer holding data to encrypt/decrypt. Must be at least len long.
[in]lenNumber of bytes to encrypt/decrypt. Must be a multiple of 16.
[in]key128 bit encryption key.
[in]iv128 bit initalization vector to use.

Definition at line 1246 of file em_aes.c.

References AES, AES_CMD_START, AES_CTRL_KEYBUFEN, and AES_STATUS_RUNNING.

void AES_OFB256 ( uint8_t *  out,
const uint8_t *  in,
unsigned int  len,
const uint8_t *  key,
const uint8_t *  iv 
)

Please see AES_OFB128() for OFB figure.

Please refer to general comments on layout and byte ordering of parameters.

Parameters
[out]outBuffer to place encrypted/decrypted data. Must be at least len long. It may be set equal to in, in which case the input buffer is overwritten.
[in]inBuffer holding data to encrypt/decrypt. Must be at least len long.
[in]lenNumber of bytes to encrypt/decrypt. Must be a multiple of 16.
[in]key256 bit encryption key.
[in]iv128 bit initalization vector to use.

Definition at line 1332 of file em_aes.c.

References AES, AES_CMD_START, AES_CTRL_AES256, and AES_STATUS_RUNNING.