nRF5 SDK v13.0.0
Macros | Functions
ECDSA related functions

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]nameName of the ECDSA signature instance.
[in]typeEither 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]nameName of the ECDSA signature instance.
[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_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_infoElliptic curve to use for signing and endianness of the resulting signature.
[in]p_private_keyPointer to structure holding private key.
[in]p_hashPointer to structure holding hash to use for signing.
[in,out]p_signaturePointer to structure holding signature.
Return values
NRF_SUCCESSIf the signature was created 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 curve or hash type is not supported.
NRF_ERROR_INVALID_ADDRIf the key, hash or signature paramenters aren't aligned.
NRF_ERROR_INVALID_LENGTHIf 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_DATAIf any of the keys or result data is deemed invalid by the nrf_crypto backend.
NRF_ERROR_INTERNALIf 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_infoCurve and hash function used for representing a signature
[in,out]p_signaturePointer to value-length structure to hold the signature.
[in]p_raw_signaturePointer to byte representation of raw key given curve type.
Return values
NRF_SUCCESSMemory for the signature was successfully allocated.
NRF_ERROR_NULLSignature parameter was NULL.
Anyother 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_signaturePointer to value-length structure that holds the allocated space to be freed.
Return values
NRF_SUCCESSMemory for the signature was successfully allocated.
NRF_ERROR_NULLSignature parameter was NULL.
Anyother 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_typeElliptic curve to use.
[in]p_sig_sizePointer to variable to hold size of a signature.
Return values
NRF_SUCCESSIf the he signature size was calculated.
NRF_ERROR_NULLIf p_sizes was NULL.
NRF_ERROR_NOT_SUPPORTEDSelected 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_infoElliptic curve and hash to use.
[in]p_sizesPointer to variable to hold the key, hash and signature sizes.
Return values
NRF_SUCCESSIf the ECDSA sizes was calculated.
NRF_ERROR_NULLIf p_sizes was NULL.
NRF_ERROR_NOT_SUPPORTEDSelected 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_infoElliptic curve to use for verification and endianness of the signature given as input.
[in]p_public_keyPointer to structure holding public key.
[in]p_hashPointer to structure holding hash to use for verification.
[in,out]p_signaturePointer to structure holding signature.
Return values
NRF_SUCCESSIf the signature was verified and is valid.
NRF_ERROR_INVALID_DATAIf the signature did not match the provided hash.
NRF_ERROR_INVALID_ADDRIf the key, hash or signature data aren't aligned.
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_INVALID_LENGTHIf the length of the provided public key, hash, or signature is invalid.
NRF_ERROR_NOT_SUPPORTEDIf the selected curve or hash type is not supported.
NRF_ERROR_INVALID_ADDRIf any of the provided pointers is invalid.
NRF_ERROR_INTERNALIf an internal error occured in the nrf_crypto backend.

Documentation feedback | Developer Zone | Subscribe | Updated