ndn-lite
Data Structures | Typedefs | Functions
ndn-lite-hmac.h File Reference
#include "../ndn-error-code.h"
#include "ndn-lite-sec-config.h"
#include <inttypes.h>

Go to the source code of this file.

Data Structures

struct  ndn_hmac_backend
 The structure to represent the backend implementation. More...
 
struct  ndn_hmac_key
 The structure to keep a HMAC key. More...
 

Typedefs

typedef struct abstract_hmac_key abstract_hmac_key_t
 The opaque abstract hmac key struct to be implemented by the backend. More...
 
typedef uint32_t(* ndn_hmac_get_key_size_impl) (const abstract_hmac_key_t *hmac_key)
 The APIs that are supposed to be implemented by the backend. More...
 
typedef const uint8_t *(* ndn_hmac_get_key_value_impl) (const abstract_hmac_key_t *hmac_key)
 
typedef int(* ndn_hmac_load_key_impl) (abstract_hmac_key_t *hmac_key, const uint8_t *key_value, uint32_t key_size)
 
typedef int(* ndn_hmac_sha256_impl) (const void *payload, uint32_t payload_length, const abstract_hmac_key_t *hmac_key, uint8_t *hmac_result)
 
typedef int(* ndn_hmac_make_key_impl) (abstract_hmac_key_t *key, const uint8_t *input_value, uint32_t input_size, const uint8_t *personalization, uint32_t personalization_size, const uint8_t *seed_value, uint32_t seed_size, const uint8_t *additional_value, uint32_t additional_size, uint32_t salt_size)
 
typedef int(* ndn_hkdf_impl) (const uint8_t *input_value, uint32_t input_size, uint8_t *output_value, uint32_t output_size, const uint8_t *seed_value, uint32_t seed_size)
 
typedef int(* ndn_hmacprng_impl) (const uint8_t *input_value, uint32_t input_size, uint8_t *output_value, uint32_t output_size, const uint8_t *seed_value, uint32_t seed_size, const uint8_t *additional_value, uint32_t additional_size)
 
typedef struct ndn_hmac_backend ndn_hmac_backend_t
 The structure to represent the backend implementation. More...
 
typedef struct ndn_hmac_key ndn_hmac_key_t
 The structure to keep a HMAC key. More...
 

Functions

ndn_hmac_backend_tndn_hmac_get_backend (void)
 
uint32_t ndn_hmac_get_key_size (const ndn_hmac_key_t *hmac_key)
 Get hmac key size in unit of byte. More...
 
const uint8_t * ndn_hmac_get_key_value (const ndn_hmac_key_t *hmac_key)
 Get hmac key bytes. More...
 
int ndn_hmac_load_key (ndn_hmac_key_t *hmac_key, const uint8_t *key_value, uint32_t key_size)
 Load in-memory key bits into an NDN hmac key. More...
 
static int ndn_hmac_key_init (ndn_hmac_key_t *hmac_key, const uint8_t *key_value, uint32_t key_size, uint32_t key_id)
 Initialize a HMAC key. More...
 
int ndn_hmac_sha256 (const void *payload, uint32_t payload_length, const ndn_hmac_key_t *hmac_key, uint8_t *hmac_result)
 Generate HMAC using sha256 digest algorithm. More...
 
int ndn_hmac_sign (const uint8_t *input_value, uint32_t input_size, uint8_t *output_value, uint32_t output_max_size, const ndn_hmac_key_t *hmac_key, uint32_t *output_used_size)
 Sign a buffer using HMAC algorithm. More...
 
int ndn_hmac_verify (const uint8_t *input_value, uint32_t input_size, const uint8_t *sig_value, uint32_t sig_size, const ndn_hmac_key_t *hmac_key)
 Verify a HMAC signature. More...
 
int ndn_hmac_make_key (ndn_hmac_key_t *key, uint32_t key_id, const uint8_t *input_value, uint32_t input_size, const uint8_t *personalization, uint32_t personalization_size, const uint8_t *seed_value, uint32_t seed_size, const uint8_t *additional_value, uint32_t additional_size, uint32_t salt_size)
 Generate a HMAC key with specific key size and key id. More...
 
