Randomness#

DRBG#

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

API Reference#

#include "Hacl_HMAC_DRBG.h"

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.

Create a DRBG state.

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

Instantiate the DRBG.

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

Reseed the DRBG.

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

Generate output.

  • a Hash algorithm to use. (Value must match the value used in Hacl_HMAC_DRBG_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.

Warning

Cleanup and free the DRBG state.

Currently, there is no free function available. You can use …

void free_state(Hacl_HMAC_DRBG_state* state)
{
  KRML_HOST_FREE(state->k);
  KRML_HOST_FREE(state->reseed_counter);
  KRML_HOST_FREE(state->v);
}

… to cleanup the 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.

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

  • a Hash algorithm to use.