0

In md5 computation algorithm there is a function

// decodes input (unsigned char) into output (uint4). Assumes len is a multiple of 4.
void MD5::decode(uint4 output[], const uint1 input[], size_type len)
{
   for (unsigned int i = 0, j = 0; j < len; i++, j += 4)
     output[i] = ((uint4)input[j]) | (((uint4)input[j+1]) << 8) |
       (((uint4)input[j+2]) << 16) | (((uint4)input[j+3]) << 24);
}

Why not just copy with memcpy? Is it because of possible different byte-orders on different machines?

flashnik
  • 1,900
  • 4
  • 19
  • 38

1 Answers1

2

Correct, it's a byte-ordering thing. It's equivalent to a straight copy on little-endian systems, but ends up reversing the byte on big-endian.

  • i.e. when compiling for Linux/Win both on x86 and x64 I can define call to memecpy instead of this function to speedup computation (if it will speedup)? – flashnik Dec 17 '12 at 05:33
  • With any competent optimizing compiler, it won't make any difference at all. But yes, you could. –  Dec 17 '12 at 05:46