[rng] Allow hash_df() to accept multiple underlying hash algorithms

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2012-03-05 16:13:07 +00:00
parent c8f52cccfb
commit fb6a33360f
5 changed files with 101 additions and 95 deletions

View File

@@ -454,7 +454,8 @@ int get_entropy_input_tmp ( unsigned int num_samples, uint8_t *tmp,
/* 5.4. tmp = tmp XOR
* df ( ( nonce || entropy_bitstring ), n )
*/
hash_df ( &data, sizeof ( data ), df_buf, sizeof ( df_buf ) );
hash_df ( &entropy_hash_df_algorithm, &data, sizeof ( data ),
df_buf, sizeof ( df_buf ) );
for ( i = 0 ; i < tmp_len ; i++ )
tmp[i] ^= df_buf[i];

View File

@@ -45,6 +45,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
/**
* Distribute entropy throughout a buffer
*
* @v hash Underlying hash algorithm
* @v input Input data
* @v input_len Length of input data, in bytes
* @v output Output buffer
@@ -63,10 +64,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
* There is no way for the Hash_df function to fail. The returned
* status SUCCESS is implicit.
*/
void hash_df ( const void *input, size_t input_len, void *output,
size_t output_len ) {
uint8_t context[HASH_DF_CTX_SIZE];
uint8_t digest[HASH_DF_OUTLEN_BYTES];
void hash_df ( struct digest_algorithm *hash, const void *input,
size_t input_len, void *output, size_t output_len ) {
uint8_t context[hash->ctxsize];
uint8_t digest[hash->digestsize];
size_t frag_len;
struct {
uint8_t pad[3];
@@ -106,12 +107,12 @@ void hash_df ( const void *input, size_t input_len, void *output,
* || input_string )
*/
prefix.no_of_bits_to_return = htonl ( output_len * 8 );
digest_init ( &hash_df_algorithm, context );
digest_update ( &hash_df_algorithm, context, &prefix.counter,
digest_init ( hash, context );
digest_update ( hash, context, &prefix.counter,
( sizeof ( prefix ) -
offsetof ( typeof ( prefix ), counter ) ) );
digest_update ( &hash_df_algorithm, context, input, input_len );
digest_final ( &hash_df_algorithm, context, digest );
digest_update ( hash, context, input, input_len );
digest_final ( hash, context, digest );
/* 4.2 counter = counter + 1 */
prefix.counter++;