I'm looking for best practices when it comes to encrypting small (< 128 bytes) amounts of data with the RSA private key. Signing it would make the resulting payload too large.
|
|
In any public key system, you don't encrypt with private key. You encrypt with public key, or sign with private key. If your goal is signing (resp. encrypting) one small value with the RSA private (resp. public) key, keeping the signature small: forget about it, that's not directly possible. Under RSA, a cryptogram is always of size at least comparable to the key. You need another public key scheme. Edit: standard RSA signatures schemes have signatures about as wide as the public modulus; a state of the art RSA variant can about half that. If you want to encrypt several small values with RSA, do that with a random secret key drawn for that purpose, and a symmetric cipher; and send the secret key, RSA-encrypted with the public key, using a proper padding scheme like OAEP. If you want to sign several small values with RSA, concatenate them (each with length indication unless the lengths are agreed in advance), then sign the aggregate using a proper RSA signature scheme like PKCS#1 PSS. If you want to send the small values along and care about the total size, use a signature scheme with message recovery, such as ISO/IEC 9796-2 (but beware that the first of the three schemes in this standard, still the most used, has some flaws if the opponent can obtain the signature of enough chosen messages). |
|||||||||||||||||
|
|
In general you shouldn't mess with standard algorithms/protocols, because of the innumerable ways you can break semantic security, like adaptive chosen ciphertext attacks. Use optimal asymmetric encryption padding if you must roll something yourself. |
||||
|
|
|
If your goal is to sign (authenticate) the data, and if RSA signatures are too long, there are some exotic schemes out there that have shorter signatures. For instance, BLS signatures are about 170 bits long and give about 80 bits of security. However, these schemes are considerably slower and more complex to implement. (An earlier version of this answer suggested that elliptic curve signatures could achieve 64-bit security with a 128-bit signature. That was incorrect. Thanks to @Thomas Pornin for pointing out my error.) |
|||||||
|
|
DSA produces much shorter signatures than RSA, and can generate them much faster. But the caveat is that verification is slower compared to RSA. If this is a problem depends on how you plan to use them, and how critical performance is. You could take a look at ECDSA, it may be the best of both worlds ;) |
|||
|
|