MPHELL  4.0.0
Functions | Variables
mphell-random.c File Reference

Definition of random functions. More...

#include "mphell-random.h"
Include dependency graph for mphell-random.c:

Go to the source code of this file.

Functions

void random_instantiate (mphell_status ret, random_state initial_state, const uint16_t requested_instantiation_security_strength, const uint8_t *personalization_string, const uint64_t pers_length, const random_type type, const entropy_type entropy, uint64_t reseed_interval)
 Instantiate one random state. More...
 
void random_reseed (mphell_status ret, random_state working_state, const uint16_t entropy_length, const entropy_type entropy_src, const uint8_t *additional_input, const uint64_t add_length)
 Reseed the DRBG (if you want to reseed it before it does by itself) More...
 
int RANDOM_INTEL_rdrand16_step (uint16_t *therand)
 
static void stm32f4_rng_error (mphell_status ret, uint8_t *data, const uint16_t length)
 If the user forget to write a correct function using the stm32f4 RNG to get random data, this one is used. More...
 
void random_generate (mphell_status ret, uint8_t *returned_bytes, random_state working_state, const uint32_t requested_number_of_bytes, const uint16_t requested_security_strength, const uint8_t *additional_input, const uint64_t add_length)
 Gererate an array of random bits. More...
 
void random_uninstantiate (mphell_status ret, random_state working_state)
 Uninstantiate a random state. More...
 

Variables

void(* stm32f4_rng )(mphell_status ret, uint8_t *data, const uint16_t length) = &stm32f4_rng_error
 This function pointer must be set in the stm32f4 application before calling init_mphell.
 

Detailed Description

Definition of random functions.

Definition in file mphell-random.c.

Function Documentation

◆ random_generate()

void random_generate ( mphell_status  ret,
uint8_t *  returned_bytes,
random_state  working_state,
const uint32_t  requested_number_of_bytes,
const uint16_t  requested_security_strength,
const uint8_t *  additionnal_input,
const uint64_t  add_length 
)

Gererate an array of random bits.

Parameters
retSet to MPHELL_ERROR_RANDOM if an error occur, MPHELL_SUCCESS otherwise
returned_bytesDestination array (of requested_number_of_bytes random bits)
working_stateDefine which DRBG state to use
requested_number_of_bytesNumber of random bits required
requested_security_strengthSecurity (in bits) required
additionnal_inputA string given by the user can be added to the material seed to reseed the DRBG
add_lengthLength of additional_input

Definition at line 367 of file mphell-random.c.

◆ random_instantiate()

void random_instantiate ( mphell_status  ret,
random_state  initial_state,
const uint16_t  requested_instantiation_security_strength,
const uint8_t *  personalization_string,
const uint64_t  pers_length,
const random_type  type,
const entropy_type  entropy,
uint64_t  reseed_interval 
)

Instantiate one random state.

Parameters
retSet to MPHELL_ERROR_RANDOM if an error occur, MPHELL_SUCCESS otherwise
initial_stateDestination structure, store the random algorithm and the number of the DRBG state used.
requested_instantiation_security_strengthSecurity (in bits) required
personalization_stringA string given by the user can be added to the material seed to instantiate the DRBG
pers_lengthLength of personalization_string
typeRandom algorithm to use (RANDOM_INTEL, RANDOM_AES128, RANDOM_AES192, RANDOM_AES256, RANDOM_SHA1, RANDOM_SHA256)
entropyEntropy to use (to seed the DRBG): INTEL, DEVURANDOM, DEVRANDOM
reseed_intervalReseed interval, must be between 1 (prediction resistance == true) and 2^48

Definition at line 29 of file mphell-random.c.

◆ random_reseed()

void random_reseed ( mphell_status  ret,
random_state  working_state,
const uint16_t  entropy_length,
const entropy_type  entropy_src,
const uint8_t *  additional_input,
const uint64_t  add_length 
)

Reseed the DRBG (if you want to reseed it before it does by itself)

Parameters
retSet to MPHELL_ERROR_RANDOM if an error occur, MPHELL_SUCCESS otherwise
working_stateDefine which DRBG state to use
entropy_lengthNumber of bits to extract from the entropy source
entropy_srcEntropy to use (to seed the DRBG): INTEL, DEVURANDOM, DEVRANDOM
additional_inputA string given by the user can be added to the material seed to reseed the DRBG
add_lengthLength of additional_input

Definition at line 226 of file mphell-random.c.

◆ random_uninstantiate()

void random_uninstantiate ( mphell_status  ret,
random_state  working_state 
)

Uninstantiate a random state.

Parameters
retSet to MPHELL_ERROR_RANDOM if an error occur, MPHELL_SUCCESS otherwise
working_stateRandom state to uninstantiate

Definition at line 427 of file mphell-random.c.

◆ stm32f4_rng_error()

stm32f4_rng_error ( mphell_status  ret,
uint8_t *  data,
const uint16_t  length 
)
static

If the user forget to write a correct function using the stm32f4 RNG to get random data, this one is used.

Parameters
retSet to MPHELL_ERROR_RANDOM
dataByte array to fill with random data
lengthLength of data

Definition at line 357 of file mphell-random.c.