Hash_DRBG

This is Hash_DRBG from SP800-90A rev 1, with SHA256 as the underlying hash function.

This generator enforces a reseed_interval of 2^32-1: use cf_hash_drbg_sha256_needs_reseed() to check whether you need to reseed before use, and reseed using cf_hash_drbg_sha256_reseed(). If you try to use the generator when it thinks it needs reseeding, it will call abort.

Internally it enforces a max_number_of_bits_per_request of 2^19 bits. It sorts out chunking up multiple requests for you though, so feel free to ask for more than 2^16 bytes at a time. If you provide additional input when doing that, it is added only once, on the first subrequest.

It does not enforce any max_length or max_personalization_string_length.

Types

cf_hash_drbg_sha256

Hash_DRBG with SHA256 context.

cf_hash_drbg_sha256.V

Current internal state.

cf_hash_drbg_sha256.C

Current update offset.

cf_hash_drbg_sha256.reseed_counter

Current number of times entropy has been extracted from generator.

Functions

void cf_hash_drbg_sha256_init(cf_hash_drbg_sha256 *ctx, const void *entropy, size_t nentropy, const void *nonce, size_t nnonce, const void *persn, size_t npersn)

Initialises the generator state ctx, using the provided entropy, nonce and personalisation string persn.

uint32_t cf_hash_drbg_sha256_needs_reseed(const cf_hash_drbg_sha256 *ctx)

Returns non-zero if the generator needs reseeding. If this function returns non-zero, the next cf_hash_drbg_sha256_gen() or cf_hash_drbg_sha256_gen_additional() call will call abort.

void cf_hash_drbg_sha256_reseed(cf_hash_drbg_sha256 *ctx, const void *entropy, size_t nentropy, const void *addnl, size_t naddnl)

Reseeds the generator with the given entropy and additional data addnl.

void cf_hash_drbg_sha256_gen(cf_hash_drbg_sha256 *ctx, void *out, size_t nout)

Generates pseudo-random output, writing nout bytes at out. This function aborts if the generator needs seeding.

void cf_hash_drbg_sha256_gen_additional(cf_hash_drbg_sha256 *ctx, const void *addnl, size_t naddnl, void *out, size_t nout)

Generates pseudo-random output, writing nout bytes at out. At the same time, addnl is input to the generator as further entropy. This function aborts if the generator needs seeding.

HMAC_DRBG

This is HMAC_DRBG from SP800-90a r1 with any hash function.

This generator enforces a reseed_interval of 2^32-1: use cf_hmac_drbg_needs_reseed() to check whether you need to reseed before use, and reseed using cf_hmac_drbg_reseed(). If you try to use the generator when it thinks it needs reseeding, it will call abort.

Internally it enforces a max_number_of_bits_per_request of 2^19 bits. It sorts out chunking up multiple requests for you though, so feel free to ask for more than 2^16 bytes at a time. If you provide additional input when doing that, it is added only once, on the first subrequest.

It does not enforce any max_length or max_personalization_string_length.

Types

cf_hmac_drbg

HMAC_DRBG context.

cf_hmac_drbg.V

Current internal state.

cf_hmac_drbg.hmac

Current HMAC context, with key scheduled in it.

cf_hmac_drbg.reseed_counter

Current number of times entropy has been extracted from generator.

Functions

void cf_hmac_drbg_init(cf_hmac_drbg *ctx, const cf_chash *hash, const void *entropy, size_t nentropy, const void *nonce, size_t nnonce, const void *persn, size_t npersn)

Initialises the generator state ctx, using the provided entropy, nonce and personalisation string persn.

uint32_t cf_hmac_drbg_needs_reseed(const cf_hmac_drbg *ctx)

Returns non-zero if the generator needs reseeding. If this function returns non-zero, the next cf_hmac_drbg_gen() or cf_hmac_drbg_gen_additional() call will call abort.

void cf_hmac_drbg_reseed(cf_hmac_drbg *ctx, const void *entropy, size_t nentropy, const void *addnl, size_t naddnl)

Reseeds the generator with the given entropy and additional data addnl.

void cf_hmac_drbg_gen(cf_hmac_drbg *ctx, void *out, size_t nout)

Generates pseudo-random output, writing nout bytes at out. This function aborts if the generator needs seeding.

void cf_hmac_drbg_gen_additional(cf_hmac_drbg *ctx, const void *addnl, size_t naddnl, void *out, size_t nout)

Generates pseudo-random output, writing nout bytes at out. At the same time, addnl is input to the generator as further entropy. This function aborts if the generator needs seeding.