Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RSA encryption output size

What is RSA encryption output size when using 2048 bit key and pkcs1padding.

Is it always 256 bytes independent of input size?

How can i calculate it for other key sizes?

like image 709
hyda Avatar asked Sep 06 '14 10:09

hyda


People also ask

What is the output of RSA?

the modulus size defines the key size. So the output of an RSA encryption is the same as the key size: ceil(keySize / 8.0) using floats or (keySize + 8 - 1) / 8 using integers. RSA with OAEP padding uses the same technique, so the answer is correct for OAEP as well (and most other, less known schemes such as RSA-KEM).

How much data 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.

Does RSA encryption increase data size?

Symmetric encryption does not increase the size of the data. The maximum asymmetric data size is 11 bytes less than the size of the key.

How big should p and q be RSA?

The security of RSA depends on how large n is, which is often measured in the number of bits for n. Current recommendation is 1024 bits for n. p and q should have the same bit length, so for 1024 bits RSA, p and q should be about 512 bits.

What is the maximum size of RSA encryption?

5 Answers 5. RSA, as defined by PKCS#1, encrypts "messages" of limited size. With the commonly used "v1.5 padding" and a 2048-bit RSA key, the maximum size of data which can be encrypted with RSA is 245 bytes.

What is the output-size of RSA key?

The output-size should always equals the size of the Modulus (part of the key), so: 2048 bit Modulus -> 2048 bit output 1024 bit Modulus -> 1024 bit output ... If it is not, there exist numerous attacks on RSA, see here for basic information about that.

What is a public key RSA encryption?

RSA (Rivest–Shamir–Adleman) is one of the first public-key cryptosystems and is widely used for secure data transmission. In such a cryptosystem, the encryption key is public and it is different from the decryption key which is kept secret (private).

What is the difference between AES and RSA encryption?

The exact difference is implementation dependent, but may be on the order of 100 to 1000 times faster. It is widely known that AES encrypts a 16-byte block of data at a time. However, how much data can be encrypted at one time with an RSA key is usually only discussed in vague terms such as “use RSA to encrypt session keys.”


Video Answer


3 Answers

Yes, it is.

The output-size should always equals the size of the Modulus (part of the key), so:

2048 bit Modulus -> 2048 bit output
1024 bit Modulus -> 1024 bit output
...

If it is not, there exist numerous attacks on RSA, see here for basic information about that.

So to guarantee that the output is 2048 bit even when the input to encrypt is, let's say 7,
a padding must always be applied!

like image 166
i_turo Avatar answered Oct 17 '22 22:10

i_turo


The output (as integer) of RSAEP (RSA encryption primitive) is always between 0 and n:

  1. If the message representative m is not between 0 and n-1, output message representative out of range and stop.

  2. Let c = m^e mod n.

  3. Output c.

Of course, c is a number. So you have to convert it to bytes for it to be usable. The only thing known about c is that it is smaller than n for a large value of m. It may be that c is a few bytes smaller even if m is large.


You've mentioned PKCS1Padding, which is part of the RSAES-PKCS1-V1_5-ENCRYPT encryption scheme. The padding will make sure that m is always large and randomized; requirements for RSA encryption to be secure.

You'll find that the encoding of c is specified in there:

...

Step 4: Convert the ciphertext representative c to a ciphertext C of length k octets: C = I2OSP (c, k)

...

where k is the size of the modulus in octets (bytes).

So yes, the answer is always k, the size of the modulus in bytes. Simply because the standard requires it that way. It is a value encoded as unsigned big endian number prefixed with as many zero bytes as required.


Notes:

  • the modulus size defines the key size. So the output of an RSA encryption is the same as the key size: ceil(keySize / 8.0) using floats or (keySize + 8 - 1) / 8 using integers.

  • RSA with OAEP padding uses the same technique, so the answer is correct for OAEP as well (and most other, less known schemes such as RSA-KEM).

  • Many library routines that perform "raw" RSA (just modular exponentiation of the message with the public exponent) still perform the I2OSP function - but better check to make sure.

like image 7
Maarten Bodewes Avatar answered Oct 17 '22 21:10

Maarten Bodewes


The output size of plain RSA (using some padding scheme, but no hybrid encryption) is always the key size. The reason is that for some public key n the result is some integer c with 0<=c<n. There are lots of introductions for RSA, e.g. http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-045j-automata-computability-and-complexity-spring-2011/lecture-notes/MIT6_045JS11_rsa.pdf

like image 3
Perseids Avatar answered Oct 17 '22 21:10

Perseids