nRF5 SDK v17.1.0
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
AES related functions

Provides AES related functionality through nrf_crypto. More...

Data Structures

struct  nrf_crypto_aes_info_t
 
struct  nrf_crypto_aes_internal_context_t
 
struct  nrf_crypto_backend_aes_ctx_t
 
struct  nrf_crypto_backend_no_iv_aes_ctx_t
 

Macros

#define NRF_CRYPTO_AES_INIT_MAGIC_VALUE   (0x53454163)
 
#define NRF_CRYPTO_AES_UNINIT_MAGIC_VALUE   (0x63414553)
 
#define NRF_CRYPTO_MBEDTLS_AES_IV_SIZE   (16)
 

Typedefs

typedef
nrf_crypto_backend_aes_context_t 
nrf_crypto_aes_context_t
 Context type for AES. More...
 
typedef ret_code_t(* aes_init_fn_t )(void *const p_context, nrf_crypto_operation_t operation)
 
typedef ret_code_t(* aes_uninit_fn_t )(void *const p_context)
 
typedef ret_code_t(* aes_key_set_fn_t )(void *const p_context, uint8_t *p_key)
 
typedef ret_code_t(* aes_iv_set_fn_t )(void *const p_context, uint8_t *p_iv)
 
typedef ret_code_t(* aes_iv_get_fn_t )(void *const p_context, uint8_t *p_iv)
 
typedef ret_code_t(* aes_update_fn_t )(void *const p_context, uint8_t *p_data_in, size_t data_size, uint8_t *p_data_out)
 
typedef ret_code_t(* aes_finalize_fn_t )(void *const p_context, uint8_t *p_data_in, size_t data_size, uint8_t *p_data_out, size_t *p_data_out_size)
 

Enumerations

enum  nrf_crypto_aes_mode_t {
  NRF_CRYPTO_AES_MODE_CBC,
  NRF_CRYPTO_AES_MODE_CBC_PAD_PCKS7,
  NRF_CRYPTO_AES_MODE_CFB,
  NRF_CRYPTO_AES_MODE_CTR,
  NRF_CRYPTO_AES_MODE_ECB,
  NRF_CRYPTO_AES_MODE_ECB_PAD_PCKS7,
  NRF_CRYPTO_AES_MODE_CBC_MAC,
  NRF_CRYPTO_AES_MODE_CBC_MAC_PAD_PCKS7,
  NRF_CRYPTO_AES_MODE_CMAC
}
 

Functions

ret_code_t nrf_crypto_aes_init (nrf_crypto_aes_context_t *const p_context, nrf_crypto_aes_info_t const *const p_info, nrf_crypto_operation_t operation)
 Function for initializing the AES context. More...
 
ret_code_t nrf_crypto_aes_uninit (nrf_crypto_aes_context_t *const p_context)
 Internal function for uninitializing the AES context. More...
 
ret_code_t nrf_crypto_aes_key_set (nrf_crypto_aes_context_t *const p_context, uint8_t *p_key)
 Function for setting the AES key. More...
 
ret_code_t nrf_crypto_aes_iv_set (nrf_crypto_aes_context_t *const p_context, uint8_t *p_iv)
 Function for setting an AES IV or a counter for AES modes which are using it. More...
 
ret_code_t nrf_crypto_aes_iv_get (nrf_crypto_aes_context_t *const p_context, uint8_t *p_iv)
 Function for getting an AES IV or a counter for mode which is supporting it. More...
 
ret_code_t nrf_crypto_aes_update (nrf_crypto_aes_context_t *const p_context, uint8_t *p_data_in, size_t data_size, uint8_t *p_data_out)
 AES update function for encryption, decryption and MAC calculation. It can be called once on the whole data block, or as many times as needed, until all the input data is processed. Functions: nrf_crypto_aes_init, nrf_crypto_aes_key_set, and, for some ciphers, nrf_crypto_aes_iv_set, must be called before call to this API with the same context. More...
 
ret_code_t nrf_crypto_aes_finalize (nrf_crypto_aes_context_t *const p_context, uint8_t *p_data_in, size_t data_size, uint8_t *p_data_out, size_t *p_data_out_size)
 Function processes the last data block if needed and finalizes the AES operation (ie. adds padding) and produces operation results (for MAC operations). Functions: nrf_crypto_aes_init, nrf_crypto_aes_key_set, and, for some ciphers, nrf_crypto_aes_iv_set, must be called before call to this API with the same context. More...
 
ret_code_t nrf_crypto_aes_crypt (nrf_crypto_aes_context_t *const p_context, nrf_crypto_aes_info_t const *const p_info, nrf_crypto_operation_t operation, uint8_t *p_key, uint8_t *p_iv, uint8_t *p_data_in, size_t data_size, uint8_t *p_data_out, size_t *p_data_out_size)
 AES integrated function for encryption, decryption and MAC calculation. It should be called once on the whole data block. More...
 
