ECDSA related functions

nRF5 SDK v13.1.0

Provides ECDSA related functionality through nrf_crypto. More...

Macros

#define NRF_CRYPTO_ECDSA_SIGN_CONTEXT_INSTANCE_CREATE (name)
Macro to create an instance of a ECDSA sign context by a given name. More...
#define NRF_CRYPTO_VERIFY_CONTEXT_INSTANCE_CREATE (name)
Macro to create an instance of a ECDSA verify context by a given name. More...
#define NRF_CRYPTO_ECDSA_SIGNATURE_CREATE (name, type)
Macro to create an instance of an ECDSA signature by a given name and type. More...
#define NRF_CRYPTO_ECDSA_SIGNATURE_INSTANCE_CREATE_FROM_INPUT (name, type, input)
Macro to create an instance of an ECDSA signature by a given name, type and input. More...

Functions

uint32_t nrf_crypto_ecdsa_signature_size_get ( nrf_ecc_curve_type_t curve_type, uint32_t *p_sig_size)
Function to get the size of a ECDSA signature given curve type. More...
uint32_t nrf_crypto_ecdsa_sizes_get ( nrf_crypto_signature_info_t sig_info, nrf_crypto_ecdsa_sizes_t *p_sizes)
Function to get the sizes used for ECDSA sign/verify given curve_type. More...
uint32_t nrf_crypto_ecdsa_signature_allocate ( nrf_crypto_signature_info_t sig_info, nrf_value_length_t *p_signature, nrf_value_length_t const *p_raw_signature)
Function to allocate dynamic memory for holding a signature. More...
uint32_t nrf_crypto_ecdsa_signature_free ( nrf_value_length_t *p_signature)
Function to free dynamic memory allocated for holding a signature. More...
uint32_t nrf_crypto_ecdsa_sign_hash ( nrf_crypto_signature_info_t sig_info, nrf_value_length_t const *p_private_key, nrf_value_length_t const *p_hash, nrf_value_length_t *p_signature)
Function for signing a hash using a private key. More...
uint32_t nrf_crypto_ecdsa_verify_hash ( nrf_crypto_signature_info_t sig_info, nrf_value_length_t const *p_public_key, nrf_value_length_t const *p_hash, nrf_value_length_t const *p_signature)
Function for verifying a hash using a public key. More...

Detailed Description

Provides ECDSA related functionality through nrf_crypto.

Macro Definition Documentation

#define NRF_CRYPTO_ECDSA_SIGN_CONTEXT_INSTANCE_CREATE ( name )
Value:
static uint8_t name ## _buffer[NRF_CRYPTO_ECDSASIGN_CONTEXT_SIZE]; \
static nrf_value_length_t name = \
{ \
.p_value = name ## _buffer, \
.length = NRF_CRYPTO_SIGN_CONTEXT_SIZE \
}

Macro to create an instance of a ECDSA sign context by a given name.

Note
This creates the value length structure used for nrf_crypto APIs and a buffer to hold the sign context without using dynamically allocated memory.
#define NRF_CRYPTO_ECDSA_SIGNATURE_CREATE ( name,
type
)
Value:
static uint8_t name ## _buffer[ STRING_CONCATENATE (NRF_CRYPTO_ECDSA_SIGNATURE_SIZE_, type)]; \
static nrf_value_length_t name = \
{ \
.p_value = name ## _buffer, \
.length = STRING_CONCATENATE (NRF_CRYPTO_ECDSA_SIGNATURE_SIZE_, type) \
}

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

Parameters
[in] name Name of the ECDSA signature instance.
[in] type Either SECP160R1, SECP192R1, SECP224R1, SECP256R1, SECP384R1, SECP521R1, SECP192K1, SECP224K1, or SECP256K1
Note
This creates the value length structure used for nrf_crypto APIs and a buffer to hold the signature without using dynamically allocated memory.
#define NRF_CRYPTO_ECDSA_SIGNATURE_INSTANCE_CREATE_FROM_INPUT ( name,
type,
input
)
Value:
STATIC_ASSERT ( sizeof (input) == STRING_CONCATENATE (NRF_CRYPTO_ECDSA_SIGNATURE_SIZE_, type)); \
static nrf_value_length_t name = \
{ \
.p_value = name ## _buffer, \
.length = STRING_CONCATENATE (NRF_CRYPTO_ECDSA_SIGNATURE_SIZE_, type) \
}

Macro to create an instance of an ECDSA signature by 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 signature without using dynamically allocated memory.
Parameters
[in] name Name of the ECDSA signature instance.
[in] type Either SECP160R1, SECP192R1, SECP224R1, SECP256R1, SECP384R1, SECP521R1, SECP192K1, SECP224K1, or SECP256K1
[in] input Input must be an array of correct size according to the curve type.
#define NRF_CRYPTO_VERIFY_CONTEXT_INSTANCE_CREATE ( name )
Value:
static uint8_t name ## _buffer[ NRF_CRYPTO_ECDSA_VERIFY_CONTEXT_SIZE ]; \
static nrf_value_length_t name = \
{ \
.p_value = name ## _buffer, \
}

Macro to create an instance of a ECDSA verify context by a given name.

Note
This creates the value length structure used for nrf_crypto APIs and a buffer to hold the verify context without using dynamically allocated memory.

