ndn-lite
Data Structures | Typedefs | Functions
ndn-lite-ecc.h File Reference
#include "../ndn-error-code.h"
#include "ndn-lite-sec-config.h"
#include "ndn-lite-rng.h"

Go to the source code of this file.

Data Structures

struct  ndn_ecc_backend
 The structure to represent the backend implementation. More...
 
struct  ndn_ecc_pub
 The structure to keep an ECC public key. More...
 
struct  ndn_ecc_prv
 The structure to keep an ECC private key. More...
 

Typedefs

typedef struct abstract_ecc_pub_key abstract_ecc_pub_key_t
 The opaque abstract ecc key struct to be implemented by the backend. More...
 
typedef struct abstract_ecc_prv_key abstract_ecc_prv_key_t
 
typedef uint32_t(* ndn_ecc_get_pub_key_size_impl) (const abstract_ecc_pub_key_t *pub_key)
 The APIs that are supposed to be implemented by the backend. More...
 
typedef uint32_t(* ndn_ecc_get_prv_key_size_impl) (const abstract_ecc_prv_key_t *prv_key)
 
typedef const uint8_t *(* ndn_ecc_get_pub_key_value_impl) (const abstract_ecc_pub_key_t *pub_key)
 
typedef int(* ndn_ecc_load_pub_key_impl) (abstract_ecc_pub_key_t *pub_key, const uint8_t *key_value, uint32_t key_size)
 
typedef int(* ndn_ecc_load_prv_key_impl) (abstract_ecc_prv_key_t *prv_key, const uint8_t *key_value, uint32_t key_size)
 
typedef int(* ndn_ecc_set_rng_impl) (ndn_rng_impl rng)
 
typedef int(* ndn_ecdsa_sign_impl) (const uint8_t *payload_value, uint32_t payload_size, uint8_t *output_value, uint32_t output_max_size, const abstract_ecc_prv_key_t *prv_key, uint8_t ecdsa_type, uint32_t *output_used_size)
 
typedef int(* ndn_ecdsa_verify_impl) (const uint8_t *payload_value, uint32_t payload_size, const uint8_t *sig_value, uint32_t sig_size, const abstract_ecc_pub_key_t *pub_key, uint8_t ecdsa_type)
 
typedef int(* ndn_ecc_make_key_impl) (abstract_ecc_pub_key_t *pub_key, abstract_ecc_prv_key_t *prv_key, uint8_t curve_type)
 
typedef int(* ndn_ecc_dh_shared_secret_impl) (const abstract_ecc_pub_key_t *ecc_pub, const abstract_ecc_prv_key_t *ecc_prv, uint8_t curve_type, uint8_t *output, uint32_t output_size)
 
typedef struct ndn_ecc_backend ndn_ecc_backend_t
 The structure to represent the backend implementation. More...
 
typedef struct ndn_ecc_pub ndn_ecc_pub_t
 The structure to keep an ECC public key. More...
 
typedef struct ndn_ecc_prv ndn_ecc_prv_t
 The structure to keep an ECC private key. More...
 

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...
 
static int ndn_ecc_pub_init (ndn_ecc_pub_t *ecc_pub, const uint8_t *key_value, uint32_t key_size, uint8_t curve_type, uint32_t key_id)
 Initialize an ECC 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...
 
static int ndn_ecc_prv_init (ndn_ecc_prv_t *ecc_prv, const uint8_t *key_value, uint32_t key_size, uint8_t curve_type, uint32_t key_id)
 Initialize an ECC 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...
 

Typedef Documentation

◆ abstract_ecc_prv_key_t

◆ abstract_ecc_pub_key_t

The opaque abstract ecc key struct to be implemented by the backend.

◆ ndn_ecc_backend_t

The structure to represent the backend implementation.

◆ ndn_ecc_dh_shared_secret_impl