int ndn_hkdf (const uint8_t *input_value, uint32_t input_size, uint8_t *output_value, uint32_t output_size, const uint8_t *seed_value, uint32_t seed_size)
 Use HMAC-KDF (key derivation function) to generate a secure HMAC key. More...
 
int ndn_hmacprng (const uint8_t *input_value, uint32_t input_size, uint8_t *output_value, uint32_t output_size, const uint8_t *seed_value, uint32_t seed_size, const uint8_t *additional_value, uint32_t additional_size)
 Use HMAC-PRNG algorithm to generate pseudo-random bytes. More...
 

Typedef Documentation

◆ abstract_hmac_key_t

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

◆ ndn_hkdf_impl

typedef int(* ndn_hkdf_impl) (const uint8_t *input_value, uint32_t input_size, uint8_t *output_value, uint32_t output_size, const uint8_t *seed_value, uint32_t seed_size)

◆ ndn_hmac_backend_t

The structure to represent the backend implementation.

◆ ndn_hmac_get_key_size_impl

typedef uint32_t(* ndn_hmac_get_key_size_impl) (const abstract_hmac_key_t *hmac_key)

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

◆ ndn_hmac_get_key_value_impl

typedef const uint8_t*(* ndn_hmac_get_key_value_impl) (const abstract_hmac_key_t *hmac_key)

◆ ndn_hmac_key_t

typedef struct ndn_hmac_key ndn_hmac_key_t

The structure to keep a HMAC key.

◆ ndn_hmac_load_key_impl

typedef int(* ndn_hmac_load_key_impl) (abstract_hmac_key_t *hmac_key, const uint8_t *key_value, uint32_t key_size)

◆ ndn_hmac_make_key_impl

typedef int(* ndn_hmac_make_key_impl) (abstract_hmac_key_t *key, const uint8_t *input_value, uint32_t input_size, const uint8_t *personalization, uint32_t personalization_size, const uint8_t *seed_value, uint32_t seed_size, const uint8_t *additional_value, uint32_t additional_size, uint32_t salt_size)

◆ ndn_hmac_sha256_impl

typedef int(* ndn_hmac_sha256_impl) (const void *payload, uint32_t payload_length, const abstract_hmac_key_t *hmac_key, uint8_t *hmac_result)

◆ ndn_hmacprng_impl

typedef int(* ndn_hmacprng_impl) (const uint8_t *input_value, uint32_t input_size, uint8_t *output_value, uint32_t output_size, const uint8_t *seed_value, uint32_t seed_size, const uint8_t *additional_value, uint32_t additional_size)

Function Documentation

◆ ndn_hkdf()

int ndn_hkdf ( const uint8_t *  input_value,
uint32_t  input_size,
uint8_t *  output_value,
uint32_t  output_size,
const uint8_t *  seed_value,
uint32_t  seed_size 
)

Use HMAC-KDF (key derivation function) to generate a secure HMAC key.

This function requires proper entropy source.

Parameters
input_value.Input. Random input that requires KDF.
input_size.Input. Random input length in bytes.
output_value.Output. Buffer to receive output.
output_size.Input. Size of the output buffer.
seed_value.Input. Entropy to mix into the prng.
seed_size.Input. Entropy length in bytes.
Returns
NDN_SUCCESS if there is no error.

◆ ndn_hmac_get_backend()

ndn_hmac_backend_t* ndn_hmac_get_backend ( void  )

◆ ndn_hmac_get_key_size()

uint32_t ndn_hmac_get_key_size ( const ndn_hmac_key_t hmac_key)

Get hmac key size in unit of byte.

Parameters
hmac_key.Input. NDN hmac key.

◆ ndn_hmac_get_key_value()

const uint8_t* ndn_hmac_get_key_value ( const ndn_hmac_key_t hmac_key)

Get hmac key bytes.

Parameters
hmac_key.Input. NDN hmac key.

◆ ndn_hmac_key_init()

