Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the RSA max block size to encode?

Tags:

rsa

encryption

What RSA max block size which I can encrypt in one cycle?

And what is the maximum speed of the RSA algorithm with a 4096 bit key size?

like image 830
lebron2323 Avatar asked Aug 06 '12 04:08

lebron2323


People also ask

What is the block size of RSA?

The block size is equal to the number of bytes of the RSA modulus. If the modulus is k bytes long, then the encrypted output size is always k. For the “NoPadding” mode, the plaintext input must be equal to or less than k; with the “PKCS1Padding” mode, the plaintext input must be equal to or less than k-11 bytes.

How much can RSA encrypt?

The modulus size is the key size in bits / 8. Thus a 1024-bit RSA key using OAEP padding can encrypt up to (1024/8) – 42 = 128 – 42 = 86 bytes. A 2048-bit key can encrypt up to (2048/8) – 42 = 256 – 42 = 214 bytes.

How strong is RSA 4096?

A 4096 bit key does provide a reasonable increase in strength over a 2048 bit key, and according to the GNFS complexity, encryption strength doesn't drop off after 2048 bits. There's a significant increase in CPU usage for the brief time of handshaking as a result of a 4096 bit key.


1 Answers

According to Lenstra's updated equations available on this site, the security level of a 4096 bit RSA key is matched by a cryptographic hash which is at least 248 bits long, for instance SHA-256.

If you use RSA OAEP (and you should), the amount of data you can encrypt at most is therefore modulus size - 2 - 2*hash size, which is 446 bytes.

With RSA PKCS#1 v1.5 you can encrypt at most modulus size - 11 bytes, but RSA PKCS#1 v1.5 provides less security (it is not provably secure, and the minimum number of random padding bytes should be extended to at least 16 bytes).

If you need to encrypt more data you should not simply chop it up and use RSA multiple times on each block. That is a security flaw. You must take a different approach, more precisely:

  1. Select a random 128 bit symmetric key.
  2. Use an authenticated mode of operation to encrypt your data (e.g. AES-128 GCM).
  3. Encrypt the symmetric key using RSA OAEP.

RSA encryption (unlike decryption) is pretty speedy, but the time is really dependent on the library and on the platform you use. For some reference, see cryptopp library's website.

like image 78
SquareRootOfTwentyThree Avatar answered Sep 23 '22 15:09

SquareRootOfTwentyThree