I'm currently reverse engineering a binary that uses Blowfish. A sample input would be:
08 00 01 00 1C FB 19 00
When this data is encrypted and then decrypted, I get the following results:
encrypt: 47 D2 23 7A 57 2B 9F B0 3F B5 1E BE C6 66 54 0C decrypt: 08 00 01 00 1C FB 19 00 94 14 EC 29 EE 4E 06 00
I'm confused about how the padding is added here. Multiple things:
- why is there padding (2nd block) in the first place, when input is 8 bytes, which is the blowfish block size?
- using a padding of 6 bytes seems arbitrary, why is 0x06 not on the last byte without a null character?
I had a look at the different types of cryptographic padding, and none really seem to match.
Perhaps this is something related to the block cipher mode of operation?
I've tried a couple of blowfish implementations but so far they don't seem to match.
Does this look familiar to anyone?
I've been asked why I assume this is a padding. Well, the binary does the following:
0063A1E5 |. 66:8B4C28 FE MOV CX,WORD PTR DS:[EAX+EBP-2] 0063A1EA |. 66:83F9 08 CMP CX,8 0063A1EE |. /76 04 JBE SHORT <some address> 0063A1F0 |. |33C0 XOR EAX,EAX 0063A1F2 |. |5D POP EBP 0063A1F3 |. |C3 RETN
So it's bailing when this short is bigger or equal than 8 (the block size).
It also makes sense when you consider the following:
[[08 00] 01 00 1C FB 19 00] [94 14 EC 29 EE 4E] [06 00] ^ ^ ^ ^ data size | padding pad size data block 6 bytes!