You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by gr...@apache.org on 2007/10/03 21:21:14 UTC

svn commit: r581697 - in /apr/apr-util/trunk: CHANGES crypto/apr_md5.c

Author: gregames
Date: Wed Oct  3 12:21:13 2007
New Revision: 581697

URL: http://svn.apache.org/viewvc?rev=581697&view=rev
Log:
make md5 hash files portable between EBCDIC and ASCII platforms.

submitter: David Jones
reviewers: Jeff Trawick, Martin Kraemer, Greg Ames


Modified:
    apr/apr-util/trunk/CHANGES
    apr/apr-util/trunk/crypto/apr_md5.c

Modified: apr/apr-util/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/CHANGES?rev=581697&r1=581696&r2=581697&view=diff
==============================================================================
--- apr/apr-util/trunk/CHANGES [utf-8] (original)
+++ apr/apr-util/trunk/CHANGES [utf-8] Wed Oct  3 12:21:13 2007
@@ -1,5 +1,8 @@
                                                      -*- coding: utf-8 -*-
 Changes with APR-util 1.3.0
+  
+  *) Make md5 hash files portable between EBCDIC and ASCII platforms  
+     [David Jones]
 
   *) Add limited apr_dbd_freetds driver (MSSQL and Sybase) [Nick Kew]
 

Modified: apr/apr-util/trunk/crypto/apr_md5.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/crypto/apr_md5.c?rev=581697&r1=581696&r2=581697&view=diff
==============================================================================
--- apr/apr-util/trunk/crypto/apr_md5.c (original)
+++ apr/apr-util/trunk/crypto/apr_md5.c Wed Oct  3 12:21:13 2007
@@ -112,6 +112,8 @@
 #if APR_CHARSET_EBCDIC
 static apr_xlate_t *xlate_ebcdic_to_ascii; /* used in apr_md5_encode() */
 #endif
+#define DO_XLATE 0
+#define SKIP_XLATE 1
 
 /* F, G, H and I are basic MD5 functions.
  */
@@ -195,9 +197,10 @@
  * operation, processing another message block, and updating the
  * context.
  */
