nRF5 SDK v13.0.0
Macros | Functions
ECDH related functions

Provides ECDH related functionality through nrf_crypto. More...

Macros

#define NRF_CRYPTO_ECDH_SHARED_SECRET_INSTANCE_CREATE(name, type)
 Macro to create an instance of a ECDH shared secret with a given name. More...
 
#define NRF_CRYPTO_ECDH_SHARED_SECRET_CREATE_FROM_ARRAY(name, type, input)
 Macro to create an instance of a ECDH shared secret with a given name, type and input. More...
 
#define NRF_CRYPTO_BLE_ECDH_CURVE_INFO
 Macro to express curve information for Bluetooth LE Secure Connection (LESC) More...
 

Functions

uint32_t nrf_crypto_ecdh_shared_secret_size_get (nrf_ecc_curve_type_t curve_type, uint32_t *p_size)
 Function to get the shared secret size given curve type. More...
 
uint32_t nrf_crypto_ecdh_shared_secret_allocate (nrf_crypto_curve_info_t curve_type, nrf_value_length_t *p_shared_secret, nrf_value_length_t const *p_raw_shared_secret)
 Function to allocate dynamic memory for ECDH shared secret. More...
 
uint32_t nrf_crypto_ecdh_shared_secret_free (nrf_value_length_t *p_shared_secret)
 Function to free allocated memory for ECDH shared secret. More...
 
uint32_t nrf_crypto_ecdh_shared_secret_compute (nrf_crypto_curve_info_t curve_info, nrf_value_length_t const *p_private_key, nrf_value_length_t const *p_public_key, nrf_value_length_t *p_shared_secret)
 Function for computing a shared secret from a key pair. More...
 

Detailed Description

Provides ECDH related functionality through nrf_crypto.

Macro Definition Documentation

#define NRF_CRYPTO_BLE_ECDH_CURVE_INFO
Value:
{ \
.curve_type = NRF_CRYPTO_CURVE_SECP256R1, \
.endian_type = NRF_CRYPTO_ENDIAN_LE \
}

Macro to express curve information for Bluetooth LE Secure Connection (LESC)

#define NRF_CRYPTO_ECDH_SHARED_SECRET_CREATE_FROM_ARRAY (   name,
  type,
  input 
)
Value:
STATIC_ASSERT(sizeof(input) == STRING_CONCATENATE(NRF_CRYPTO_ECDH_SHARED_SECRET_SIZE_, type)); \
static nrf_value_length_t name = \
{ \
.p_value = input, \
.length = STRING_CONCATENATE(NRF_CRYPTO_ECDH_SHARED_SECRET_SIZE_, type) \
}

Macro to create an instance of a ECDH shared secret with a given name, type and input.

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

Note
This creates the value length structure used for nrf_crypto APIs and a buffer to hold the shared secret without using dynamically allocated memory.
Parameters
[in]nameName of the variable to hold an ECDH shared secret.
[in]typeEither SECP160R1, SECP192R1, SECP224R1, SECP256R1, SECP384R1, SECP521R1, SECP192K1, SECP224K1, or SECP256K1.
[in]inputInput must be an array of correct size according to the curve type.
#define NRF_CRYPTO_ECDH_SHARED_SECRET_INSTANCE_CREATE (   name,
  type 
)
Value:
__ALIGN(4) static uint8_t \
name ## _backing[STRING_CONCATENATE(NRF_CRYPTO_ECDH_SHARED_SECRET_SIZE_, type)]; \
static nrf_value_length_t name = \
{ \
.p_value = name ## _backing, \
.length = STRING_CONCATENATE(NRF_CRYPTO_ECDH_SHARED_SECRET_SIZE_, type) \
}

Macro to create an instance of a ECDH shared secret with a given name.

Note
This creates the value length structure used for nrf_crypto APIs and a buffer to hold the shared secret without using dynamically allocated memory.
Parameters
[in]nameName of the variable to hold an ECDH shared secret.
[in]typeEither SECP160R1, SECP192R1, SECP224R1, SECP256R1, SECP384R1, SECP521R1, SECP192K1, SECP224K1, or SECP256K1.

Function Documentation

uint32_t nrf_crypto_ecdh_shared_secret_allocate ( nrf_crypto_curve_info_t  curve_type,
nrf_value_length_t p_shared_secret,
nrf_value_length_t const *  p_raw_shared_secret 
)

Function to allocate dynamic memory for ECDH shared secret.

Parameters
[in]curve_typeElliptic curve to use.
[in,out]p_shared_secretPointer to structure to hold a shared secret.
[in]p_raw_shared_secretPointer to structure holding a raw representation of a shared secret. If this is not NULL, the value will be copied to the allocated memory.
Return values
NRF_SUCCESSMemory for the public key was successfully allocated.
NRF_ERROR_NULLIf any of the parameters was NULL.
Anyother error code reported by the memory manager.
uint32_t nrf_crypto_ecdh_shared_secret_compute ( nrf_crypto_curve_info_t  curve_info,
nrf_value_length_t const *  p_private_key,
nrf_value_length_t const *  p_public_key,
nrf_value_length_t p_shared_secret 
)

Function for computing a shared secret from a key pair.

Note
Length of allocated buffers for private key, public key and shared secret is taken as input.
Parameters
[in]curve_infoElliptic curve to use, and requested endianness of p_shared_secret.
[in]p_private_keyPointer to structure holding private key.
[in]p_public_keyPointer to structure holding public key.
[in,out]p_shared_secretPointer to structure to hold the calculated shared secret. After the call the length variable will be updated to the actual length of the shared secret data
Return values
NRF_SUCCESSIf the shared secret was computed successfully.
NRF_ERROR_INVALID_STATEIf the function was called when nrf_crypto was uninitialized.
NRF_ERROR_NULLIf the provided key, hash or signature parameters was NULL.
NRF_ERROR_NOT_SUPPORTEDIf the selected elliptic curve is not supported.
NRF_ERROR_INVALID_ADDRIf any of the provided pointers are invalid.
NRF_ERROR_INVALID_DATAIf any of the keys or result data is deemed invalid by the nrf_crypto backend.
NRF_ERROR_INVALID_LENGTHIf the length of allocated data for keys or result is incorrect.
NRF_ERROR_INTERNALIf an internal error occured in the nrf_crypto backend.
uint32_t nrf_crypto_ecdh_shared_secret_free ( nrf_value_length_t p_shared_secret)

Function to free allocated memory for ECDH shared secret.

Parameters
[in]p_shared_secret
Return values
NRF_SUCCESSMemory for the ECDH shared secret was successfully freed.
Anyother error code reported by the memory manager.
uint32_t nrf_crypto_ecdh_shared_secret_size_get ( nrf_ecc_curve_type_t  curve_type,
uint32_t *  p_size 
)

Function to get the shared secret size given curve type.

Parameters
[in]curve_typeElliptic curve to use.
[in,out]p_sizePointer to variable to hold size of shared secret.
Return values
NRF_SUCCESSShared secret size was calculated.
NRF_ERROR_NOT_SUPPORTEDSelected curve was not supported.

Documentation feedback | Developer Zone | Subscribe | Updated