ndn-lite
Functions | Variables
ndn-lite-ecc.c File Reference
#include "ndn-lite-ecc.h"
#include "ndn-lite-sha.h"
#include "ndn-lite-sec-utils.h"

Functions

ndn_ecc_backend_tndn_ecc_get_backend (void)
 
uint32_t ndn_ecc_get_pub_key_size (const ndn_ecc_pub_t *pub_key)
 Get public key size in unit of byte. More...
 
uint32_t ndn_ecc_get_prv_key_size (const ndn_ecc_prv_t *prv_key)
 Get private key size in unit of byte. More...
 
const uint8_t * ndn_ecc_get_pub_key_value (const ndn_ecc_pub_t *pub_key)
 Get public key bytes. More...
 
int ndn_ecc_load_pub_key (ndn_ecc_pub_t *pub_key, const uint8_t *key_value, uint32_t key_size)
 Load in-memory key bits into an NDN public key. More...
 
int ndn_ecc_load_prv_key (ndn_ecc_prv_t *prv_key, const uint8_t *key_value, uint32_t key_size)
 Load in-memory key bits into an NDN private key. More...
 
int ndn_ecc_set_rng (ndn_rng_impl rng)
 Set RNG function for backend implementation library, which need this to perform non-deterministic signing. More...
 
int ndn_ecc_make_key (ndn_ecc_pub_t *ecc_pub, ndn_ecc_prv_t *ecc_prv, uint8_t curve_type, uint32_t key_id)
 Generate an ECC key pair with specific curve type and key id. More...
 
int ndn_ecc_dh_shared_secret (const ndn_ecc_pub_t *ecc_pub, const ndn_ecc_prv_t *ecc_prv, uint8_t curve_type, uint8_t *output, uint32_t output_size)
 Negotiate a shared secret wih given ECC public and private keys via ECDH. More...
 
int ndn_ecdsa_sign (const uint8_t *input_value, uint32_t input_size, uint8_t *output_value, uint32_t output_max_size, const ndn_ecc_prv_t *ecc_prv_key, uint8_t ecdsa_type, uint32_t *output_used_size)
 Sign a buffer using ECDSA algorithm. More...
 
int ndn_ecdsa_verify (const uint8_t *input_value, uint32_t input_size, const uint8_t *sig_value, uint32_t sig_size, const ndn_ecc_pub_t *ecc_pub_key, uint8_t ecdsa_type)
 Verify an ECDSA signature in ASN.1 DER format. More...
 

Variables

ndn_ecc_backend_t ndn_ecc_backend
 

Function Documentation

◆ ndn_ecc_dh_shared_secret()

int ndn_ecc_dh_shared_secret ( const ndn_ecc_pub_t ecc_pub,
const ndn_ecc_prv_t ecc_prv,
uint8_t  curve_type,
uint8_t *  output,
uint32_t  output_size 
)

Negotiate a shared secret wih given ECC public and private keys via ECDH.

Parameters
ecc_pub.Input. Input ECC public key.
ecc_prv.Input. Input ECC private key.
curve_type.Input. ECC curve type. Should be the same type of input public and private key.
output.Output. Buffer to receive negotiated shared secret.
output_size.Input. Size of the output buffer. Should not be smaller than 24 bytes.
Returns
NDN_SUCCESS if there is no error.

◆ ndn_ecc_get_backend()

ndn_ecc_backend_t* ndn_ecc_get_backend ( void  )

◆ ndn_ecc_get_prv_key_size()

uint32_t ndn_ecc_get_prv_key_size ( const ndn_ecc_prv_t prv_key)

Get private key size in unit of byte.

Parameters
prv_key.Input. NDN ECC private key.

◆ ndn_ecc_get_pub_key_size()

uint32_t ndn_ecc_get_pub_key_size ( const ndn_ecc_pub_t pub_key)

Get public key size in unit of byte.

