ndn-lite
Functions | Variables
tc_hmac_prng.c File Reference
#include "tc_hmac_prng.h"
#include "tc_hmac.h"
#include "tc_constants.h"
#include "tc_utils.h"

Functions

static void update (TCHmacPrng_t prng, const uint8_t *e, unsigned int len)
 
int tc_hmac_prng_init (TCHmacPrng_t prng, const uint8_t *personalization, unsigned int plen)
 HMAC-PRNG initialization procedure Initializes prng with personalization, disables tc_hmac_prng_generate. More...
 
int tc_hmac_prng_reseed (TCHmacPrng_t prng, const uint8_t *seed, unsigned int seedlen, const uint8_t *additional_input, unsigned int additionallen)
 HMAC-PRNG reseed procedure Mixes seed into prng, enables tc_hmac_prng_generate. More...
 
int tc_hmac_prng_generate (uint8_t *out, unsigned int outlen, TCHmacPrng_t prng)
 HMAC-PRNG generate procedure Generates outlen pseudo-random bytes into out buffer, updates prng. More...
 

Variables

static const unsigned int MIN_SLEN = 32
 
static const unsigned int MAX_SLEN = UINT32_MAX
 
static const unsigned int MAX_PLEN = UINT32_MAX
 
static const unsigned int MAX_ALEN = UINT32_MAX
 
static const unsigned int MAX_GENS = UINT32_MAX
 
static const unsigned int MAX_OUT = (1 << 19)
 

Function Documentation

◆ tc_hmac_prng_generate()

int tc_hmac_prng_generate ( uint8_t *  out,
unsigned int  outlen,
TCHmacPrng_t  prng 
)

HMAC-PRNG generate procedure Generates outlen pseudo-random bytes into out buffer, updates prng.

Returns
returns TC_CRYPTO_SUCCESS (1) returns TC_HMAC_PRNG_RESEED_REQ (-1) if a reseed is needed returns TC_CRYPTO_FAIL (0) if: out == NULL, prng == NULL, outlen == 0, outlen >= MAX_OUT
Note
Assumes tc_hmac_prng_init has been called for prng
Parameters
outIN/OUT – buffer to receive output
outlenIN – size of out buffer in bytes
prngIN/OUT – the PRNG state

◆ tc_hmac_prng_init()

int tc_hmac_prng_init ( TCHmacPrng_t  prng,
const uint8_t *  personalization,
unsigned int  plen 
)

HMAC-PRNG initialization procedure Initializes prng with personalization, disables tc_hmac_prng_generate.

Returns
returns TC_CRYPTO_SUCCESS (1) returns TC_CRYPTO_FAIL (0) if: prng == NULL, personalization == NULL, plen > MAX_PLEN
Note
Assumes: - personalization != NULL. The personalization is a platform unique string (e.g., the host name) and is the last line of defense against failure of the entropy source
Warning
NIST SP 800-90A specifies 3 items as seed material during initialization: entropy seed, personalization, and an optional nonce. TinyCrypts requires instead a non-null personalization (which is easily computed) and indirectly requires an entropy seed (since the reseed function is mandatorily called after init)
Parameters
prngIN/OUT – the PRNG state to initialize
personalizationIN – personalization string
plenIN – personalization length in bytes

◆ tc_hmac_prng_reseed()

int tc_hmac_prng_reseed ( TCHmacPrng_t  prng,
const uint8_t *  seed,
unsigned int  seedlen,
const uint8_t *  additional_input,
unsigned int  additionallen 
)

HMAC-PRNG reseed procedure Mixes seed into prng, enables tc_hmac_prng_generate.

Returns
returns TC_CRYPTO_SUCCESS (1) returns TC_CRYPTO_FAIL (0) if: prng == NULL, seed == NULL, seedlen < MIN_SLEN, seendlen > MAX_SLEN, additional_input != (const uint8_t *) 0 && additionallen == 0, additional_input != (const uint8_t *) 0 && additionallen > MAX_ALEN
Note
Assumes:- tc_hmac_prng_init has been called for prng
  • seed has sufficient entropy.
Parameters
prngIN/OUT – the PRNG state
seedIN – entropy to mix into the prng
seedlenIN – length of seed in bytes
additional_inputIN – additional input to the prng
additionallenIN – additional input length in bytes

◆ update()

static void update ( TCHmacPrng_t  prng,
const uint8_t *  e,
unsigned int  len 
)
static

Variable Documentation

◆ MAX_ALEN

const unsigned int MAX_ALEN = UINT32_MAX
static

◆ MAX_GENS

const unsigned int MAX_GENS = UINT32_MAX
static

◆ MAX_OUT

const unsigned int MAX_OUT = (1 << 19)
static

◆ MAX_PLEN

const unsigned int MAX_PLEN = UINT32_MAX
static

◆ MAX_SLEN

const unsigned int MAX_SLEN = UINT32_MAX
static

◆ MIN_SLEN

const unsigned int MIN_SLEN = 32
static