How can padding be disambiguated from data, when encrypting using a block cipher?
I'm by no means an expert in cryptography, but rather a programmer with a keen interest.
Suppose, I've X
bytes of data, message M
, that I want to encrypt using an N
-byte block cipher, where N >> X
.
How can M
be padded using N-X
bytes of padding O
, such that there would be no ambiguity between decrypting the padded message M´
and the (concatenated) message M|O
?
How is this done in practice? Normally, when encrypting using a block cipher, I don't see a header being output describing the original length of the message M
?
M|1
? And what if the block size is >= 256 bits :-) ? Is your padding scheme the one used for all block ciphers, like AES? – Shuzheng Aug 12 '19 at 11:39N-X
bytes of padding, nvm. Is the padding scheme for AES (512 bits) similar? – Shuzheng Aug 12 '19 at 11:55N-X
, it's the smaller number larger than zero that makes the result size a multiple of the block size. AES has 128-bit block size (e.g. 16 bytes), and it indeed works as described – Conrado Aug 12 '19 at 11:58N
is the block size in bytes, whileX
is the length of the message to be encrypted. Then indeed,N-X
bytes of padding is needed, right? What do you mean by "it's the smaller number larger than..."? – Shuzheng Aug 12 '19 at 12:56N
is 16 andX
is 31, thenN-X=-15
but 1 byte of padding is needed. The size of the padding is basicallyN - (X % N)
. – Conrado Aug 12 '19 at 13:05