Randomness#

DRBG#

Deterministic Random Bit Generator (DRBG) (NIST, SP 800-90A).

Available Implementations#

#include "Hacl_HMAC_DRBG.h"

API Reference#

Example

// First, we initialize the DRBG by feeding it ...

// ... entropy ...
uint8_t entropy_input[123];
uint32_t entropy_input_len = 123;
generate_random(entropy_input, entropy_input_len);

// ... a nonce ...
uint8_t nonce[123];
uint32_t nonce_len = 123;
generate_random(nonce, nonce_len);

// ... and a personalization string.
const char* personalization_string = "HACL Packages Example";
uint32_t personalization_string_len = strlen(personalization_string);

Hacl_HMAC_DRBG_state state =
  Hacl_HMAC_DRBG_create_in(Spec_Hash_Definitions_SHA2_256);
Hacl_HMAC_DRBG_instantiate(Spec_Hash_Definitions_SHA2_256,
                           state,
                           entropy_input_len,
                           entropy_input,
                           nonce_len,
                           nonce,
                           personalization_string_len,
                           (uint8_t*)personalization_string);

// Then, we can generate output.
const char* additional_input = "";
uint32_t additional_input_len = 0;

uint8_t output[1337];
bool res = Hacl_HMAC_DRBG_generate(Spec_Hash_Definitions_SHA2_256,
                                   output,
                                   state,
                                   1337,
                                   additional_input_len,
                                   (uint8_t*)additional_input);

Hacl_HMAC_DRBG_free(Spec_Hash_Definitions_SHA2_256, state);

Variables#

uint32_t Hacl_HMAC_DRBG_reseed_interval#
uint32_t Hacl_HMAC_DRBG_max_output_length#
uint32_t Hacl_HMAC_DRBG_max_length#
uint32_t Hacl_HMAC_DRBG_max_personalization_string_length#
uint32_t Hacl_HMAC_DRBG_max_additional_input_length#

Typedefs#

typedef Spec_Hash_Definitions_hash_alg Hacl_HMAC_DRBG_supported_alg#
typedef struct Hacl_HMAC_DRBG_state_s Hacl_HMAC_DRBG_state#

Functions#

Hacl_HMAC_DRBG_state Hacl_HMAC_DRBG_create_in(Spec_Hash_Definitions_hash_alg a)#

Create a DRBG state.

Parameters

a – Hash algorithm to use. The possible instantiations are … Spec_Hash_Definitions_SHA2_256, Spec_Hash_Definitions_SHA2_384, Spec_Hash_Definitions_SHA2_512, and Spec_Hash_Definitions_SHA1.

void Hacl_HMAC_DRBG_instantiate(Spec_Hash_Definitions_hash_alg a, Hacl_HMAC_DRBG_state st, uint32_t entropy_input_len, uint8_t *entropy_input, uint32_t nonce_len, uint8_t *nonce, uint32_t personalization_string_len, uint8_t *personalization_string)#

Instantiate the DRBG.

Parameters
  • a – Hash algorithm to use. (Value must match the value used in Hacl_HMAC_DRBG_create_in.)

  • st – Pointer to DRBG state.

  • entropy_input_len – Length of entropy input.

  • entropy_input – Pointer to entropy_input_len bytes of memory where entropy input is read from.

  • nonce_len – Length of nonce.

  • nonce – Pointer to nonce_len bytes of memory where nonce is read from.

  • personalization_string_len – length of personalization string.

  • personalization_string – Pointer to personalization_string_len bytes of memory where personalization string is read from.

void Hacl_HMAC_DRBG_reseed(Spec_Hash_Definitions_hash_alg a, Hacl_HMAC_DRBG_state st, uint32_t entropy_input_len, uint8_t *entropy_input, uint32_t additional_input_input_len, uint8_t *additional_input_input)#

Reseed the DRBG.

Parameters
  • a – Hash algorithm to use. (Value must match the value used in Hacl_HMAC_DRBG_create_in.)

  • st – Pointer to DRBG state.

  • entropy_input_len – Length of entropy input.

  • entropy_input – Pointer to entropy_input_len bytes of memory where entropy input is read from.

  • additional_input_input_len – Length of additional input.

  • additional_input_input – Pointer to additional_input_input_len bytes of memory where additional input is read from.

bool Hacl_HMAC_DRBG_generate(Spec_Hash_Definitions_hash_alg a, uint8_t *output, Hacl_HMAC_DRBG_state st, uint32_t n, uint32_t additional_input_len, uint8_t *additional_input)#

Generate output.

Parameters
  • a – Hash algorithm to use. (Value must match the value used in create_in.)

  • output – Pointer to n bytes of memory where random output is written to.

  • st – Pointer to DRBG state.

  • n – Length of desired output.

  • additional_input_input_len – Length of additional input.

  • additional_input_input – Pointer to additional_input_input_len bytes of memory where additional input is read from.

void Hacl_HMAC_DRBG_free(Spec_Hash_Definitions_hash_alg uu___, Hacl_HMAC_DRBG_state s)#

Free the DRBG state.

uint32_t Hacl_HMAC_DRBG_min_length(Spec_Hash_Definitions_hash_alg a)#

Return the minimal entropy input length of the desired hash function.

Parameters

a – Hash algorithm to use.