ret_code_t padding_pkcs7_add (uint8_t *p_padding_buff, uint8_t *p_message_buff, uint8_t msg_ending_len)
 
ret_code_t padding_pkcs7_remove (uint8_t *p_padded_message, size_t *p_message_len)
 

Variables

const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_128_info
 External variable declaration to the info structure for AES CBC mode with a 128-bit key. No padding. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_192_info
 External variable declaration to the info structure for AES CBC mode with a 192-bit key. No padding. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_256_info
 External variable declaration to the info structure for AES CBC mode with a 256-bit key. No padding. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_128_pad_pkcs7_info
 External variable declaration to the info structure for AES CBC mode with a 128-bit key. Padding pkcs7 enabled. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_192_pad_pkcs7_info
 External variable declaration to the info structure for AES CBC mode with a 192-bit key. Padding pkcs7 enabled. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_256_pad_pkcs7_info
 External variable declaration to the info structure for AES CBC mode with a 256-bit key. Padding pkcs7 enabled. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ctr_128_info
 External variable declaration to the info structure for AES CTR mode with a 128-bit key. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ctr_192_info
 External variable declaration to the info structure for AES CTR mode with a 192-bit key. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ctr_256_info
 External variable declaration to the info structure for AES CTR mode with a 256-bit key. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cfb_128_info
 External variable declaration to the info structure for AES CFB mode with a 128-bit key. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cfb_192_info
 External variable declaration to the info structure for AES CFB mode with a 192-bit key. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cfb_256_info
 External variable declaration to the info structure for AES CFB mode with a 256-bit key. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ecb_128_info
 External variable declaration to the info structure for AES ECB mode with a 128-bit key. No padding. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ecb_192_info
 External variable declaration to the info structure for AES ECB mode with a 192-bit key. No padding. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ecb_256_info
 External variable declaration to the info structure for AES ECB mode with a 256-bit key. No padding. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ecb_128_pad_pkcs7_info
 External variable declaration to the info structure for AES ECB mode with a 128-bit key. Padding pkcs7 enabled. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ecb_192_pad_pkcs7_info
 External variable declaration to the info structure for AES ECB mode with a 192-bit key. Padding pkcs7 enabled. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ecb_256_pad_pkcs7_info
 External variable declaration to the info structure for AES ECB mode with a 256-bit key. Padding pkcs7 enabled. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_mac_128_info
 External variable declaration to the info structure for AES CBC MAC mode with a 128-bit key. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_mac_192_info
 External variable declaration to the info structure for AES CBC MAC mode with a 192-bit key. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_mac_256_info
 External variable declaration to the info structure for AES CBC MAC mode with a 256-bit key. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_mac_128_pad_pkcs7_info
 External variable declaration to the info structure for AES CBC MAC mode with a 128-bit key. Padding pkcs7 enabled. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_mac_192_pad_pkcs7_info
 External variable declaration to the info structure for AES CBC MAC mode with a 192-bit key. Padding pkcs7 enabled. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_mac_256_pad_pkcs7_info
 External variable declaration to the info structure for AES CBC MAC mode with a 256-bit key. Padding pkcs7 enabled. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cmac_128_info
 External variable declaration to the info structure for AES CMAC mode with a 128-bit key. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cmac_192_info
 External variable declaration to the info structure for AES CMAC mode with a 192-bit key. More...
 
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cmac_256_info
 External variable declaration to the info structure for AES CMAC mode with a 256-bit key. More...
 

Detailed Description

Provides AES related functionality through nrf_crypto.

Typedef Documentation

Context type for AES.

Note
The size of this type is scaled for the largest AES backend context that is enabled in SDK configuration header file.

Function Documentation

ret_code_t nrf_crypto_aes_crypt ( nrf_crypto_aes_context_t *const  p_context,
nrf_crypto_aes_info_t const *const  p_info,
nrf_crypto_operation_t  operation,
uint8_t *  p_key,
uint8_t *  p_iv,
uint8_t *  p_data_in,
size_t  data_size,
uint8_t *  p_data_out,
size_t *  p_data_out_size 
)

AES integrated function for encryption, decryption and MAC calculation. It should be called once on the whole data block.

