nRF5 SDK v13.0.0
Macros | Functions
Cryptographic hash related functions.

Provides cryptographic hash related functionality through nrf_crypto. More...

Macros

#define NRF_CRYPTO_HASH_SIZE(type)   STRING_CONCATENATE(NRF_CRYPTO_HASH_SIZE_, type)
 Internal macro to get the size of a given hash type. More...
 
#define NRF_CRYPTO_HASH_CONTEXT_CREATE(name, type)
 Macro to create an instance of a hash context by a given name and type. More...
 
#define NRF_CRYPTO_HASH_CREATE(name, type)
 Macro to create an instance of a hash by a given name and type. More...
 
#define NRF_CRYPTO_HASH_CREATE_FROM_ARRAY(name, type, input)
 Macro to create an instance of a hash by a given name and type and input buffer. More...
 

Functions

uint32_t nrf_crypto_hash_size_get (nrf_hash_type_t hash_type, uint32_t *p_hash_size)
 Function to get the size of a given hash type. More...
 
uint32_t nrf_crypto_hash_context_allocate (nrf_crypto_hash_info_t hash_info, nrf_value_length_t *p_hash_context)
 Function to dynamically allocate memory to hold a hash context used when calculating hash as a non-integrated step. More...
 
uint32_t nrf_crypto_hash_context_free (nrf_value_length_t *p_hash_context)
 Function to free dynamically allocated memory for hash context used when calculating hash as a non-integrated step. More...
 
uint32_t nrf_crypto_hash_allocate (nrf_crypto_hash_info_t hash_info, nrf_value_length_t *p_hash, nrf_value_length_t const *p_raw_hash)
 Function to dynamically allocate memory to hold a hash value. More...
 
uint32_t nrf_crypto_hash_free (nrf_value_length_t *p_hash)
 Function to free dynamically allocated memory for a hash value. More...
 
uint32_t nrf_crypto_hash_init (nrf_crypto_hash_info_t hash_info, nrf_value_length_t *p_hash_context)
 Function for computing a hash from arbitrary data. More...
 
uint32_t nrf_crypto_hash_update (nrf_value_length_t *p_hash_context, uint8_t const *p_data, uint32_t len)
 Function for computing a hash or a digest from arbitrary data. More...
 
uint32_t nrf_crypto_hash_finalize (nrf_crypto_hash_info_t hash_info, nrf_value_length_t *p_hash_context, nrf_value_length_t *p_hash)
 Function for computing a hash from arbitrary data. More...
 
uint32_t nrf_crypto_hash_compute (nrf_crypto_hash_info_t hash_info, uint8_t const *p_data, uint32_t len, nrf_value_length_t *p_hash)
 Function for computing a hash from arbitrary data in a single integrated step. More...
 

Detailed Description

Provides cryptographic hash related functionality through nrf_crypto.

Macro Definition Documentation

#define NRF_CRYPTO_HASH_CONTEXT_CREATE (   name,
  type 
)
Value:
__ALIGN(4) static uint8_t name ## _buffer[NRF_CRYPTO_HASH_CONTEXT_MAX_SIZE]; \
static nrf_value_length_t name = \
{ \
.p_value = name ## _buffer, \
.length = NRF_CRYPTO_HASH_CONTEXT_MAX_SIZE \
}

Macro to create an instance of a hash context by a given name and type.

Note
This creates the value length structure and a backing buffer without using dynamically allocated memory.
#define NRF_CRYPTO_HASH_CREATE (   name,
  type 
)
Value:
__ALIGN(4) static uint8_t name ## _buffer[NRF_CRYPTO_HASH_SIZE(type)]; \
static nrf_value_length_t name = \
{ \
.p_value = name ## _buffer, \
.length = NRF_CRYPTO_HASH_SIZE(type) \
}

Macro to create an instance of a hash by a given name and type.

Parameters
[in]nameName of the hash instance.
[in]typeEither MD5, SHA0, SHA1, SHA224, SHA256, SHA384 or SHA512.
Note
This creates the value length structure and a backing buffer without using dynamically allocated memory.
#define NRF_CRYPTO_HASH_CREATE_FROM_ARRAY (   name,
  type,
  input 
)
Value:
STATIC_ASSERT(sizeof(input) == NRF_CRYPTO_HASH_SIZE(type)) \
static nrf_value_length_t name = \
{ \
.p_value = (uint8_t*) input, \
.length = NRF_CRYPTO_HASH_SIZE(type) \
}

