0

I'm trying to understand padding in sha family.

padded message abc is 61626380000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000018

a=61 , b=62 and c=63 I got it. 18 means 24 in hex which is abc => 3.8

what is 8 and the whole zeros for?

Thanks for the answers

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
someWhereElse
  • 15
  • 2
  • 6
  • i learned so i'm sharing. we are adding 1 so in eight bit 10000000 means 80 in hex. And the other zeros to complete the padding block to 64 byte. – someWhereElse Aug 28 '14 at 12:39

1 Answers1

0

To extend someWhereElse's comment. SHA padding extends the message to the next block boundary. At the end of the message add a 1 bit (not byte) followed by zero bits until 64 bits from the end of the block. Use the last 64 bits of the block to hold the length of the message in binary.

Your padded block is made up of:

616263 : "abc" - the message text.
8      : "1000" - the 1 bit to start the padding, followed by padding zeros.
0...0  : The rest of the padding zero bits.
0000000000000018 : 64 bit message length, 24 bits in this case.

If the message ends within 65 bits of the block boundary, then the padding needs to include a whole extra block.

rossum
  • 15,344
  • 1
  • 24
  • 38
  • Sorry there's another question. What about the salt? Is that similar to padding? @rossum – someWhereElse Aug 29 '14 at 08:30
  • Salt is for a different purpose. It is applied before the hash. Rather than just hashing the message, you hash the message concatenated with the salt. If two people pick the same password, then the salts will be different so the hashes will be different. There is an article on Wikipedia [Salt (cryptography)](http://en.wikipedia.org/wiki/Salt_(cryptography)). – rossum Aug 29 '14 at 10:43
  • So it's like the real salt. The dishes taste change because different pinch of salt . So the hashes change because different salt ha? I think i got it. Thank you! By the way, sorry about my English. It's not my native language so i can't use efficiently. – someWhereElse Aug 29 '14 at 13:03