From fb6a33360fd99b19f557a1721475da9d4dd6b05c Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 5 Mar 2012 16:13:07 +0000 Subject: [rng] Allow hash_df() to accept multiple underlying hash algorithms Signed-off-by: Michael Brown --- src/crypto/entropy.c | 3 ++- src/crypto/hash_df.c | 17 +++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'src/crypto') diff --git a/src/crypto/entropy.c b/src/crypto/entropy.c index ab574a94c..cb3d54d8f 100644 --- a/src/crypto/entropy.c +++ b/src/crypto/entropy.c @@ -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]; diff --git a/src/crypto/hash_df.c b/src/crypto/hash_df.c index 1074f8ca6..250c2ffc8 100644 --- a/src/crypto/hash_df.c +++ b/src/crypto/hash_df.c @@ -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++; -- cgit v1.2.3-55-g7522