I'm was reading this example for length extension attack
given here
link
When working out, how the extended block length be divisible by 512 (SHA block size).
I'm assuming following:-
- In SHA, the size of the blocks is 512 bit.
- The last block must contain:the rest of data in message (mod 512).
- some filling (padding)
- the last 64 bits as length
In example given in link shared above, this is what extended msg
looks like
http://example.com/downloadfile=report.pdf%80%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%A8/../../../../../../../etc/passwd&mac=ee40aa8ec0cfafb7e2ec4de20943b673968857a5
Example 1 Calculating
A more precise of asking is that,
message =10 bytes = 80 bits
secret key = 11 bytes= 88 bits
168 mod 512= 160 bits= 21 bytes
64 - 21= 43
padding +message length= 464+552 =1016 bits
adding /../../../../../../../etc/passwd 32 x 8= 256 bits
Adding it to A8/= 424
How I make sense If I add the missing padding which is 256 mod 512 =256=32 bytes
64-32 = 32 x8= 256 bits
Example 2
count=10&lat=37.351&user_id=1&long=-119.827&waffle=eggo\x80\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x02\x28&waffle=liege
Going on by logic
- message =55 bytes = 440 bits
- secret key = 14 bytes= 112 bits
- length encoding = 552
- 552 mod 512= 40 bits= 5 bytes
64 - 5= 59 bytes
If you check the padding its 58 bytes not 59 . Can you tell why?
padding +message length= 472+552 =1024 bits
- adding extra
&waffle=liege
13 x 8= 104 - adding to existing message length(552) + 104= 656
- How I make sense If I add the missing padding which is 656 mod 512 =144 = 18 bytes
- 64 - 18= 46 x 8 = 368 bits
- 104 + 368 (message length and padding)