nRF5 SDK v15.0.0
Modules | Typedefs | Functions | Variables
Hash-based message authentication code (HMAC) related functions

Provides functions to generate Hash-based message authentication code (HMAC). More...

Modules

 Meta backend.
 Includes all backends definitions.
 
 Types shared between all @ref nrf_crypto_hmac backends.
 Types shared between all Hash-based message authentication code (HMAC) related functions backends.
 

Typedefs

typedef
nrf_crypto_backend_hmac_context_t 
nrf_crypto_hmac_context_t
 Context type for HMAC. More...
 

Functions

ret_code_t nrf_crypto_hmac_init (nrf_crypto_hmac_context_t *const p_context, nrf_crypto_hmac_info_t const *p_info, uint8_t const *p_key, size_t key_size)
 Initialize context object for HMAC. More...
 
ret_code_t nrf_crypto_hmac_update (nrf_crypto_hmac_context_t *const p_context, uint8_t const *p_data, size_t data_size)
 Feed data to HMAC algorithm. More...
 
ret_code_t nrf_crypto_hmac_finalize (nrf_crypto_hmac_context_t *const p_context, uint8_t *p_digest, size_t *const p_digest_size)
 Calculate HMAC. More...
 
ret_code_t nrf_crypto_hmac_calculate (nrf_crypto_hmac_context_t *const p_context, nrf_crypto_hmac_info_t const *p_info, uint8_t *p_digest, size_t *const p_digest_size, uint8_t const *p_key, size_t key_size, uint8_t const *p_data, size_t data_size)
 Integrated HMAC wrapper function. More...
 

Variables

const nrf_crypto_hmac_info_t g_nrf_crypto_hmac_sha256_info
 Information structures used to select the specific algorithm (SHA-256) More...
 
const nrf_crypto_hmac_info_t g_nrf_crypto_hmac_sha512_info
 Information structures used to select the specific algorithm (SHA-512) More...
 

Detailed Description

Provides functions to generate Hash-based message authentication code (HMAC).

Provides functions to generate Hash-based message authentication code (HMAC) using one of the supported hash algorithms. This layer is independent of backend crypto library.

Typedef Documentation

Context type for HMAC.

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

Function Documentation

ret_code_t nrf_crypto_hmac_calculate ( nrf_crypto_hmac_context_t *const  p_context,
nrf_crypto_hmac_info_t const *  p_info,
uint8_t *  p_digest,
size_t *const  p_digest_size,
uint8_t const *  p_key,
size_t  key_size,
uint8_t const *  p_data,
size_t  data_size 
)

Integrated HMAC wrapper function.

Note
This is an integrated wrapper functions that can be used instead of calling other HMAC functions individually.
Parameters
[in,out]p_contextOptional pointer to context structure. Context memory will be allocated internally if the pointer is NULL.
[in]p_infoPointer to static info structure. This defines the algorithm. This should be either g_nrf_crypto_hmac_sha256_info or g_nrf_crypto_hmac_sha512_info.
[out]p_digestPointer to HMAC digest. Buffer must be large enough to hold the digest.
[in,out]p_digest_sizeLength of digest (result) buffer as input. Length of digest as output.
[in]p_keyPointer to HMAC key.
[in]key_sizeLenth of the HMAC key in bytes.
[in]p_dataPointer to input data.
[in]data_sizeLength of input data.
Return values
NRF_SUCCESSHMAC hash was successfully calculated.
NRF_ERROR_CRYPTO_INPUT_NULLIf p_key or p_data was NULL.
NRF_ERROR_CRYPTO_INPUT_LOCATIONInput data not in RAM (CC310 only).
NRF_ERROR_CRYPTO_INPUT_LENGTHIf key_size or data_size was invalid.
NRF_ERROR_CRYPTO_OUTPUT_NULLIf data_size was NULL.
NRF_ERROR_CRYPTO_OUTPUT_LENGTHIf data_size is not enough to hold the digest.
NRF_ERROR_CRYPTO_ALLOC_FAILEDUnable to allocate memory for the context.
NRF_ERROR_CRYPTO_INTERNALAn error occurred in the crypto backend.
NRF_ERROR_CRYPTO_BUSYThe function could not be called because the nrf_crypto backend was busy. Please rerun the cryptographic routine at a later time. CC310 only.
ret_code_t nrf_crypto_hmac_finalize ( nrf_crypto_hmac_context_t *const  p_context,
uint8_t *  p_digest,
size_t *const  p_digest_size 
)

