AES
[EM_Library]

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

Collaboration diagram for AES:

Typedefs

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

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.
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.
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.
void AES_CTRUpdate32Bit (uint8_t *ctr)
 Update last 32 bits of 128 bit counter, by incrementing with 1.
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.
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.
__STATIC_INLINE void AES_IntClear (uint32_t flags)
 Clear one or more pending AES interrupts.
__STATIC_INLINE void AES_IntDisable (uint32_t flags)
 Disable one or more AES interrupts.
__STATIC_INLINE void AES_IntEnable (uint32_t flags)
 Enable one or more AES interrupts.
__STATIC_INLINE uint32_t AES_IntGet (void)
 Get pending AES interrupt flags.
__STATIC_INLINE void AES_IntSet (uint32_t flags)
 Set one or more pending AES interrupts from SW.
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.

Detailed Description

Advanced Encryption Standard Accelerator (AES) Peripheral API for EFM32.

This API is intended for use on EFM32 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)

AES counter modification function pointer.

Parameters:

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

Definition at line 68 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 
)

Cipher-block chaining (CBC) cipher mode encryption/decryption, 128 bit key.

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] out Buffer 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] in Buffer holding data to encrypt/decrypt. Must be at least len long.
[in] len Number of bytes to encrypt/decrypt. Must be a multiple of 16.
[in] key When 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] iv 128 bit initalization vector to use.
[in] encrypt Set to true to encrypt, false to decrypt.

Definition at line 159 of file em_aes.c.

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.

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] out Buffer 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] in Buffer holding data to encrypt/decrypt. Must be at least len long.
[in] len Number of bytes to encrypt/decrypt. Must be a multiple of 16.
[in] key 128 bit encryption key is used for both encryption and decryption modes.
[in] iv 128 bit initalization vector to use.
[in] encrypt Set to true to encrypt, false to decrypt.

Definition at line 488 of file em_aes.c.

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.

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] out Buffer 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] in Buffer holding data to encrypt/decrypt. Must be at least len long.
[in] len Number of bytes to encrypt/decrypt. Must be a multiple of 16.
[in] key 128 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] ctr 128 bit initial counter value. The counter is updated after each AES block encoding through use of ctrFunc.
[in] ctrFunc Function used to update counter value.

Definition at line 722 of file em_aes.c.

void AES_CTRUpdate32Bit ( uint8_t *  ctr  ) 

Update last 32 bits of 128 bit counter, by incrementing with 1.

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] ctr Buffer holding 128 bit counter to be updated.

Definition at line 885 of file em_aes.c.

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.

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

Parameters:
[out] out Buffer 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] in Buffer holding 128 bit encryption key. Must be at least 16 bytes long.

Definition at line 908 of file em_aes.c.

References AES_IntClear().

Here is the call graph for this function:

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.

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] out Buffer 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] in Buffer holding data to encrypt/decrypt. Must be at least len long.
[in] len Number of bytes to encrypt/decrypt. Must be a multiple of 16.
[in] key When 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] encrypt Set to true to encrypt, false to decrypt.

Definition at line 1036 of file em_aes.c.

__STATIC_INLINE void AES_IntClear ( uint32_t  flags  ) 

Clear one or more pending AES interrupts.

Parameters:
[in] flags Pending 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 152 of file em_aes.h.

Referenced by AES_DecryptKey128().

Here is the caller graph for this function:

__STATIC_INLINE void AES_IntDisable ( uint32_t  flags  ) 

Disable one or more AES interrupts.

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

Definition at line 166 of file em_aes.h.

__STATIC_INLINE void AES_IntEnable ( uint32_t  flags  ) 

Enable one or more AES interrupts.

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] flags AES interrupt sources to enable. Use a bitwise logic OR combination of valid interrupt flags for the AES module (AES_IF_nnn).

Definition at line 185 of file em_aes.h.

__STATIC_INLINE uint32_t AES_IntGet ( void   ) 

Get pending AES interrupt flags.

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 202 of file em_aes.h.

__STATIC_INLINE void AES_IntSet ( uint32_t  flags  ) 

Set one or more pending AES interrupts from SW.

Parameters:
[in] flags AES 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 216 of file em_aes.h.

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.

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] out Buffer 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] in Buffer holding data to encrypt/decrypt. Must be at least len long.
[in] len Number of bytes to encrypt/decrypt. Must be a multiple of 16.
[in] key 128 bit encryption key.
[in] iv 128 bit initalization vector to use.

Definition at line 1248 of file em_aes.c.