|
From: Ross S. W. W. <RW...@me...> - 2010-06-29 21:13:13
|
New md5/sha1 code in ietd didn't handle the byte swap properly for the digest counters on big endian systems. Tested on PPC by Harshal Shete Signed-off-by: Ross Walker Index: usr/md5.c =================================================================== --- usr/md5.c (revision 339) +++ usr/md5.c (working copy) @@ -179,13 +179,14 @@ void md5_final(struct md5_ctx *ctx, u8 * memset(p, 0, padding); /* 64-bit bit counter stored in LSW/LSB format */ - ctx->block[14] = ctx->count << 3; - ctx->block[15] = ctx->count >> 29; + ctx->block[14] = cpu_to_le32(ctx->count << 3); + ctx->block[15] = cpu_to_le32(ctx->count >> 29); md5_transform(ctx->digest, ctx->block); for (i = 0; i < MD5_DIGEST_WORDS; i++) ctx->digest[i] = le32_to_cpu(ctx->digest[i]); + memcpy(out, ctx->digest, MD5_DIGEST_BYTES); memset(ctx, 0, sizeof(*ctx)); } Index: usr/sha1.c =================================================================== --- usr/sha1.c (revision 339) +++ usr/sha1.c (working copy) @@ -144,14 +144,15 @@ void sha1_final(struct sha1_ctx *ctx, u8 memset(p, 0, padding); - /* 64-bit bit counter stored in MSW/LSB format (RFC bug?) */ - ctx->block[14] = bswap_32(ctx->count >> 29); - ctx->block[15] = bswap_32(ctx->count << 3); + /* 64-bit bit counter stored in MSW/MSB format */ + ctx->block[14] = cpu_to_be32(ctx->count >> 29); + ctx->block[15] = cpu_to_be32(ctx->count << 3); sha1_transform(ctx->digest, ctx->block); for (i = 0; i < SHA1_DIGEST_WORDS; i++) ctx->digest[i] = be32_to_cpu(ctx->digest[i]); + memcpy(out, ctx->digest, SHA1_DIGEST_BYTES); memset(ctx, 0, sizeof(*ctx)); } ______________________________________________________________________ This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender and permanently delete the original and any copy or printout thereof. |