Calculate HMAC.

Note
nrf_crypto_hmac_update must be called at least once before calling this.
Parameters
[in,out]p_contextContext pointer.
[out]p_digestPointer to HMAC digest (result) buffer. Must be large enough to hold the digest (32 byte for SHA-256 and 64 byte for SHA-512).
[in,out]p_digest_sizeLength of buffer as input. Length of digest as output.
Return values
NRF_SUCCESSHMAC hash was successfully calculated.
NRF_ERROR_CRYPTO_CONTEXT_NULLIf p_context was NULL.
NRF_ERROR_CRYPTO_CONTEXT_NOT_INITIALIZEDIf p_context has not been initialized.
NRF_ERROR_CRYPTO_OUTPUT_NULLIf p_digest was NULL.
NRF_ERROR_CRYPTO_OUTPUT_LENGTHIf p_size is not enough to hold the digest.
NRF_ERROR_CRYPTO_INTERNALAn error occurred in the crypto backend.
NRF_ERROR_CRYPTO_BUSYThe function could not be called because the nrf_crypto backend was busy. Please rerun the cryptographic routine at a later time. CC310 only.
ret_code_t nrf_crypto_hmac_init ( nrf_crypto_hmac_context_t *const  p_context,
nrf_crypto_hmac_info_t const *  p_info,
uint8_t const *  p_key,
size_t  key_size 
)

Initialize context object for HMAC.

Use to initialize a context once it has been allocated.

Note
Must be called before nrf_crypto_hmac_update. Can also be called after nrf_crypto_hmac_finalize order to start a new HMAC calculation re-using an existing context object.
Parameters
[in,out]p_contextPointer to context structure.
[in]p_infoPointer to static info structure. This defines the algorithm. This should be either g_nrf_crypto_hmac_sha256_info or g_nrf_crypto_hmac_sha512_info.
[in]p_keyHMAC key.
[in]key_sizeLength of the HMAC key in bytes.
Return values
NRF_SUCCESSData successfully consumed.
NRF_ERROR_CRYPTO_CONTEXT_NULLIf p_context has not been initialized.
NRF_ERROR_CRYPTO_INPUT_NULLIf p_info or p_key was NULL.
NRF_ERROR_CRYPTO_INPUT_LENGTHIf key_size was invalid.
NRF_ERROR_CRYPTO_INPUT_LOCATIONInput data not in RAM (CC310 only).
NRF_ERROR_CRYPTO_INTERNALAn error occurred in the crypto backend.
NRF_ERROR_CRYPTO_BUSYThe function could not be called because the nrf_crypto backend was busy. Please rerun the cryptographic routine at a later time. CC310 only.
ret_code_t nrf_crypto_hmac_update ( nrf_crypto_hmac_context_t *const  p_context,
uint8_t const *  p_data,
size_t  data_size 
)

Feed data to HMAC algorithm.

Note
Must be called after nrf_crypto_hmac_init and before nrf_crypto_hmac_finalize. Can be called repeatedly to consume data as it arrives.
Parameters
[in,out]p_contextContext pointer.
[in]p_dataPointer to input data buffer.
[in]data_sizeLength of input data.
Return values
NRF_SUCCESSData successfully consumed.
NRF_ERROR_CRYPTO_CONTEXT_NULLIf p_context has not been initialized.
NRF_ERROR_CRYPTO_CONTEXT_NOT_INITIALIZEDIf p_data was NULL.
NRF_ERROR_CRYPTO_INPUT_NULLIf p_data was NULL.
NRF_ERROR_CRYPTO_INPUT_LENGTHIf size was invalid.
NRF_ERROR_CRYPTO_INPUT_LOCATIONInput data not in RAM (CC310 only).
NRF_ERROR_CRYPTO_INTERNALAn error occurred in the crypto backend.
NRF_ERROR_CRYPTO_BUSYThe function could not be called because the nrf_crypto backend was busy. Please rerun the cryptographic routine at a later time. CC310 only.

Variable Documentation

const nrf_crypto_hmac_info_t g_nrf_crypto_hmac_sha256_info

Information structures used to select the specific algorithm (SHA-256)

The information structure is used in a generic way but is populated by the backend, and contains backend specific data.

const nrf_crypto_hmac_info_t g_nrf_crypto_hmac_sha512_info

Information structures used to select the specific algorithm (SHA-512)

The information structure is used in a generic way but is populated by the backend, and contains backend specific data.


Documentation feedback | Developer Zone | Subscribe | Updated