0

In Wikipedia SHA-1 pseudocode, it's said:

Pre-processing: append the bit '1' to the message e.g. by adding 0x80 if message length is a multiple of 8 bits. append 0 ≤ k < 512 bits '0', such that the resulting message length in bits

So is it same with \x01 and x00\x01?

Python example:

import hashlib
for s in ('01', '0001'):
    m=hashlib.sha1()
    m.update(s.decode('hex'))
    print m.hexdigest()

>>>bf8b4530d8d246dd74ac53a13471bba17941dff7
>>>0e356ba505631fbf715758bed27d503f8b260e3a

It turns out not to be the same, why?

msvalkon
  • 11,887
  • 2
  • 42
  • 38
whi
  • 2,685
  • 6
  • 33
  • 40

1 Answers1

1

\x01 and \x0001 cannot be the same after pre-processing.

I think that you misunderstand the pseudocode in Wiki. Here I take \x01 and \x0001 as examples, which their length are less than 512 bits.

(Now suppose that the original message length is less than 448 bits)

  • first step: fill in to let its length =448 (mod 512). We append the 1 bit first, then append 0.

Thus, for \x01, it becomes \x01800000...000, and its length is 448 bits, and the ellipsis represents 0 in hex.

  • second step: fill in the length. We should add the reminder (512 - 448) = 64 bits to represent its original length.

Thus, for \x01, its original length is 8, it shall append \x00000000 00000008.

From mentioned above, after pre-processing, \x01 becomes \x01800000...08, and whole length is 512, and the ellipsis represents 0 in hex.

chenzhongpu
  • 6,193
  • 8
  • 41
  • 79
  • so in conclusion, shall we say that from '\x1' to any 100 TB length data, there's no collision found yet for 160bit sha1 digest now? – whi Mar 02 '16 at 08:22