Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MD5.digest.endian should be LITTLE_ENDIAN(patch included) #177

Open
laiyonghao opened this issue Sep 25, 2011 · 0 comments
Open

MD5.digest.endian should be LITTLE_ENDIAN(patch included) #177

laiyonghao opened this issue Sep 25, 2011 · 0 comments

Comments

@laiyonghao
Copy link

MD5.digest.endian is a ByteArray object, and it's default endian is BIG_ENDIAN.
according to the RFC1321 "APPENDIX A - Reference Implementation"(http://www.faqs.org/rfcs/rfc1321.html), it should be LITTLE_ENDIAN.

static void Encode (output, input, len)
unsigned char *output;
UINT4 *input;
unsigned int len;
{
  unsigned int i, j;

  for (i = 0, j = 0; j < len; i++, j += 4) {
 output[j] = (unsigned char)(input[i] & 0xff);
 output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
 output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
 output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
  }
}

and i found wikipedia page(http://en.wikipedia.org/wiki/Md5)

var char digest[16] := h0 append h1 append h2 append h3 //(expressed as little-endian)

i created a patch to fix this bug, and pasted below.

From 86ac4e1a516e2213d9c781c34be0de59523d515a Mon Sep 17 00:00:00 2001
From: root <[email protected]>
Date: Sun, 25 Sep 2011 05:44:03 -0400
Subject: [PATCH] MD5.digest.endian should be LITTLE_ENDIAN.

---
 src/com/adobe/crypto/MD5.as |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/com/adobe/crypto/MD5.as b/src/com/adobe/crypto/MD5.as
index da533cc..db5406a 100644
--- a/src/com/adobe/crypto/MD5.as
+++ b/src/com/adobe/crypto/MD5.as
@@ -34,6 +34,7 @@ package com.adobe.crypto {

        import com.adobe.utils.IntUtil;
        import flash.utils.ByteArray;
+       import flash.utils.Endian;
        /**
         * The MD5 Message-Digest Algorithm
         *
@@ -178,7 +179,8 @@ package com.adobe.crypto {
                                c += cc;
                                d += dd;
                        }
-                       digest = new ByteArray()
+                       digest = new ByteArray();
+                       digest.endian = Endian.LITTLE_ENDIAN;
                        digest.writeInt(a);
                        digest.writeInt(b);
                        digest.writeInt(c);
-- 
1.7.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant