For a school project we have been given some example hexadecimal numbers to hash like the following:

Len = 2 (in bits)
Msg = c0
SHA 256 - MD = 1e1cea10a23697dc97b423c259842ac12ee679d6b43f088f3c32b26dbbfb0d79

The binary representation of c0 is 11000000, but as the length is 2 units, I assume that the binary number to be hashed is 11, which corresponds to 3 in decimal. Using online hash converters, I cannot get the example hash value back. What am I doing wrong?

  • $\begingroup$ To clarify: why are you converting things to binary notation? $\endgroup$ – e-sushi Dec 4 '16 at 20:57
  • $\begingroup$ It is given in the description of the exercise.Recall that the binary representation of c0 is 11000000. Then ● The first sample message is 2 bits in length and is 11 $\endgroup$ – jgulacsy Dec 4 '16 at 21:10
  • 3
    $\begingroup$ 11000000 is 8 bits in length, not 2, a 0 bit is still a bit $\endgroup$ – Richie Frame Dec 4 '16 at 21:36

You need to hash exactly 2 bits set to 1. Two bits need to be padded, remembering that this is the last block. In that case the result is correct.

Note that representing two bits with hex value C0 is not correct. C0 represents a full byte and there is no reason to use the most significant bits rather than the lowest significant bits. Two bits set to one should simply be represented as 11 in binary.

I calculated the required result by performing a digest of the value E0 (the value with an additional padding bit set to 1, and the rest 0 valued padding bits: 11 1 0 0000), skipping the usual padding byte 80 (or 1000 0000 in binary), padding with zero valued bytes and then finally setting the (internal, encoded) length to 2. A bit messy, but it works.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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