The MD5 algorithm is designed to accept a message of any length and produce a 512-bit message digest. Because of the way it pads the original message, by adding a 1-bit then a number of 0-bits, the length of the message can be any number of bits. It is not limited to an integer number of bytes. But it can also be written to work only in bytes, so the padding stage would involve adding a 0x80 byte then a number of 0x00 bytes. The end result is the same, as long as the input data is an integer number of bytes.
However, my understanding is that data is almost always stored in bytes. This is especially the case for character strings, where each character is represented by at least 1 byte. For this use case, I believe a byte-oriented approach would work fine. But if I wanted to write an MD5 implementation that also accepts files, does the bit/byte distinction become important? Would I need to write the algorithm to deal specifically with bits, or would a byte-oriented implementation work just as well for strings (e.g. from STDIN) and files?
In other words, is data always stored as whole bytes? And if so, what applications are there in which one would need to write an MD5 algorithm that uses individual bits, rather than whole bytes?
md5 "some string"
and have it return5ac749fbeec93607fc28d666be85e73a
. But I'm also considering functionality to accept a file. Therefore, could a byte-oriented approach work for both use cases, or would I need to write the algorithm to use individual bits? I've edited my question to make this clearer. $\endgroup$