iPXE
|
HMAC_DRBG algorithm. More...
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <ipxe/crypto.h>
#include <ipxe/hmac.h>
#include <ipxe/hmac_drbg.h>
Go to the source code of this file.
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
static void | hmac_drbg_update_key (struct digest_algorithm *hash, struct hmac_drbg_state *state, const void *data, size_t len, const uint8_t single) |
Update the HMAC_DRBG key. More... | |
static void | hmac_drbg_update_value (struct digest_algorithm *hash, struct hmac_drbg_state *state) |
Update the HMAC_DRBG value. More... | |
static void | hmac_drbg_update (struct digest_algorithm *hash, struct hmac_drbg_state *state, const void *data, size_t len) |
Update HMAC_DRBG internal state. More... | |
void | hmac_drbg_instantiate (struct digest_algorithm *hash, struct hmac_drbg_state *state, const void *entropy, size_t entropy_len, const void *personal, size_t personal_len) |
Instantiate HMAC_DRBG. More... | |
void | hmac_drbg_reseed (struct digest_algorithm *hash, struct hmac_drbg_state *state, const void *entropy, size_t entropy_len, const void *additional, size_t additional_len) |
Reseed HMAC_DRBG. More... | |
int | hmac_drbg_generate (struct digest_algorithm *hash, struct hmac_drbg_state *state, const void *additional, size_t additional_len, void *data, size_t len) |
Generate pseudorandom bits using HMAC_DRBG. More... | |
HMAC_DRBG algorithm.
This algorithm is designed to comply with ANS X9.82 Part 3-2007 Section 10.2.2.2. This standard is not freely available, but most of the text appears to be shared with NIST SP 800-90, which can be downloaded from
http://csrc.nist.gov/publications/nistpubs/800-90/SP800-90revised_March2007.pdf
Where possible, references are given to both documents. In the case of any disagreement, ANS X9.82 takes priority over NIST SP 800-90. (In particular, note that some algorithms that are Approved by NIST SP 800-90 are not Approved by ANS X9.82.)
Definition in file hmac_drbg.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
static |
Update the HMAC_DRBG key.
hash | Underlying hash algorithm |
state | HMAC_DRBG internal state |
data | Provided data |
len | Length of provided data |
single | Single byte used in concatenation |
This function carries out the operation
K = HMAC ( K, V || single || provided_data )
as used by hmac_drbg_update()
Definition at line 78 of file hmac_drbg.c.
References assert(), data, DBGC, DBGC_HDA, hash, hmac_ctxsize(), hmac_final(), hmac_init(), hmac_update(), len, NULL, and state.
Referenced by hmac_drbg_update().
|
static |
Update the HMAC_DRBG value.
hash | Underlying hash algorithm |
state | HMAC_DRBG internal state |
data | Provided data |
len | Length of provided data |
single | Single byte used in concatenation |
This function carries out the operation
V = HMAC ( K, V )
as used by hmac_drbg_update() and hmac_drbg_generate()
Definition at line 121 of file hmac_drbg.c.
References assert(), DBGC, DBGC_HDA, hash, hmac_ctxsize(), hmac_final(), hmac_init(), hmac_update(), NULL, and state.
Referenced by hmac_drbg_generate(), and hmac_drbg_update().
|
static |
Update HMAC_DRBG internal state.
hash | Underlying hash algorithm |
state | HMAC_DRBG internal state |
data | Provided data |
len | Length of provided data |
This is the HMAC_DRBG_Update function defined in ANS X9.82 Part 3-2007 Section 10.2.2.2.2 (NIST SP 800-90 Section 10.1.2.2).
The key and value are updated in-place within the HMAC_DRBG internal state.
Definition at line 154 of file hmac_drbg.c.
References assert(), data, DBGC, hash, hmac_drbg_update_key(), hmac_drbg_update_value(), len, NULL, and state.
Referenced by hmac_drbg_generate(), and hmac_drbg_reseed().
void hmac_drbg_instantiate | ( | struct digest_algorithm * | hash, |
struct hmac_drbg_state * | state, | ||
const void * | entropy, | ||
size_t | entropy_len, | ||
const void * | personal, | ||
size_t | personal_len | ||
) |
Instantiate HMAC_DRBG.
hash | Underlying hash algorithm |
state | HMAC_DRBG internal state to be initialised |
entropy | Entropy input |
entropy_len | Length of entropy input |
personal | Personalisation string |
personal_len | Length of personalisation string |
This is the HMAC_DRBG_Instantiate_algorithm function defined in ANS X9.82 Part 3-2007 Section 10.2.2.2.3 (NIST SP 800-90 Section 10.1.2.3).
The nonce must be included within the entropy input (i.e. the entropy input must contain at least 3/2 * security_strength bits of entropy, as per ANS X9.82 Part 3-2007 Section 8.4.2 (NIST SP 800-90 Section 8.6.7).
The key, value and reseed counter are updated in-place within the HMAC_DRBG internal state.
Definition at line 206 of file hmac_drbg.c.
References assert(), DBGC, hash, hmac_drbg_reseed(), memset(), NULL, and state.
Referenced by drbg_instantiate_algorithm().
void hmac_drbg_reseed | ( | struct digest_algorithm * | hash, |
struct hmac_drbg_state * | state, | ||
const void * | entropy, | ||
size_t | entropy_len, | ||
const void * | additional, | ||
size_t | additional_len | ||
) |
Reseed HMAC_DRBG.
hash | Underlying hash algorithm |
state | HMAC_DRBG internal state |
entropy | Entropy input |
entropy_len | Length of entropy input |
additional | Additional input |
additional_len | Length of additional input |
This is the HMAC_DRBG_Reseed_algorithm function defined in ANS X9.82 Part 3-2007 Section 10.2.2.2.4 (NIST SP 800-90 Section 10.1.2.4).
The key, value and reseed counter are updated in-place within the HMAC_DRBG internal state.
Definition at line 255 of file hmac_drbg.c.
References additional, assert(), DBGC, DBGC_HDA, hash, hmac_drbg_update(), memcpy(), NULL, and state.
Referenced by drbg_reseed_algorithm(), and hmac_drbg_instantiate().
int hmac_drbg_generate | ( | struct digest_algorithm * | hash, |
struct hmac_drbg_state * | state, | ||
const void * | additional, | ||
size_t | additional_len, | ||
void * | data, | ||
size_t | len | ||
) |
Generate pseudorandom bits using HMAC_DRBG.
hash | Underlying hash algorithm |
state | HMAC_DRBG internal state |
additional | Additional input |
additional_len | Length of additional input |
data | Output buffer |
len | Length of output buffer |
rc | Return status code |
This is the HMAC_DRBG_Generate_algorithm function defined in ANS X9.82 Part 3-2007 Section 10.2.2.2.5 (NIST SP 800-90 Section 10.1.2.5).
Requests must be for an integral number of bytes.
The key, value and reseed counter are updated in-place within the HMAC_DRBG internal state.
Note that the only permitted error is "reseed required".
Definition at line 306 of file hmac_drbg.c.
References additional, assert(), data, DBGC, DBGC_HDA, ESTALE, hash, HMAC_DRBG_RESEED_INTERVAL, hmac_drbg_update(), hmac_drbg_update_value(), len, memcpy(), NULL, and state.
Referenced by drbg_generate_algorithm().