On 3/28/2012 11:49 PM, Alex Chen wrote:
When the padding is disabled by setting the padding size to 0 in 
EVP_CIPHER_CTX_set_padding(), is the output data block size the same as the 
input block size?
Will this reduce the encryption strength?
Padding doesn't change the block size at all.

Padding changes the number of plain text bytes so any number
of bytes can be encrypted with an algorithm that can only
encrypt a multiple of its block size.

For example AES has a block size of 16 bytes, so without
padding, it can only encrypt 0, 16, 32, 48, 64, ... bytes.
Padding allows you to encrypt 0, 1, 2, 3, ... bytes by
adding 1 to 16 bytes extra, which are then removed after
decryption (only if you tell the decryption that padding
was used).

Because a plain text of 16 bytes could be the same 16 bytes
as what OpenSSL creates when padding a shorter plain text,
OpenSSL has to also add padding to a 16 byte plain text
when padding is enabled, so the decryption can tell the
difference between such a 16 byte plain text and a shorter
plaintext padded to 16 bytes.

The same principle applies to any other multiple of the
block size (0, 32, 48, 64, ...)

For DES, 3DES, Blowfish etc. the block size is 8 bytes,
but the principle is the same.

The above padding description is for modes that can only
encrypt a whole number of blocks by themselves, such as
CBC, ABC, ECB etc.

Some other modes have their own way to encrypt arbitrary
number of bytes and don't need additional padding.

Thus the "padding" option tells EVP if you want a kind
of encryption that can encrypt any number of bytes, or
one that can only encrypt a multiple of the block size.
And you need to set it the same when decrypting, so this
is something that must be decided at protocol/file
format design time.

P.S.

Next time, please start a new thread by using the
"new mail" button, not the "reply" button.


--
Jakob Bohm, CIO, partner, WiseMo A/S. http://www.wisemo.com
Transformervej 29, 2730 Herlev, Denmark. direct: +45 31 13 16 10 <call:+4531131610>
This message is only for its intended recipient, delete if misaddressed.
WiseMo - Remote Service Management for PCs, Phones and Embedded
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to