typedef int(* ndn_ecc_dh_shared_secret_impl) (const abstract_ecc_pub_key_t *ecc_pub, const abstract_ecc_prv_key_t *ecc_prv, uint8_t curve_type, uint8_t *output, uint32_t output_size)

◆ ndn_ecc_get_prv_key_size_impl

typedef uint32_t(* ndn_ecc_get_prv_key_size_impl) (const abstract_ecc_prv_key_t *prv_key)

◆ ndn_ecc_get_pub_key_size_impl

typedef uint32_t(* ndn_ecc_get_pub_key_size_impl) (const abstract_ecc_pub_key_t *pub_key)

The APIs that are supposed to be implemented by the backend.

◆ ndn_ecc_get_pub_key_value_impl

typedef const uint8_t*(* ndn_ecc_get_pub_key_value_impl) (const abstract_ecc_pub_key_t *pub_key)

◆ ndn_ecc_load_prv_key_impl

typedef int(* ndn_ecc_load_prv_key_impl) (abstract_ecc_prv_key_t *prv_key, const uint8_t *key_value, uint32_t key_size)

◆ ndn_ecc_load_pub_key_impl

typedef int(* ndn_ecc_load_pub_key_impl) (abstract_ecc_pub_key_t *pub_key, const uint8_t *key_value, uint32_t key_size)

◆ ndn_ecc_make_key_impl

typedef int(* ndn_ecc_make_key_impl) (abstract_ecc_pub_key_t *pub_key, abstract_ecc_prv_key_t *prv_key, uint8_t curve_type)

◆ ndn_ecc_prv_t

typedef struct ndn_ecc_prv ndn_ecc_prv_t

The structure to keep an ECC private key.

◆ ndn_ecc_pub_t

typedef struct ndn_ecc_pub ndn_ecc_pub_t

The structure to keep an ECC public key.

◆ ndn_ecc_set_rng_impl

typedef int(* ndn_ecc_set_rng_impl) (ndn_rng_impl rng)

◆ ndn_ecdsa_sign_impl

typedef int(* ndn_ecdsa_sign_impl) (const uint8_t *payload_value, uint32_t payload_size, uint8_t *output_value, uint32_t output_max_size, const abstract_ecc_prv_key_t *prv_key, uint8_t ecdsa_type, uint32_t *output_used_size)

◆ ndn_ecdsa_verify_impl

typedef int(* ndn_ecdsa_verify_impl) (const uint8_t *payload_value, uint32_t payload_size, const uint8_t *sig_value, uint32_t sig_size, const abstract_ecc_pub_key_t *pub_key, uint8_t ecdsa_type)

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_prv_init()

static int ndn_ecc_prv_init ( ndn_ecc_prv_t ecc_prv,
const uint8_t *  key_value,
uint32_t  key_size,
uint8_t  curve_type,
uint32_t  key_id 
)
inlinestatic

Initialize an ECC private key.

Parameters
ecc_prv.Input. The ECC private key whose info will be set.
key_value.Input. The key value bytes to set.
key_size.Input. The key size. Should not larger than 32 bytes.
curve_type.Input. Type of ECC Curve. Can be secp160r1, secp192r1, secp224r1, secp256r1, secp256k1.
key_id.Input. The key id to be set with this ECC private key.
Returns
0 if there is no error.

◆ ndn_ecc_pub_init()

static int ndn_ecc_pub_init ( ndn_ecc_pub_t ecc_pub,
const uint8_t *  key_value,
uint32_t  key_size,
uint8_t  curve_type,
uint32_t  key_id 
)
inlinestatic

Initialize an ECC public key.

Parameters
ecc_pub.Input. The ECC public key whose info will be set.
key_value.Input. The key value bytes to set.
key_size.Input. The key size. Should not larger than 64 bytes.
curve_type.Input. Type of ECC Curve. Can be secp160r1, secp192r1, secp224r1, secp256r1, secp256k1.
key_id.Input. The key id to be set with this ECC public key.
Returns
0 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.