md5sum makes unaligned word accesses...

Rob Landley rob at landley.net
Mon May 15 19:54:24 UTC 2006


On Sunday 14 May 2006 8:07 pm, Mike Frysinger wrote:
> On Sunday 14 May 2006 20:00, Rob Landley wrote:
> > try actually benching stuff and the alignment is likely to be noise at
> > best.
>
> sure, if we ignore the cases where the result is either wrong or the
> process is just out right killed
> -mike

Of course. :)

I just changed my copy of md5_hash() to look like:

void md5_hash(const void *data, size_t length, md5_ctx_t *ctx)
{
    /* We can only call the hash function directly on data that's
     * 32-bit aligned and a multiple of 64 bytes. */

    if ((length&63) || (data&3)) md5_hash_bytes(data, length, ctx);
    else md5_hash_block(data, length, ctx);
}

And I'm fixing up md5_hash_bytes() to always copy data into its temporary 
buffer.  Since that code's already there the size increase shouldn't be too 
bad (no extra allocations required and I might even be able to shrink the 
code size if I find cleanup opportunities in md5_hash_bytes), and copying 
data in 64 byte chunks right before processing each chunk is _extremely_ 
cache friendly, so the speed hit should be effectively zero.  So we can 
happily do this for all platforms and life is good.

Now to finish implementing it...

Rob
-- 
Never bet against the cheap plastic solution.



More information about the busybox mailing list