Function Documentation

uint32_t nrf_crypto_ecdsa_sign_hash ( nrf_crypto_signature_info_t sig_info ,
nrf_value_length_t const * p_private_key ,
nrf_value_length_t const * p_hash ,
nrf_value_length_t * p_signature
)

Function for signing a hash using a private key.

Note
Key sizes and signature must be allocated before calling this function.
Parameters
[in] sig_info Elliptic curve to use for signing and endianness of the resulting signature.
[in] p_private_key Pointer to structure holding private key.
[in] p_hash Pointer to structure holding hash to use for signing.
[in,out] p_signature Pointer to structure holding signature.
Return values
NRF_SUCCESS If the signature was created successfully.
NRF_ERROR_INVALID_STATE If the function was called when nrf_crypto was uninitialized.
NRF_ERROR_NULL If the provided key, hash or signature parameters was NULL.
NRF_ERROR_NOT_SUPPORTED If the selected curve or hash type is not supported.
NRF_ERROR_INVALID_ADDR If the key, hash or signature paramenters aren't aligned.
NRF_ERROR_INVALID_LENGTH If the allocated length of the provided private key or hash is invalid or the signature is bigger than the size of the provided buffer.
NRF_ERROR_INVALID_DATA If any of the keys or result data is deemed invalid by the nrf_crypto backend.
NRF_ERROR_INTERNAL If an internal error occured in the nrf_crypto backend.
uint32_t nrf_crypto_ecdsa_signature_allocate ( nrf_crypto_signature_info_t sig_info ,
nrf_value_length_t * p_signature ,
nrf_value_length_t const * p_raw_signature
)

Function to allocate dynamic memory for holding a signature.

Note
The signature must be allocated before calling this function.
If p_raw_signature is not NULL, then the content will be copied to the allocated buffer.
Parameters
[in] sig_info Curve and hash function used for representing a signature
[in,out] p_signature Pointer to value-length structure to hold the signature.
[in] p_raw_signature Pointer to byte representation of raw key given curve type.
Return values
NRF_SUCCESS Memory for the signature was successfully allocated.
NRF_ERROR_NULL Signature parameter was NULL.
Any other error code reported by the memory manager.
uint32_t nrf_crypto_ecdsa_signature_free ( nrf_value_length_t * p_signature )

Function to free dynamic memory allocated for holding a signature.

Parameters
[in,out] p_signature Pointer to value-length structure that holds the allocated space to be freed.
Return values
NRF_SUCCESS Memory for the signature was successfully allocated.
NRF_ERROR_NULL Signature parameter was NULL.
Any other error code reported by the memory manager.
uint32_t nrf_crypto_ecdsa_signature_size_get ( nrf_ecc_curve_type_t curve_type ,
uint32_t * p_sig_size
)

Function to get the size of a ECDSA signature given curve type.

Parameters
[in] curve_type Elliptic curve to use.
[in] p_sig_size Pointer to variable to hold size of a signature.
Return values
NRF_SUCCESS If the he signature size was calculated.
NRF_ERROR_NULL If p_sizes was NULL.
NRF_ERROR_NOT_SUPPORTED Selected curve was not supported.
uint32_t nrf_crypto_ecdsa_sizes_get ( nrf_crypto_signature_info_t sig_info ,
nrf_crypto_ecdsa_sizes_t * p_sizes
)

Function to get the sizes used for ECDSA sign/verify given curve_type.

This function will report back the private/public key, signature and hash sizes.

Parameters
[in] sig_info Elliptic curve and hash to use.
[in] p_sizes Pointer to variable to hold the key, hash and signature sizes.
Return values
NRF_SUCCESS If the ECDSA sizes was calculated.
NRF_ERROR_NULL If p_sizes was NULL.
NRF_ERROR_NOT_SUPPORTED Selected curve or hash was not supported.
uint32_t nrf_crypto_ecdsa_verify_hash ( nrf_crypto_signature_info_t sig_info ,
nrf_value_length_t const * p_public_key ,
nrf_value_length_t const * p_hash ,
nrf_value_length_t const * p_signature
)

Function for verifying a hash using a public key.

Note
Key sizes and signature must be allocated before calling this function.
Parameters
[in] sig_info Elliptic curve to use for verification and endianness of the signature given as input.
[in] p_public_key Pointer to structure holding public key.
[in] p_hash Pointer to structure holding hash to use for verification.
[in,out] p_signature Pointer to structure holding signature.
Return values
NRF_SUCCESS If the signature was verified and is valid.
NRF_ERROR_INVALID_DATA If the signature did not match the provided hash.
NRF_ERROR_INVALID_ADDR If the key, hash or signature data aren't aligned.
NRF_ERROR_INVALID_STATE If the function was called when nrf_crypto was uninitialized.
NRF_ERROR_NULL If the provided key, hash or signature parameters was NULL.
NRF_ERROR_INVALID_LENGTH If the length of the provided public key, hash, or signature is invalid.
NRF_ERROR_NOT_SUPPORTED If the selected curve or hash type is not supported.
NRF_ERROR_INVALID_ADDR If any of the provided pointers is invalid.
NRF_ERROR_INTERNAL If an internal error occured in the nrf_crypto backend.