Provides functions to generate Hash-based message authentication code (HMAC).
More...
|
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...
|
|
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.
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.
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_context | Optional pointer to context structure. Context memory will be allocated internally if the pointer is NULL. |
[in] | p_info | Pointer 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_digest | Pointer to HMAC digest. Buffer must be large enough to hold the digest. |
[in,out] | p_digest_size | Length of digest (result) buffer as input. Length of digest as output. |
[in] | p_key | Pointer to HMAC key. |
[in] | key_size | Lenth of the HMAC key in bytes. |
[in] | p_data | Pointer to input data. |
[in] | data_size | Length of input data. |
- Return values
-
NRF_SUCCESS | HMAC hash was successfully calculated. |
NRF_ERROR_CRYPTO_INPUT_NULL | If p_key or p_data was NULL. |
NRF_ERROR_CRYPTO_INPUT_LOCATION | Input data not in RAM (CC310 only). |
NRF_ERROR_CRYPTO_INPUT_LENGTH | If key_size or data_size was invalid. |
NRF_ERROR_CRYPTO_OUTPUT_NULL | If data_size was NULL. |
NRF_ERROR_CRYPTO_OUTPUT_LENGTH | If data_size is not enough to hold the digest. |
NRF_ERROR_CRYPTO_ALLOC_FAILED | Unable to allocate memory for the context. |
NRF_ERROR_CRYPTO_INTERNAL | An error occurred in the crypto backend. |
NRF_ERROR_CRYPTO_BUSY | The function could not be called because the nrf_crypto backend was busy. Please rerun the cryptographic routine at a later time. CC310 only. |
Calculate HMAC.
- Note
- nrf_crypto_hmac_update must be called at least once before calling this.
- Parameters
-
[in,out] | p_context | Context pointer. |
[out] | p_digest | Pointer 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_size | Length of buffer as input. Length of digest as output. |
- Return values
-
NRF_SUCCESS | HMAC hash was successfully calculated. |
NRF_ERROR_CRYPTO_CONTEXT_NULL | If p_context was NULL. |
NRF_ERROR_CRYPTO_CONTEXT_NOT_INITIALIZED | If p_context has not been initialized. |
NRF_ERROR_CRYPTO_OUTPUT_NULL | If p_digest was NULL. |
NRF_ERROR_CRYPTO_OUTPUT_LENGTH | If p_size is not enough to hold the digest. |
NRF_ERROR_CRYPTO_INTERNAL | An error occurred in the crypto backend. |
NRF_ERROR_CRYPTO_BUSY | The function could not be called because the nrf_crypto backend was busy. Please rerun the cryptographic routine at a later time. CC310 only. |
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
-
- Return values
-
NRF_SUCCESS | Data successfully consumed. |
NRF_ERROR_CRYPTO_CONTEXT_NULL | If p_context has not been initialized. |
NRF_ERROR_CRYPTO_INPUT_NULL | If p_info or p_key was NULL. |
NRF_ERROR_CRYPTO_INPUT_LENGTH | If key_size was invalid. |
NRF_ERROR_CRYPTO_INPUT_LOCATION | Input data not in RAM (CC310 only). |
NRF_ERROR_CRYPTO_INTERNAL | An error occurred in the crypto backend. |
NRF_ERROR_CRYPTO_BUSY | The function could not be called because the nrf_crypto backend was busy. Please rerun the cryptographic routine at a later time. CC310 only. |
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_context | Context pointer. |
[in] | p_data | Pointer to input data buffer. |
[in] | data_size | Length of input data. |
- Return values
-
NRF_SUCCESS | Data successfully consumed. |
NRF_ERROR_CRYPTO_CONTEXT_NULL | If p_context has not been initialized. |
NRF_ERROR_CRYPTO_CONTEXT_NOT_INITIALIZED | If p_data was NULL. |
NRF_ERROR_CRYPTO_INPUT_NULL | If p_data was NULL. |
NRF_ERROR_CRYPTO_INPUT_LENGTH | If size was invalid. |
NRF_ERROR_CRYPTO_INPUT_LOCATION | Input data not in RAM (CC310 only). |
NRF_ERROR_CRYPTO_INTERNAL | An error occurred in the crypto backend. |
NRF_ERROR_CRYPTO_BUSY | The function could not be called because the nrf_crypto backend was busy. Please rerun the cryptographic routine at a later time. CC310 only. |
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.
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.