ndn-lite
Functions
tc_ctr_prng.c File Reference
#include "tc_ctr_prng.h"
#include "tc_utils.h"
#include "tc_constants.h"
#include <string.h>

Functions

static void arrInc (uint8_t arr[], unsigned int len)
 Array incrementer Treats the supplied array as one contiguous number (MSB in arr[0]), and increments it by one. More...
 
static void tc_ctr_prng_update (TCCtrPrng_t *const ctx, uint8_t const *const providedData)
 CTR PRNG update Updates the internal state of supplied the CTR PRNG context increments it by one. More...
 
int tc_ctr_prng_init (TCCtrPrng_t *const ctx, uint8_t const *const entropy, unsigned int entropyLen, uint8_t const *const personalization, unsigned int pLen)
 CTR-PRNG initialization procedure Initializes prng context with entropy and personalization string (if any) More...
 
int tc_ctr_prng_reseed (TCCtrPrng_t *const ctx, uint8_t const *const entropy, unsigned int entropyLen, uint8_t const *const additional_input, unsigned int additionallen)
 CTR-PRNG reseed procedure Mixes entropy and additional_input into the prng context. More...
 
int tc_ctr_prng_generate (TCCtrPrng_t *const ctx, uint8_t const *const additional_input, unsigned int additionallen, uint8_t *const out, unsigned int outlen)
 CTR-PRNG generate procedure Generates outlen pseudo-random bytes into out buffer, updates prng. More...
 
void tc_ctr_prng_uninstantiate (TCCtrPrng_t *const ctx)
 CTR-PRNG uninstantiate procedure Zeroes the internal state of the supplied prng context. More...
 

Function Documentation

◆ arrInc()

static void arrInc ( uint8_t  arr[],
unsigned int  len 
)
static

Array incrementer Treats the supplied array as one contiguous number (MSB in arr[0]), and increments it by one.

Returns
none
Parameters
arrIN/OUT – array to be incremented
lenIN – size of arr in bytes

◆ tc_ctr_prng_generate()

int tc_ctr_prng_generate ( TCCtrPrng_t *const  ctx,
uint8_t const *const  additional_input,
unsigned int  additionallen,
uint8_t *const  out,
unsigned int  outlen 
)

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

Returns
returns TC_CRYPTO_SUCCESS (1) returns TC_CTR_PRNG_RESEED_REQ (-1) if a reseed is needed returns TC_CRYPTO_FAIL (0) if: ctx == NULL, out == NULL, outlen >= 2^16
Note
Assumes tc_ctr_prng_init has been called for ctx
Parameters
ctxIN/OUT – the PRNG context
additional_inputIN – additional input to the prng (may be null)
additionallenIN – additional input length in bytes
outIN/OUT – buffer to receive output
outlenIN – size of out buffer in bytes

◆ tc_ctr_prng_init()

int tc_ctr_prng_init ( TCCtrPrng_t *const  ctx,
uint8_t const *const  entropy,
unsigned int  entropyLen,
uint8_t const *const  personalization,
unsigned int  pLen 
)

CTR-PRNG initialization procedure Initializes prng context with entropy and personalization string (if any)

Returns
returns TC_CRYPTO_SUCCESS (1) returns TC_CRYPTO_FAIL (0) if: ctx == NULL, entropy == NULL, entropyLen < (TC_AES_KEY_SIZE + TC_AES_BLOCK_SIZE)
Note
Only the first (TC_AES_KEY_SIZE + TC_AES_BLOCK_SIZE) bytes of both the entropy and personalization inputs are used - supplying additional bytes has no effect.
Parameters
ctxIN/OUT – the PRNG context to initialize
entropyIN – entropy used to seed the PRNG
entropyLenIN – entropy length in bytes
personalizationIN – personalization string used to seed the PRNG (may be null)
plenIN – personalization length in bytes

◆ tc_ctr_prng_reseed()

int tc_ctr_prng_reseed ( TCCtrPrng_t *const  ctx,
uint8_t const *const  entropy,
unsigned int  entropyLen,
uint8_t const *const  additional_input,
unsigned int  additionallen 
)

CTR-PRNG reseed procedure Mixes entropy and additional_input into the prng context.

Returns
returns TC_CRYPTO_SUCCESS (1) returns TC_CRYPTO_FAIL (0) if: ctx == NULL, entropy == NULL, entropylen < (TC_AES_KEY_SIZE + TC_AES_BLOCK_SIZE)
Note
It is better to reseed an existing prng context rather than re-initialise, so that any existing entropy in the context is presereved. This offers some protection against undetected failures of the entropy source.
Assumes tc_ctr_prng_init has been called for ctx
Parameters
ctxIN/OUT – the PRNG state
entropyIN – entropy to mix into the prng
entropylenIN – length of entropy in bytes
additional_inputIN – additional input to the prng (may be null)
additionallenIN – additional input length in bytes

◆ tc_ctr_prng_uninstantiate()

void tc_ctr_prng_uninstantiate ( TCCtrPrng_t *const  ctx)

CTR-PRNG uninstantiate procedure Zeroes the internal state of the supplied prng context.

Returns
none
Parameters
ctxIN/OUT – the PRNG context

◆ tc_ctr_prng_update()

static void tc_ctr_prng_update ( TCCtrPrng_t *const  ctx,
uint8_t const *const  providedData 
)
static

CTR PRNG update Updates the internal state of supplied the CTR PRNG context increments it by one.

Returns
none
Note
Assumes: providedData is (TC_AES_KEY_SIZE + TC_AES_BLOCK_SIZE) bytes long
Parameters
ctxIN/OUT – CTR PRNG state
providedDataIN – data used when updating the internal state