mirror of
https://github.com/ipxe/ipxe
synced 2026-07-04 20:01:38 +03:00
[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:
+10
-5
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user