Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top