ndn-lite
Macros | Functions | Variables
ndn-lite-hmac.c File Reference
#include "ndn-lite-hmac.h"
#include "ndn-lite-sec-utils.h"
#include "../ndn-constants.h"

Macros

#define NDN_SECURITY_AES_H_
 

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...
 
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 *hmac_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...
 

Variables

ndn_hmac_backend_t ndn_hmac_backend
 

Macro Definition Documentation

◆ NDN_SECURITY_AES_H_

#define NDN_SECURITY_AES_H_

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_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.

Variable Documentation

◆ ndn_hmac_backend