Parameters
[in]p_contextContext object. If NULL, memory will be dynamically allocated.
[in]p_infoPointer to structure holding information about: selected AES mode, key size, and padding.
[in]operationParameter indicating whether an encrypt (NRF_CRYPTO_ENCRYPT), a decrypt (NRF_CRYPTO_DECRYPT) or MAC calculation (NRF_CRYPTO_MAC_CALCULATE) operation shall be performed.
[in]p_keyPointer to the AES key. This buffer will be copied and there is no need to keep it by the user.
[in]p_ivPointer to a buffer of the IV or a counter. This buffer will be copied and there is no need to keep it by the user. Can be NULL for ECB and CMAC.
[in]p_data_inPointer to the input buffer to the AES.
[in]data_sizeSize of the data to be processed in bytes.
[out]p_data_outPointer to the output buffer. When padding is set:
  • The size of p_data_out buffer must have extra space for padding. Otherwise, the function will return an error: NRF_ERROR_CRYPTO_OUTPUT_LENGTH.
  • When text_size is multiple of 16 bytes, p_text_out must be allocated with size equal to text_size + an additional block (i.e 16 bytes for padding).
  • When text_size is not a multiple of 16 bytes, p_text_out must be allocated with size aligned to the next full 16 bytes block (i.e. 1 - 15 bytes for padding).
[in,out]p_data_out_sizeIN: Size of the p_data_out buffer. OUT: Upon successfull function execution value will be updated with number of signifacnt bytes in p_data_out buffer. On decryption function will result in a value without padded bytes.
Returns
NRF_SUCCESS on success.
ret_code_t nrf_crypto_aes_finalize ( nrf_crypto_aes_context_t *const  p_context,
uint8_t *  p_data_in,
size_t  data_size,
uint8_t *  p_data_out,
size_t *  p_data_out_size 
)

Function processes the last data block if needed and finalizes the AES operation (ie. adds padding) and produces operation results (for MAC operations). Functions: nrf_crypto_aes_init, nrf_crypto_aes_key_set, and, for some ciphers, nrf_crypto_aes_iv_set, must be called before call to this API with the same context.

Upon successful operation function will deinitialize the context but for some ciphers it will be possible to read IV. In order to fully deinitialize context you must call nrf_crypto_aes_uninit.

Parameters
[in]p_contextContext object. Must be initialized before the call.
[in]p_data_inPointer to the input buffer to the AES.
[in]data_sizeSize of the data to be processed in bytes.
[out]p_data_outPointer to the output buffer. When padding is set:
  • The size of p_data_out buffer must have extra space for padding. Otherwise, the function will return an error: NRF_ERROR_CRYPTO_OUTPUT_LENGTH.
  • When text_size is multiple of 16 bytes, p_text_out must be allocated with size equal to text_size + an additional block (i.e 16 bytes for padding).
  • When text_size is not a multiple of 16 bytes, p_text_out must be allocated with size aligned to the next full 16 bytes block (i.e. 1 - 15 bytes for padding).
[in,out]p_data_out_sizeIN: Size of the p_data_out buffer. OUT: Upon successfull function execution value will be updated with number of signifacnt bytes in p_data_out buffer. On decryption with padding function will result in a value without padded bytes.
Returns
NRF_SUCCESS on success.
ret_code_t nrf_crypto_aes_init ( nrf_crypto_aes_context_t *const  p_context,
nrf_crypto_aes_info_t const *const  p_info,
nrf_crypto_operation_t  operation 
)

Function for initializing the AES context.

Parameters
[in]p_contextPointer to the context object. It must be a context type associated with the object provided in the p_info parameter or other memory that can hold that context type.
[in]p_infoPointer to structure holding information about: selected AES mode, key size, and padding.
[in]operationParameter indicating whether an encrypt (NRF_CRYPTO_ENCRYPT), a decrypt (NRF_CRYPTO_DECRYPT) or MAC calculation (NRF_CRYPTO_MAC_CALCULATE) operation shall be performed.
Returns
NRF_SUCCESS on success.
ret_code_t nrf_crypto_aes_iv_get ( nrf_crypto_aes_context_t *const  p_context,
uint8_t *  p_iv 
)

Function for getting an AES IV or a counter for mode which is supporting it.

Parameters
[in]p_contextContext object. Must be initialized before the call.
[out]p_ivPointer to a buffer of the IV or a counter.
Returns
NRF_SUCCESS on success.
ret_code_t nrf_crypto_aes_iv_set ( nrf_crypto_aes_context_t *const  p_context,
uint8_t *  p_iv 
)

Function for setting an AES IV or a counter for AES modes which are using it.

Parameters
[in]p_contextContext object. Must be initialized before the call.
[in]p_ivPointer to a buffer of the IV or a counter. This buffer will be copied and there is no need to keep it by the user.
Returns
NRF_SUCCESS on success.
ret_code_t nrf_crypto_aes_key_set ( nrf_crypto_aes_context_t *const  p_context,
uint8_t *  p_key 
)

