Bug 49011

Summary: [PATCH] Speed up MD5 on Little Endian Machines
Product: APR Reporter: Stefan Fuhrmann <stefanfuhrmann>
Component: APR-utilAssignee: Apache Portable Runtime bugs mailinglist <bugs>
Status: RESOLVED FIXED    
Severity: enhancement Keywords: FixedInTrunk
Priority: P2    
Version: 1.3.9   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: MD5 speedup patch

Description Stefan Fuhrmann 2010-03-28 14:27:42 UTC
Created attachment 25199 [details]
MD5 speedup patch

The patch attached eliminates unnecessary
buffer copy and clean-up operations on 
little-endian machines (e.g. x86 & friends).

Calling decode() will convert the buffer
'block' from little-endian to machine-endian
in 'x'. That is only necessary on big-endian
machines.

Net runtime savings: ~15%.

[[[
If we are on a little-endian machine, we
can read directly from the input buffer.

* crypto/apr_md5.c
  (MD5Transform): optmimize by translating 
  buffers & cleaning them up on big-endian
  machines only.

patch by stefanfuhrmann < at > alice-dsl.de
]]]
Comment 1 Stefan Fritsch 2010-09-18 04:05:20 UTC
I don't think your patch is correct in general because block may be 1-byte aligned but x must be 4-byte aligned. It would work on x86 but it may fail on other architectures that don't support unaligned access.

One has to check the alignment and do a memcpy if the input block is not properly aligned.
Comment 2 Stefan Fritsch 2013-03-23 23:19:55 UTC
committed different version with alignment checks:
r1460244
Comment 3 Stefan Fritsch 2013-03-24 08:04:52 UTC
1.5 commit: r1460281
Comment 4 Stefan Fritsch 2013-04-05 20:25:30 UTC
fixed in 1.5.2