Macro to create an instance of a hash by a given name and type and input buffer.

If the input is not of the correct size a static assert will be occur compile-time.

Parameters
[in]nameName of the hash instance.
[in]typeEither MD5, SHA0, SHA1, SHA224, SHA256, SHA384 or SHA512.
[in]inputArray used as input buffer.
Note
This creates the value length structure and a backing buffer without using dynamically allocated memory.
#define NRF_CRYPTO_HASH_SIZE (   type)    STRING_CONCATENATE(NRF_CRYPTO_HASH_SIZE_, type)

Internal macro to get the size of a given hash type.

Parameters
[in]typeEither MD5, SHA0, SHA1, SHA224, SHA256, SHA384 or SHA512

Function Documentation

uint32_t nrf_crypto_hash_allocate ( nrf_crypto_hash_info_t  hash_info,
nrf_value_length_t p_hash,
nrf_value_length_t const *  p_raw_hash 
)

Function to dynamically allocate memory to hold a hash value.

Parameters
[in]hash_infoStructure holding info about hash algorithm to use and endianness for the computed hash.
[in,out]p_hashPointer to value-length structure to hold allocated space.
[in]p_raw_hashPointer to value length structure to hold raw representation of hash.
Return values
NRF_SUCCESSSpace was successfully alloacted.
uint32_t nrf_crypto_hash_compute ( nrf_crypto_hash_info_t  hash_info,
uint8_t const *  p_data,
uint32_t  len,
nrf_value_length_t p_hash 
)

Function for computing a hash from arbitrary data in a single integrated step.

Parameters
[in]hash_infoStructure holding info about hash algorithm to use and endianness for the computed hash.
[in]p_dataPointer to data to be hashed.
[in]lenLength of the data to be hashed.
[in,out]p_hashPointer to structure holding the calculated hash.
Return values
NRF_SUCCESSIf the hash was computed successfully.
NRF_ERROR_INVALID_STATEIf the function was called when nrf_crypto was uninitialized.
NRF_ERROR_NOT_SUPPORTEDIf the selected hash algorithm is not supported.
NRF_ERROR_INVALID_ADDRIf any of the provided pointers are invalid.
NRF_ERROR_INVALID_LENGTHIf the hash is bigger than the size of the provided buffer or the size of the hash context is invalid.
NRF_ERROR_INVALID_DATAIf the hash context was deemed invalid by the nrf_crypto backend.
NRF_ERROR_INTERNALIf an internal error occured in the nrf_crypto backend.
uint32_t nrf_crypto_hash_context_allocate ( nrf_crypto_hash_info_t  hash_info,
nrf_value_length_t p_hash_context 
)

Function to dynamically allocate memory to hold a hash context used when calculating hash as a non-integrated step.

Parameters
[in]hash_infoHashing algorithm to create context for
[in,out]p_hash_contextPointer to value-length structure to hold allocated space.
Return values
NRF_SUCCESSSpace was successfully allocated.
uint32_t nrf_crypto_hash_context_free ( nrf_value_length_t p_hash_context)

Function to free dynamically allocated memory for hash context used when calculating hash as a non-integrated step.

Note
The length value of the value length structure will be set to zero when the memory is freed. There is no impact of running this function on already deallocated memory.
Parameters
[in,out]p_hash_contextPointer a to value-length structure that holds the allocated space to be freed.
Return values
NRF_SUCCESSSpace was successfully freed.
uint32_t nrf_crypto_hash_finalize ( nrf_crypto_hash_info_t  hash_info,
nrf_value_length_t p_hash_context,
nrf_value_length_t p_hash 
)

Function for computing a hash from arbitrary data.

