Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Open
laiyonghao opened this Issue · 0 comments

1 participant

@laiyonghao

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 <root@li331-163.members.linode.com>
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
Something went wrong with that request. Please try again.