Cryptography library

nRF5 SDK v12.2.0

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.

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_alg Hashing algorithm to use (see Hashing algorithms ).
[in] p_data Data to be hashed.
[in] len Length of the data to be hashed.
[out] p_hash Hash or digest (see nrf_crypto_key_t ).
Return values
NRF_SUCCESS If the hash was computed successfully.
NRF_ERROR_NOT_SUPPORTED If the selected hashing algorithm is not supported.
NRF_ERROR_INVALID_ADDR If any of the provided pointers is invalid.
NRF_ERROR_INVALID_LENGTH If 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] curve Elliptic curve to use (see Cryptographic curves ).
[in] p_sk Private key (see nrf_crypto_key_t ).
[out] p_pk Public key (see nrf_crypto_key_t ).
Return values
NRF_SUCCESS If the public key was computed successfully.
NRF_ERROR_NOT_SUPPORTED If the selected curve is not supported.
NRF_ERROR_INVALID_ADDR If any of the provided pointers is invalid.
NRF_ERROR_INVALID_LENGTH If 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] curve Elliptic curve to use (see Cryptographic curves ).
[in] p_sk Private key (see nrf_crypto_key_t ).
[in] p_pk Public key (see nrf_crypto_key_t ).
[out] p_ss Shared secret (see nrf_crypto_key_t ).
Return values
NRF_SUCCESS If the shared secret was computed successfully.
NRF_ERROR_NOT_SUPPORTED If the selected curve is not supported.
NRF_ERROR_INVALID_ADDR If any of the provided pointers is invalid.
NRF_ERROR_INVALID_LENGTH If 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] curve Elliptic curve to use (see Cryptographic curves ).
[in] p_sk Private key (see nrf_crypto_key_t ).
[in] p_hash Hash or digest to sign (see nrf_crypto_key_t ).
[out] p_sig Signature (see nrf_crypto_key_t ).
Return values
NRF_SUCCESS If the signature was created successfully.
NRF_ERROR_NOT_SUPPORTED If the selected curve is not supported.
NRF_ERROR_INVALID_ADDR If any of the provided pointers is invalid.
NRF_ERROR_INVALID_LENGTH If 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] curve Elliptic curve to use (see Cryptographic curves ).
[in] p_pk Public key (see nrf_crypto_key_t ).
[in] p_hash Hash or digest to compare to (see nrf_crypto_key_t ).
[in] p_sig Signature (see nrf_crypto_key_t ).
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 or digest.
NRF_ERROR_NOT_SUPPORTED If the selected curve is not supported.
NRF_ERROR_INVALID_ADDR If any of the provided pointers is invalid.
NRF_ERROR_INVALID_LENGTH If the length of the provided public key, hash, or signature is invalid.