apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1460244 - in /apr/apr/trunk: CHANGES crypto/apr_md5.c test/testmd5.c
Date Sat, 23 Mar 2013 23:18:49 GMT
Author: sf
Date: Sat Mar 23 23:18:49 2013
New Revision: 1460244

URL: http://svn.apache.org/r1460244
Log:
speed-up md5 by avoiding some memcopies
    
PR: 49011
Submitted by: Stefan Fritsch, Stefan Fuhrmann <stefanfuhrmann alice-dsl de>

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/crypto/apr_md5.c
    apr/apr/trunk/test/testmd5.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1460244&r1=1460243&r2=1460244&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Sat Mar 23 23:18:49 2013
@@ -1,6 +1,10 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) Speedup md5 calculation by avoiding some copying on little endian
+     architectures. PR 49011. [Stefan Fritsch, Stefan Fuhrmann
+     <stefanfuhrmann alice-dsl de>]
+
   *) Fix pool integrity checks with threads. Add new apr_pool_owner_set()
      function. PR 43375, 52785. [Stefan Fritsch]
 

Modified: apr/apr/trunk/crypto/apr_md5.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/crypto/apr_md5.c?rev=1460244&r1=1460243&r2=1460244&view=diff
==============================================================================
--- apr/apr/trunk/crypto/apr_md5.c (original)
+++ apr/apr/trunk/crypto/apr_md5.c Sat Mar 23 23:18:49 2013
@@ -338,9 +338,18 @@ APR_DECLARE(apr_status_t) apr_md5(unsign
 static void MD5Transform(apr_uint32_t state[4], const unsigned char block[64])
 {
     apr_uint32_t a = state[0], b = state[1], c = state[2], d = state[3],
-                 x[APR_MD5_DIGESTSIZE];
+                 tmpbuf[APR_MD5_DIGESTSIZE];
+    const apr_uint32_t *x;
 
-    Decode(x, block, 64);
+#if !APR_IS_BIGENDIAN
+    if ((apr_uintptr_t)block % sizeof(apr_uint32_t) == 0) {
+        x = (apr_uint32_t *)block;
+    } else
+#endif
+    {
+        Decode(tmpbuf, block, 64);
+	x = tmpbuf;
+    }
 
     /* Round 1 */
     FF(a, b, c, d, x[0],  S11, 0xd76aa478); /* 1 */
@@ -419,8 +428,13 @@ static void MD5Transform(apr_uint32_t st
     state[2] += c;
     state[3] += d;
 
-    /* Zeroize sensitive information. */
-    memset(x, 0, sizeof(x));
+#if !APR_IS_BIGENDIAN
+    if (x == tmpbuf)
+#endif
+    {
+        /* Zeroize sensitive information. */
+        memset(tmpbuf, 0, sizeof(tmpbuf));
+    }
 }
 
 /* Encodes input (apr_uint32_t) into output (unsigned char). Assumes len is

Modified: apr/apr/trunk/test/testmd5.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testmd5.c?rev=1460244&r1=1460243&r2=1460244&view=diff
==============================================================================
--- apr/apr/trunk/test/testmd5.c (original)
+++ apr/apr/trunk/test/testmd5.c Sat Mar 23 23:18:49 2013
@@ -66,6 +66,30 @@ static void test_md5sum(abts_case *tc, v
                     (memcmp(digest, sum, APR_MD5_DIGESTSIZE) == 0));
 }
 
+static void test_md5sum_unaligned(abts_case *tc, void *data)
+{
+        apr_md5_ctx_t context;
+        const char *string = "abcdefghijklmnopqrstuvwxyz01234"
+                             "abcdefghijklmnopqrstuvwxyz01234"
+                             "abcdefghijklmnopqrstuvwxyz01234"
+                             "abcdefghijklmnopqrstuvwxyz01234_";
+        const char *sum =
+            "\x93\x17\x22\x78\xee\x30\x82\xb3\xeb\x95\x33\xec\xea\x78\xb7\x89";
+        unsigned char digest[APR_MD5_DIGESTSIZE];
+        unsigned int i;
+
+        ABTS_ASSERT(tc, "apr_md5_init", (apr_md5_init(&context) == 0));
+        for (i = 0; i < 10; i++) {
+                ABTS_ASSERT(tc, "apr_md5_update",
+                    (apr_md5_update(&context, string, strlen(string)) == 0));
+                string++;
+        }
+        ABTS_ASSERT(tc, "apr_md5_final", (apr_md5_final(digest, &context)
+                                          == 0));
+        ABTS_ASSERT(tc, "check for correct md5 digest of unaligned data",
+                    (memcmp(digest, sum, APR_MD5_DIGESTSIZE) == 0));
+}
+
 abts_suite *testmd5(abts_suite *suite)
 {
         suite = ADD_SUITE(suite);
@@ -73,6 +97,7 @@ abts_suite *testmd5(abts_suite *suite)
         for (count=0; count < num_sums; count++) {
             abts_run_test(suite, test_md5sum, NULL);
         }
+        abts_run_test(suite, test_md5sum_unaligned, NULL);
 
         return suite;
 }



Mime
View raw message