static int ndn_hmac_key_init ( ndn_hmac_key_t hmac_key,
const uint8_t *  key_value,
uint32_t  key_size,
uint32_t  key_id 
)
inlinestatic

Initialize a HMAC key.

Parameters
hmac_key.Input. The HMAC 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.
key_id.Input. The key id to be set with this key.
Returns
0 if there is no error.

◆ ndn_hmac_load_key()

int ndn_hmac_load_key ( ndn_hmac_key_t hmac_key,
const uint8_t *  key_value,
uint32_t  key_size 
)

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

Parameters
hmac_key.Output. NDN hmac key.
key_value.Input. Key bytes.
key_size.Input. The size of the key bytes.

◆ ndn_hmac_make_key()

int ndn_hmac_make_key ( ndn_hmac_key_t key,
uint32_t  key_id,
const uint8_t *  input_value,
uint32_t  input_size,
const uint8_t *  personalization,
uint32_t  personalization_size,
const uint8_t *  seed_value,
uint32_t  seed_size,
const uint8_t *  additional_value,
uint32_t  additional_size,
uint32_t  salt_size 
)

Generate a HMAC key with specific key size and key id.

This function requires proper entropy source.

Note
This function will invoke different imple depending on the backend.
Parameters
input_value.Input. Personalization string.
input_size.Input. Personalization length in bytes.
output_value.Output. Buffer to receive output.
output_size.Input. Size of the output buffer.
seed_value.Input. Entropy to mix into the prng.
seed_size.Input. Entropy length in bytes.
additional_value.Input. Additional input to the prng.
additional_size.Input. Additional input length in bytes.
Returns
NDN_SUCCESS if there is no error.

◆ ndn_hmac_sha256()

int ndn_hmac_sha256 ( const void *  payload,
uint32_t  payload_length,
const ndn_hmac_key_t hmac_key,
uint8_t *  hmac_result 
)

Generate HMAC using sha256 digest algorithm.

Note
This function will invoke different impl depending on the backend.

◆ ndn_hmac_sign()

int ndn_hmac_sign ( const uint8_t *  input_value,
uint32_t  input_size,
uint8_t *  output_value,
uint32_t  output_max_size,
const ndn_hmac_key_t hmac_key,
uint32_t *  output_used_size 
)

Sign a buffer using HMAC algorithm.

The memory buffer to hold the signature should not be smaller than 32 bytes.

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
key_value.Input. HMAC key.
key_size.Input. Size of HMAC key.
output_used_size.Output. Size of used output buffer when signing complete.
Returns
NDN_SUCCESS if there is no error.

◆ ndn_hmac_verify()

int ndn_hmac_verify ( const uint8_t *  input_value,
uint32_t  input_size,
const uint8_t *  sig_value,
uint32_t  sig_size,
const ndn_hmac_key_t hmac_key 
)

Verify a HMAC signature.

Parameters
input_value.Input. HMAC-signed buffer.
input_size.Input. Size of input buffer.
sig_value.Input. HMAC signature value.
sig_size.Input. HMAC signature size. Should be 32 bytes.
key_value.Input. HMAC key buffer.
key_size.Input. size of HMAC key.
Returns
NDN_SUCCESS if verification succeeded.

◆ ndn_hmacprng()

int ndn_hmacprng ( const uint8_t *  input_value,
uint32_t  input_size,
uint8_t *  output_value,
uint32_t  output_size,
const uint8_t *  seed_value,
uint32_t  seed_size,
const uint8_t *  additional_value,
uint32_t  additional_size 
)

Use HMAC-PRNG algorithm to generate pseudo-random bytes.

This function requires proper entropy source.

Parameters
input_value.Input. Personalization string.
input_size.Input. Personalization length in bytes.
output_value.Output. Buffer to receive output.
output_size.Input. Size of the output buffer.
seed_value.Input. Entropy to mix into the prng, highly recommend larger than 32 bytes.
seed_size.Input. Entropy length in bytes, highly recommend larger than 32 bytes.
additional_value.Input. Additional input to the prng
additional_size.Input. Additional input length in bytes
Returns
NDN_SUCCESS if there is no error.