Function for setting the AES key.

Parameters
[in]p_contextContext object. Must be initialized before the call.
[in]p_keyPointer to the AES key. This buffer will be copied and there is no need to keep it by the user.
Returns
NRF_SUCCESS on success.
ret_code_t nrf_crypto_aes_uninit ( nrf_crypto_aes_context_t *const  p_context)

Internal function for uninitializing the AES context.

Parameters
[in]p_contextContext object. Must be initialized before the call.
Returns
NRF_SUCCESS on success.
ret_code_t nrf_crypto_aes_update ( nrf_crypto_aes_context_t *const  p_context,
uint8_t *  p_data_in,
size_t  data_size,
uint8_t *  p_data_out 
)

AES update function for encryption, decryption and MAC calculation. It can be called once on the whole data block, or as many times as needed, until all the input data is processed. Functions: nrf_crypto_aes_init, nrf_crypto_aes_key_set, and, for some ciphers, nrf_crypto_aes_iv_set, must be called before call to this API with the same context.

Parameters
[in]p_contextContext object. Must be initialized before the call.
[in]p_data_inPointer to the input buffer to the AES.
[in]data_sizeSize of the data to be processed in bytes. For all modes except CFB it must be multiple of 16 bytes.
[out]p_data_outPointer to the output buffer.
Returns
NRF_SUCCESS on success.

Variable Documentation

const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_128_info

External variable declaration to the info structure for AES CBC mode with a 128-bit key. No padding.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_128_pad_pkcs7_info

External variable declaration to the info structure for AES CBC mode with a 128-bit key. Padding pkcs7 enabled.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_192_info

External variable declaration to the info structure for AES CBC mode with a 192-bit key. No padding.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_192_pad_pkcs7_info

External variable declaration to the info structure for AES CBC mode with a 192-bit key. Padding pkcs7 enabled.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_256_info

External variable declaration to the info structure for AES CBC mode with a 256-bit key. No padding.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_256_pad_pkcs7_info

External variable declaration to the info structure for AES CBC mode with a 256-bit key. Padding pkcs7 enabled.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_mac_128_info

External variable declaration to the info structure for AES CBC MAC mode with a 128-bit key.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_mac_128_pad_pkcs7_info

External variable declaration to the info structure for AES CBC MAC mode with a 128-bit key. Padding pkcs7 enabled.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_mac_192_info

External variable declaration to the info structure for AES CBC MAC mode with a 192-bit key.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_mac_192_pad_pkcs7_info

External variable declaration to the info structure for AES CBC MAC mode with a 192-bit key. Padding pkcs7 enabled.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_mac_256_info

External variable declaration to the info structure for AES CBC MAC mode with a 256-bit key.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cbc_mac_256_pad_pkcs7_info

External variable declaration to the info structure for AES CBC MAC mode with a 256-bit key. Padding pkcs7 enabled.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cfb_128_info

External variable declaration to the info structure for AES CFB mode with a 128-bit key.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cfb_192_info

External variable declaration to the info structure for AES CFB mode with a 192-bit key.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cfb_256_info

External variable declaration to the info structure for AES CFB mode with a 256-bit key.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cmac_128_info

External variable declaration to the info structure for AES CMAC mode with a 128-bit key.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cmac_192_info

External variable declaration to the info structure for AES CMAC mode with a 192-bit key.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_cmac_256_info

External variable declaration to the info structure for AES CMAC mode with a 256-bit key.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ctr_128_info

External variable declaration to the info structure for AES CTR mode with a 128-bit key.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ctr_192_info

External variable declaration to the info structure for AES CTR mode with a 192-bit key.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ctr_256_info

External variable declaration to the info structure for AES CTR mode with a 256-bit key.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ecb_128_info

External variable declaration to the info structure for AES ECB mode with a 128-bit key. No padding.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ecb_128_pad_pkcs7_info

External variable declaration to the info structure for AES ECB mode with a 128-bit key. Padding pkcs7 enabled.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ecb_192_info

External variable declaration to the info structure for AES ECB mode with a 192-bit key. No padding.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ecb_192_pad_pkcs7_info

External variable declaration to the info structure for AES ECB mode with a 192-bit key. Padding pkcs7 enabled.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ecb_256_info

External variable declaration to the info structure for AES ECB mode with a 256-bit key. No padding.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.
const nrf_crypto_aes_info_t g_nrf_crypto_aes_ecb_256_pad_pkcs7_info

External variable declaration to the info structure for AES ECB mode with a 256-bit key. Padding pkcs7 enabled.

Note
The variable is defined in the nrf_crypto backend that is enabled in the sdk_config file.

Documentation feedback | Developer Zone | Subscribe | Updated