-APU_DECLARE(apr_status_t) apr_md5_update(apr_md5_ctx_t *context,
-                                         const void *_input,
-                                         apr_size_t inputLen)
+static apr_status_t md5_update_buffer(apr_md5_ctx_t *context,
+                               const void *_input,
+                               apr_size_t inputLen,
+                               int xlate_buffer)
 {
     const unsigned char *input = _input;
     unsigned int i, idx, partLen;
@@ -234,7 +237,7 @@
     memcpy(&context->buffer[idx], &input[i], inputLen - i);
 #else /*APR_HAS_XLATE*/
     if (inputLen >= partLen) {
-        if (context->xlate) {
+        if (context->xlate && (xlate_buffer == DO_XLATE)) {
             inbytes_left = outbytes_left = partLen;
             apr_xlate_conv_buffer(context->xlate, (const char *)input, 
                                   &inbytes_left,
@@ -247,7 +250,7 @@
         MD5Transform(context->state, context->buffer);
 
         for (i = partLen; i + 63 < inputLen; i += 64) {
-            if (context->xlate) {
+            if (context->xlate && (xlate_buffer == DO_XLATE)) {
                 unsigned char inp_tmp[64];
                 inbytes_left = outbytes_left = 64;
                 apr_xlate_conv_buffer(context->xlate, (const char *)&input[i], 
@@ -266,7 +269,7 @@
         i = 0;
 
     /* Buffer remaining input */
-    if (context->xlate) {
+    if (context->xlate && (xlate_buffer == DO_XLATE)) {
         inbytes_left = outbytes_left = inputLen - i;
         apr_xlate_conv_buffer(context->xlate, (const char *)&input[i], 
                               &inbytes_left, (char *)&context->buffer[idx], 
@@ -279,6 +282,16 @@
     return APR_SUCCESS;
 }
 
+/* MD5 block update operation. API with the default setting 
+ * for EBCDIC translations
+ */  
+APU_DECLARE(apr_status_t) apr_md5_update(apr_md5_ctx_t *context,
+                                         const void *_input,
+                                         apr_size_t inputLen)
+{
+    md5_update_buffer( context, _input, inputLen, DO_XLATE);
+}
+
 /* MD5 finalization. Ends an MD5 message-digest operation, writing the
  * the message digest and zeroizing the context.
  */
@@ -553,13 +566,16 @@
      * Then just as many characters of the MD5(pw, salt, pw)
      */
     apr_md5_init(&ctx1);
+#if APR_CHARSET_EBCDIC
+    apr_md5_set_xlate(&ctx1, xlate_ebcdic_to_ascii);
+#endif
     apr_md5_update(&ctx1, pw, strlen(pw));
     apr_md5_update(&ctx1, sp, sl);
     apr_md5_update(&ctx1, pw, strlen(pw));
     apr_md5_final(final, &ctx1);
     for (pl = strlen(pw); pl > 0; pl -= APR_MD5_DIGESTSIZE) {
-        apr_md5_update(&ctx, final, 
-                      (pl > APR_MD5_DIGESTSIZE) ? APR_MD5_DIGESTSIZE : pl);
+        md5_update_buffer(&ctx, final,
+                      (pl > APR_MD5_DIGESTSIZE) ? APR_MD5_DIGESTSIZE : pl, SKIP_XLATE);
     }
 
     /*
@@ -572,7 +588,7 @@
      */
     for (i = strlen(pw); i != 0; i >>= 1) {
         if (i & 1) {
-            apr_md5_update(&ctx, final, 1);
+            md5_update_buffer(&ctx, final, 1, SKIP_XLATE);
         }
         else {
             apr_md5_update(&ctx, pw, 1);
@@ -596,11 +612,18 @@
      */
     for (i = 0; i < 1000; i++) {
         apr_md5_init(&ctx1);
+         /*
+          * apr_md5_final clears out ctx1.xlate at the end of each loop,
+          * so need to to set it each time through
+          */
+#if APR_CHARSET_EBCDIC
+        apr_md5_set_xlate(&ctx1, xlate_ebcdic_to_ascii);
+#endif
         if (i & 1) {
             apr_md5_update(&ctx1, pw, strlen(pw));
         }
         else {
-            apr_md5_update(&ctx1, final, APR_MD5_DIGESTSIZE);
+            md5_update_buffer(&ctx1, final, APR_MD5_DIGESTSIZE, SKIP_XLATE);
         }
         if (i % 3) {
             apr_md5_update(&ctx1, sp, sl);
@@ -611,7 +634,7 @@
         }
 
         if (i & 1) {
-            apr_md5_update(&ctx1, final, APR_MD5_DIGESTSIZE);
+            md5_update_buffer(&ctx1, final, APR_MD5_DIGESTSIZE, SKIP_XLATE);
         }
         else {
             apr_md5_update(&ctx1, pw, strlen(pw));



Re: svn commit: r581697 - in /apr/apr-util/trunk: CHANGES crypto/apr_md5.c

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Jeff Trawick wrote:
> On 10/3/07, gregames@apache.org <gr...@apache.org> wrote:
>> Author: gregames
>> Date: Wed Oct  3 12:21:13 2007
>> New Revision: 581697
>>
>> URL: http://svn.apache.org/viewvc?rev=581697&view=rev
>> Log:
>> make md5 hash files portable between EBCDIC and ASCII platforms.
> 
> any objections for putting this in the 1.2.x branch?

Do we consider that this changes the ABI contract between the user and
the implementation?  Does it invalidate all prior hash results?  If so
I can't quite see it going into 1.2 or into 1.x without some flag to
say we are doing 'portable' md5.

Bill

Re: svn commit: r581697 - in /apr/apr-util/trunk: CHANGES crypto/apr_md5.c

Posted by Jeff Trawick <tr...@gmail.com>.
On 10/3/07, gregames@apache.org <gr...@apache.org> wrote:
> Author: gregames
> Date: Wed Oct  3 12:21:13 2007
> New Revision: 581697
>
> URL: http://svn.apache.org/viewvc?rev=581697&view=rev
> Log:
> make md5 hash files portable between EBCDIC and ASCII platforms.

any objections for putting this in the 1.2.x branch?