Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

NIST FIPS 180-4. “5.1. Padding the Message.”

Suppose that the length of the message, $M$, is $l$ bits.

Is there any library that can receive a message of length (in bits) which is not a multiple of $2^3$?

share|improve this question
This is one of the things on my hash library todo list. By simply adding another optional argument of "number of bits in last byte", then do a shift on the padding byte and xor it to the last byte, and change the total bit count. I assume this would be the most simple method of modification of any code to support this where the input is always in bytes. – Richie Frame Oct 5 '13 at 6:37
@Richie Frame: If I may suggest you, define one argument which is a length in bits. When generating bit strings, I am shifting machine words, not bytes. When finalizing, length is in bits, on previous calls length is in blocks natural for a hashing algorithm. Shifting really is obligation of a caller. – beroal Oct 5 '13 at 16:08
The argument would be handled internally by the code that performs the hash, it does not care if you are generating individual bits, bytes, or words. If you are generating words then truncating, the number of bits you truncated $t$ is passed as the argument $-t$ $mod$ $8$ to the library. Having the argument be the total bitlength may cause problems where the input and argument vary by more than 7, unless the library performs the final truncation. – Richie Frame Oct 6 '13 at 8:55
I should not that if the message is not passed to the library as a byte array (such as an array of uInt64) my method would no longer work, the application of my code requires input as a string or byte array, so that would not be a problem, but may be on other platforms where a $char$ is not 8-bits – Richie Frame Oct 6 '13 at 9:03

Such libraries most certainly do exist; see here and here for two examples.

A hash implementation that can handle odd-sized bit strings is called "bit-oriented"; most implementations don't bother with it (just because the requirement just doesn't come up that often), however, a few do.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.