From 1e7ca7a0b7a3bea10aaa0804fad0878881d0881a Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Sat, 17 Jul 2010 16:02:30 +0000 Subject: [PATCH] Merge of IET r341: New md5/sha1 code in ietd didn't handle the byte swap properly for the digest counters on big endian systems. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@1835 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/md5.c | 5 +++-- iscsi-scst/usr/sha1.c | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/iscsi-scst/usr/md5.c b/iscsi-scst/usr/md5.c index d68acbef1..746eef545 100644 --- a/iscsi-scst/usr/md5.c +++ b/iscsi-scst/usr/md5.c @@ -179,13 +179,14 @@ void md5_final(struct md5_ctx *ctx, u8 *out) 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)); } diff --git a/iscsi-scst/usr/sha1.c b/iscsi-scst/usr/sha1.c index 79fd936f0..52771c459 100644 --- a/iscsi-scst/usr/sha1.c +++ b/iscsi-scst/usr/sha1.c @@ -144,14 +144,15 @@ void sha1_final(struct sha1_ctx *ctx, u8 *out) 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)); }