

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer

I would like to know how much padding OpenSSL algorithms expect.

share|improve this question

migrated from Sep 23 '13 at 7:35

This question came from our site for information security professionals.

The answers here will reflect the higher level primitives of course, if you directly use block encrypt then it will probably not pad at all. – Maarten Bodewes Sep 23 '13 at 14:21
up vote 4 down vote accepted

The documentation says:


which is both informative, and slightly misleading. OpenSSL supports, by default, one stream cipher (RC4) and a variety of block ciphers (Blowfish, 3DES, AES...). The enc command (from the command-line tool) encrypts an input file into an OpenSSL-specific format, with a custom header (of length 16 bytes), and then the encrypted data as processed through the selected algorithm. For RC4, there is no padding: the encrypted data will have the same length as the source file (but there will be the extra 16-byte header). For block ciphers, it depends on the mode of operation:

  • CBC and ECB modes require that the input consists in an integral number of blocks, so padding must be applied to ensure that. PKCS#5 padding (identical to PKCS#7 padding) adds at least one byte, at most 255 bytes; OpenSSL will add the minimal number of bytes needed to reach the next multiple of the block size, so if blocks have size n, then padding will involve between 1 and n extra bytes (including). Block size depends on the algorithm: Blowfish and 3DES use 8-byte blocks, AES uses 16-byte blocks.

  • CFB and OFB modes don't require padding, so there is none applied.

share|improve this answer
By definition, when you decrypt, the decryption engine removes the padding. So that engine reliably detects the padding length; this is why PKCS#5 always adds at least one byte (otherwise, the padding would be ambiguous). However, you cannot know the padding length without decrypting. As for encryption, then just look at the length of the data before and after encryption. – Tom Leek Sep 22 '13 at 19:33
Thanks for your help! – warrior24 Sep 22 '13 at 19:55

Your Answer

