[crypto] Use private data field for digest algorithms

Following the example of commit 25072c1 ("[crypto] Use private data
field for key exchange algorithms"), extend the definition of a digest
algorithm to include an opaque private data field.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2026-06-18 15:54:19 +01:00
parent 69e95ae7a5
commit d7e89f46b4
14 changed files with 161 additions and 198 deletions
+10 -5
View File
@@ -121,9 +121,10 @@ static struct md4_step md4_steps[4] = {
/**
* Initialise MD4 algorithm
*
* @v digest Digest algorithm
* @v ctx MD4 context
*/
static void md4_init ( void *ctx ) {
static void md4_init ( struct digest_algorithm *digest __unused, void *ctx ) {
struct md4_context *context = ctx;
context->ddd.dd.digest.h[0] = cpu_to_le32 ( 0x67452301 );
@@ -206,11 +207,13 @@ static void md4_digest ( struct md4_context *context ) {
/**
* Accumulate data with MD4 algorithm
*
* @v digest Digest algorithm
* @v ctx MD4 context
* @v data Data
* @v len Length of data
*/
static void md4_update ( void *ctx, const void *data, size_t len ) {
static void md4_update ( struct digest_algorithm *digest __unused, void *ctx,
const void *data, size_t len ) {
struct md4_context *context = ctx;
const uint8_t *byte = data;
size_t offset;
@@ -230,10 +233,12 @@ static void md4_update ( void *ctx, const void *data, size_t len ) {
/**
* Generate MD4 digest
*
* @v digest Digest algorithm
* @v ctx MD4 context
* @v out Output buffer
*/
static void md4_final ( void *ctx, void *out ) {
static void md4_final ( struct digest_algorithm *digest, void *ctx,
void *out ) {
struct md4_context *context = ctx;
uint64_t len_bits;
uint8_t pad;
@@ -244,13 +249,13 @@ static void md4_final ( void *ctx, void *out ) {
/* Pad with a single "1" bit followed by as many "0" bits as required */
pad = 0x80;
do {
md4_update ( ctx, &pad, sizeof ( pad ) );
md4_update ( digest, ctx, &pad, sizeof ( pad ) );
pad = 0x00;
} while ( ( context->len % sizeof ( context->ddd.dd.data ) ) !=
offsetof ( typeof ( context->ddd.dd.data ), final.len ) );
/* Append length (in bits) */
md4_update ( ctx, &len_bits, sizeof ( len_bits ) );
md4_update ( digest, ctx, &len_bits, sizeof ( len_bits ) );
assert ( ( context->len % sizeof ( context->ddd.dd.data ) ) == 0 );
/* Copy out final digest */