Note
The context object is assumed to be an opaque type defined by the nrf_crypto backend. See NRF_CRYPTO_HASH_CONTEXT_SIZE for the relevant nrf_crypto backend.
Parameters
[in]hash_infoStructure holding info about hash algorithm to use.
[in,out]p_hash_contextPointer to structure holding context information for the hash computation.
[in,out]p_hashPointer to structure holding the calculated hash.
Return values
NRF_SUCCESSIf the hash was computed successfully.
NRF_ERROR_INVALID_STATEIf the function was called when nrf_crypto was uninitialized.
NRF_ERROR_NULLIf the any of the parameters was NULL.
NRF_ERROR_NOT_SUPPORTEDIf the selected hash algorithm is not supported.
NRF_ERROR_INVALID_ADDRIf any of the provided pointers are invalid.
NRF_ERROR_INVALID_LENGTHIf the hash is bigger than the size of the provided buffer or the size of the hash context is invalid.
NRF_ERROR_INVALID_DATAIf the hash context was deemed invalid by the nrf_crypto backend.
NRF_ERROR_INTERNALIf an internal error occured in the nrf_crypto backend.
uint32_t nrf_crypto_hash_free ( nrf_value_length_t p_hash)

Function to free dynamically allocated memory for a hash value.

Note
The length value of the value length structure will be set to zero when the memory is freed. There is no impact of running this function on already deallocated memory.
Parameters
[in,out]p_hashPointer to a value-length structure that holds the allocated space to be freed.
Return values
NRF_SUCCESSSpace was successfully freed.
uint32_t nrf_crypto_hash_init ( nrf_crypto_hash_info_t  hash_info,
nrf_value_length_t p_hash_context 
)

Function for computing a hash from arbitrary data.

Note
The context object is assumed to be an opaque type defined by the nrf_crypto backend. See NRF_CRYPTO_HASH_CONTEXT_SIZE for the relevant nrf_crypto backend.
Parameters
[in]hash_infoStructure holding info about hash algorithm to use and endianness for the computed hash.
[in,out]p_hash_contextPointer to structure holding context information for the hash computation.
Return values
NRF_SUCCESSIf the hash initialization was successful.
NRF_ERROR_INVALID_STATEIf the function was called when nrf_crypto was uninitialized.
NRF_ERROR_NULLIf the hash context parameter was NULL.
NRF_ERROR_NOT_SUPPORTEDIf the selected hash algorithm is not supported.
NRF_ERROR_INVALID_ADDRIf any of the provided pointers are invalid.
NRF_ERROR_INVALID_LENGTHIf the hash is bigger than the size of the provided buffer.
NRF_ERROR_INVALID_DATAIf the hash context was deemed invalid by the nrf_crypto backend.
NRF_ERROR_INTERNALIf an internal error occured in the nrf_crypto backend.
uint32_t nrf_crypto_hash_size_get ( nrf_hash_type_t  hash_type,
uint32_t *  p_hash_size 
)

Function to get the size of a given hash type.

Parameters
[in]hash_typeType of hash.
[in,out]p_hash_sizePointer to variable to hold the hash size. Must not be NULL.
Return values
NRF_SUCCESSHash function found.
NRF_ERROR_NULLp_hash_size was NULL.
NRF_ERROR_NOT_SUPPORTEDRequested hash type isn't supported.
uint32_t nrf_crypto_hash_update ( nrf_value_length_t p_hash_context,
uint8_t const *  p_data,
uint32_t  len 
)

Function for computing a hash or a digest from arbitrary data.

Note
The context object is assumed to be an opaque type defined by the nrf_crypto backend. See NRF_CRYPTO_HASH_CONTEXT_SIZE for the relevant nrf_crypto backend.
Parameters
[in,out]p_hash_contextPointer to structure holding context information for the hash computation.
[in]p_dataPointer to data to be hashed.
[in]lenLength of the data to be hashed.
Return values
NRF_SUCCESSIf the hash was computed successfully.
NRF_ERROR_NULLIf the hash context parameter was NULL.
NRF_ERROR_INVALID_STATEIf the function was called when nrf_crypto was uninitialized.
NRF_ERROR_NOT_SUPPORTEDIf the selected hash algorithm is not supported.
NRF_ERROR_INVALID_ADDRIf any of the provided pointers are invalid.
NRF_ERROR_INVALID_LENGTHIf the size of the hash context is invalid.
NRF_ERROR_INVALID_DATAIf the hash context was deemed invalid by the nrf_crypto backend.
NRF_ERROR_INTERNALIf an internal error occured in the nrf_crypto backend.

Documentation feedback | Developer Zone | Subscribe | Updated