summaryrefslogtreecommitdiffstats
path: root/src/crypto/hash_df.c
diff options
context:
space:
mode:
authorMichael Brown2012-03-05 17:13:07 +0100
committerMichael Brown2012-03-06 00:23:45 +0100
commitfb6a33360fd99b19f557a1721475da9d4dd6b05c (patch)
tree13f60dd57b2c69da5220d095e9575b2466fd6b9c /src/crypto/hash_df.c
parent[tls] Formalise the definition of a TLS cipher suite (diff)
downloadipxe-fb6a33360fd99b19f557a1721475da9d4dd6b05c.tar.gz
ipxe-fb6a33360fd99b19f557a1721475da9d4dd6b05c.tar.xz
ipxe-fb6a33360fd99b19f557a1721475da9d4dd6b05c.zip
[rng] Allow hash_df() to accept multiple underlying hash algorithms
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/crypto/hash_df.c')
-rw-r--r--src/crypto/hash_df.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/crypto/hash_df.c b/src/crypto/hash_df.c
index 1074f8ca..250c2ffc 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++;