Parameters
pub_key.Input. NDN ECC public key.

◆ ndn_ecc_get_pub_key_value()

const uint8_t* ndn_ecc_get_pub_key_value ( const ndn_ecc_pub_t pub_key)

Get public key bytes.

Parameters
pub_key.Input. NDN ECC public key.

◆ ndn_ecc_load_prv_key()

int ndn_ecc_load_prv_key ( ndn_ecc_prv_t prv_key,
const uint8_t *  key_value,
uint32_t  key_size 
)

Load in-memory key bits into an NDN private key.

Parameters
prv_key.Output. NDN ECC private key.
key_value.Input. Key bytes.
key_size.Input. The size of the key bytes.

◆ ndn_ecc_load_pub_key()

int ndn_ecc_load_pub_key ( ndn_ecc_pub_t pub_key,
const uint8_t *  key_value,
uint32_t  key_size 
)

Load in-memory key bits into an NDN public key.

Parameters
pub_key.Output. NDN ECC public key.
key_value.Input. Key bytes.
key_size.Input. The size of the key bytes.

◆ ndn_ecc_make_key()

int ndn_ecc_make_key ( ndn_ecc_pub_t ecc_pub,
ndn_ecc_prv_t ecc_prv,
uint8_t  curve_type,
uint32_t  key_id 
)

Generate an ECC key pair with specific curve type and key id.

Parameters
ecc_pub.Output. ECC public key whose key bytes to be generated.
ecc_prv.Output. ECC private key whose key bytes to be generated.
curve_type.Input. The chosen ECC curve type to generate the key pair.
key_id.Input. The key id to be set with public and private key.
Returns
NDN_SUCCESS if there is no error.

◆ ndn_ecc_set_rng()

int ndn_ecc_set_rng ( ndn_rng_impl  rng)

Set RNG function for backend implementation library, which need this to perform non-deterministic signing.

This function should be called before ndn_ecdsa_sign() and ndn_ecc_make_key().

Parameters
rng.Input. RNG function which will be bound to the backend implementation library.

◆ ndn_ecdsa_sign()

int ndn_ecdsa_sign ( const uint8_t *  input_value,
uint32_t  input_size,
uint8_t *  output_value,
uint32_t  output_max_size,
const ndn_ecc_prv_t ecc_prv_key,
uint8_t  ecdsa_type,
uint32_t *  output_used_size 
)

Sign a buffer using ECDSA algorithm.

This function will automatically use deterministic signing when no hardware pseudo-random number generator is available. The signature generated will be in ASN.1 DER format.

Parameters
input_value.Input. Buffer prepared to sign.
input_size.Input. Size of input buffer.
output_value.Output. Signature value.
output_max_size.Input. Buffer size of output_value
prv_key_value.Input. ECDSA private key buffer.
prv_key_size.Input. Size of private key.
ecdsa_type.Input. Type of ECDSA signature. Can be secp160r1, secp192r1, secp224r1, secp256r1, secp256k1.
output_used_size.Output. Size of used output buffer when signing complete.
Returns
NDN_SUCCESS if there is no error.

◆ ndn_ecdsa_verify()

int ndn_ecdsa_verify ( const uint8_t *  input_value,
uint32_t  input_size,
const uint8_t *  sig_value,
uint32_t  sig_size,
const ndn_ecc_pub_t ecc_pub_key,
uint8_t  ecdsa_type 
)

Verify an ECDSA signature in ASN.1 DER format.

Parameters
input_value.Input. ECDSA-signed buffer.
input_size.Input. Size of input buffer.
sig_value.Input. ECDSA signature value.
sig_size.Input. ECDSA signature size. Should not be larger than 64 bytes.
pub_key_value.Input. ECDSA public key.
pub_key_size.Input. size of public key. Should not be larger than 64 bytes.
Returns
NDN_SUCCESS if verification succeeded.

Variable Documentation

◆ ndn_ecc_backend