3
$\begingroup$

I can see that the message (after padding) should not be 256 bytes because it might be bigger than the modulus of RSA. So I think that the message should be 255 bytes, but I saw posts that says the maximum input is 245 bytes. Why is that?

$\endgroup$

1 Answer 1

7
$\begingroup$

This is due to RSA with PKCS#1 v1.5 padding, as defined in section 7.2 of RFC 3447 (PKCS#1 v2.1):

2. EME-PKCS1-v1_5 encoding:

      a. Generate an octet string PS of length k - mLen - 3 consisting
         of pseudo-randomly generated nonzero octets.  The length of PS
         will be at least eight octets.

      b. Concatenate PS, the message M, and other padding to form an
         encoded message EM of length k octets as

            EM = 0x00 || 0x02 || PS || 0x00 || M.

As you can see there are three overhead bytes and a minimum of 8 bytes of random padding.

Without the padding RSA encryption would be deterministic and not secure.


Originally the RSA encryption scheme has mostly been used with PKCS#1 v1.5 defined padding. No other schemes were all that popular at the time. So it is most likely that PKCS#1 v1.5 is implicitly used when no padding scheme is indicated.

Officially the name should be RSAES-PKCS1-V1_5-ENCRYPT of course, but nobody uses the function names directly.


Note that there are other modes of padding such as OAEP (defined in the same RFC), which is more secure. For new protocols PKCS#1 padding should not be used anymore. If you're stuck with an old protocol that requires PKCS#1 unpadding, you should make sure that padding / decryption oracles do not apply.

$\endgroup$
1
  • 8
    $\begingroup$ I just want to emphasize that PKCS#1 v1.5 encryption padding is weak and should not be used. Unless both protocol and implementation carefully step around its weaknesses you'll likely end up with a decryption oracle. $\endgroup$ Aug 18, 2016 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.