diff options
author | Michael Brown | 2006-11-21 14:26:59 +0100 |
---|---|---|
committer | Michael Brown | 2006-11-21 14:26:59 +0100 |
commit | c5428303e4d71856daf61fc27ae19aeca09cc834 (patch) | |
tree | e69327bec2619d9a608967071e68eaaba5ee6891 /src/crypto/md5.c | |
parent | Made it temporarily possible to call MD5 routines directly from external (diff) | |
download | ipxe-c5428303e4d71856daf61fc27ae19aeca09cc834.tar.gz ipxe-c5428303e4d71856daf61fc27ae19aeca09cc834.tar.xz ipxe-c5428303e4d71856daf61fc27ae19aeca09cc834.zip |
Added generic CHAP layer, independent of iSCSI
Diffstat (limited to 'src/crypto/md5.c')
-rw-r--r-- | src/crypto/md5.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/crypto/md5.c b/src/crypto/md5.c index ed062054..2aa21020 100644 --- a/src/crypto/md5.c +++ b/src/crypto/md5.c @@ -26,6 +26,16 @@ #include <gpxe/crypto.h> #include <gpxe/md5.h> +#define MD5_DIGEST_SIZE 16 +#define MD5_BLOCK_WORDS 16 +#define MD5_HASH_WORDS 4 + +struct md5_ctx { + u32 hash[MD5_HASH_WORDS]; + u32 block[MD5_BLOCK_WORDS]; + u64 byte_count; +}; + #define __md5step __attribute__ (( regparm ( 3 ) )) struct md5_step { @@ -150,15 +160,16 @@ static inline void cpu_to_le32_array(u32 *buf, unsigned int words) } } -static inline void md5_transform_helper(struct md5_context *ctx) +static inline void md5_transform_helper(struct md5_ctx *ctx) { le32_to_cpu_array(ctx->block, sizeof(ctx->block) / sizeof(u32)); md5_transform(ctx->hash, ctx->block); } -void md5_init ( struct md5_context *context ) +static void md5_init(void *context) { - struct md5_context *mctx = context; + struct md5_ctx *mctx = context; + mctx->hash[0] = 0x67452301; mctx->hash[1] = 0xefcdab89; mctx->hash[2] = 0x98badcfe; @@ -166,9 +177,9 @@ void md5_init ( struct md5_context *context ) mctx->byte_count = 0; } -void md5_update ( struct md5_context *context, const void *data, size_t len ) +static void md5_update(void *context, const void *data, size_t len) { - struct md5_context *mctx = context; + struct md5_ctx *mctx = context; const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); mctx->byte_count += len; @@ -196,9 +207,9 @@ void md5_update ( struct md5_context *context, const void *data, size_t len ) memcpy(mctx->block, data, len); } -void md5_finish ( struct md5_context *context, struct md5_hash *out ) +static void md5_finish(void *context, void *out) { - struct md5_context *mctx = context; + struct md5_ctx *mctx = context; const unsigned int offset = mctx->byte_count & 0x3f; char *p = (char *)mctx->block + offset; int padding = 56 - (offset + 1); @@ -222,12 +233,10 @@ void md5_finish ( struct md5_context *context, struct md5_hash *out ) memset(mctx, 0, sizeof(*mctx)); } -/* struct digest_algorithm md5_algorithm = { - .context_len = sizeof ( struct md5_context ), + .context_len = sizeof ( struct md5_ctx ), .digest_len = MD5_DIGEST_SIZE, .init = md5_init, .update = md5_update, .finish = md5_finish, }; -*/ |