nRF5 SDK v12.1.0
Modules | Data Structures | Macros | Enumerations | Functions
Cryptography library

Cryptography library (nrf_crypto). More...

Modules

 Cryptographic curves
 Cryptographic curves that are available to the application. Currently, the nrf_crypto library supports only NIST p-256.
 
 Hashing algorithms
 Hashing algorithms that are available to the application. Currently, the nrf_crypto library supports only SHA-256.
 

Data Structures

struct  nrf_crypto_key_t
 Cryptographic key. More...
 

Macros

#define NRF_CRYPTO_SVCI_BASE   0
 Base SVCI number for the nrf_crypto module.
 

Enumerations

enum  NRF_CRYPTO_SVCIS {
  NRF_CRYPTO_SVCI_INIT = 0,
  NRF_CRYPTO_SVCI_PUBLIC_KEY_COMPUTE,
  NRF_CRYPTO_SVCI_SHARED_SECRET_COMPUTE,
  NRF_CRYPTO_SVCI_SIGN,
  NRF_CRYPTO_SVCI_VERIFY,
  NRF_CRYPTO_SVCI_HASH_COMPUTE
}
 SVCIs for the nrf_crypto module. More...
 

Functions

uint32_t nrf_crypto_init (void)
 Function for initializing the cryptography library.
 
uint32_t nrf_crypto_public_key_compute (uint32_t curve, nrf_crypto_key_t const *p_sk, nrf_crypto_key_t *p_pk)
 Function for computing a public key from a private key. More...
 
uint32_t nrf_crypto_shared_secret_compute (uint32_t curve, nrf_crypto_key_t const *p_sk, nrf_crypto_key_t const *p_pk, nrf_crypto_key_t *p_ss)
 Function for computing a shared secret from a key pair. More...
 
uint32_t nrf_crypto_sign (uint32_t curve, nrf_crypto_key_t const *p_sk, nrf_crypto_key_t const *p_hash, nrf_crypto_key_t *p_sig)
 Function for signing a hash or a digest using a private key. More...
 
uint32_t nrf_crypto_verify (uint32_t curve, nrf_crypto_key_t const *p_pk, nrf_crypto_key_t const *p_hash, nrf_crypto_key_t const *p_sig)
 Function for verifying the signature of a hash or a digest using a public key. More...
 
uint32_t nrf_crypto_hash_compute (uint32_t hash_alg, uint8_t const *p_data, uint32_t len, nrf_crypto_key_t *p_hash)
 Function for computing a hash or a digest from arbitrary data. More...
 

Detailed Description

Cryptography library (nrf_crypto).

The cryptography library provides functions to compute keys, shared secrets, and hashes, and to sign and verify data using digital signatures.

Enumeration Type Documentation

SVCIs for the nrf_crypto module.

Enumerator
NRF_CRYPTO_SVCI_INIT 

Initialize the nrf_crypto module.

NRF_CRYPTO_SVCI_PUBLIC_KEY_COMPUTE 

Compute a public key from a private key.

NRF_CRYPTO_SVCI_SHARED_SECRET_COMPUTE 

Compute a shared secret from a key pair.

NRF_CRYPTO_SVCI_SIGN 

Compute a signature from a private key and a hash.

NRF_CRYPTO_SVCI_VERIFY 

Verify a signature with a public key and a hash.

NRF_CRYPTO_SVCI_HASH_COMPUTE 

Compute a digest from data.

Function Documentation

uint32_t nrf_crypto_hash_compute ( uint32_t  hash_alg,
uint8_t const *  p_data,
uint32_t  len,
nrf_crypto_key_t p_hash 
)

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

Parameters
[in]hash_algHashing algorithm to use (see Hashing algorithms).
[in]p_dataData to be hashed.
[in]lenLength of the data to be hashed.
[out]p_hashHash or digest (see nrf_crypto_key_t).
Return values
NRF_SUCCESSIf the hash was computed successfully.
NRF_ERROR_NOT_SUPPORTEDIf the selected hashing algorithm is not supported.
NRF_ERROR_INVALID_ADDRIf any of the provided pointers is invalid.
NRF_ERROR_INVALID_LENGTHIf the hash is bigger than the size of the provided buffer.
uint32_t nrf_crypto_public_key_compute ( uint32_t  curve,
nrf_crypto_key_t const *  p_sk,
nrf_crypto_key_t p_pk 
)

Function for computing a public key from a private key.

Parameters
[in]curveElliptic curve to use (see Cryptographic curves).
[in]p_skPrivate key (see nrf_crypto_key_t).
[out]p_pkPublic key (see nrf_crypto_key_t).
Return values
NRF_SUCCESSIf the public key was computed successfully.
NRF_ERROR_NOT_SUPPORTEDIf the selected curve is not supported.
NRF_ERROR_INVALID_ADDRIf any of the provided pointers is invalid.
NRF_ERROR_INVALID_LENGTHIf the length of the provided private key is invalid or the public key is bigger than the size of the provided buffer.
uint32_t nrf_crypto_shared_secret_compute ( uint32_t  curve,
nrf_crypto_key_t const *  p_sk,
nrf_crypto_key_t const *  p_pk,
nrf_crypto_key_t p_ss 
)

Function for computing a shared secret from a key pair.

Parameters
[in]curveElliptic curve to use (see Cryptographic curves).
[in]p_skPrivate key (see nrf_crypto_key_t).
[in]p_pkPublic key (see nrf_crypto_key_t).
[out]p_ssShared secret (see nrf_crypto_key_t).
Return values
NRF_SUCCESSIf the shared secret was computed successfully.
NRF_ERROR_NOT_SUPPORTEDIf the selected curve is not supported.
NRF_ERROR_INVALID_ADDRIf any of the provided pointers is invalid.
NRF_ERROR_INVALID_LENGTHIf the length of any of the provided keys is invalid or the shared secret is bigger than the size of the provided buffer.
uint32_t nrf_crypto_sign ( uint32_t  curve,
nrf_crypto_key_t const *  p_sk,
nrf_crypto_key_t const *  p_hash,
nrf_crypto_key_t p_sig 
)

Function for signing a hash or a digest using a private key.

Parameters
[in]curveElliptic curve to use (see Cryptographic curves).
[in]p_skPrivate key (see nrf_crypto_key_t).
[in]p_hashHash or digest to sign (see nrf_crypto_key_t).
[out]p_sigSignature (see nrf_crypto_key_t).
Return values
NRF_SUCCESSIf the signature was created successfully.
NRF_ERROR_NOT_SUPPORTEDIf the selected curve is not supported.
NRF_ERROR_INVALID_ADDRIf any of the provided pointers is invalid.
NRF_ERROR_INVALID_LENGTHIf the length of the provided private key or hash is invalid or the signature is bigger than the size of the provided buffer.
uint32_t nrf_crypto_verify ( uint32_t  curve,
nrf_crypto_key_t const *  p_pk,
nrf_crypto_key_t const *  p_hash,
nrf_crypto_key_t const *  p_sig 
)

Function for verifying the signature of a hash or a digest using a public key.

Parameters
[in]curveElliptic curve to use (see Cryptographic curves).
[in]p_pkPublic key (see nrf_crypto_key_t).
[in]p_hashHash or digest to compare to (see nrf_crypto_key_t).
[in]p_sigSignature (see nrf_crypto_key_t).
Return values
NRF_SUCCESSIf the signature was verified and is valid.
NRF_ERROR_INVALID_DATAIf the signature did not match the provided hash or digest.
NRF_ERROR_NOT_SUPPORTEDIf the selected curve is not supported.
NRF_ERROR_INVALID_ADDRIf any of the provided pointers is invalid.
NRF_ERROR_INVALID_LENGTHIf the length of the provided public key, hash, or signature is invalid.

Documentation feedback | Developer Zone | Subscribe | Updated