I am trying to find information about the Signature Algorithm SHA512withRSA and have been unsuccessful so far.

In the current state, the signature is too long, so I would like to check the code for overhead and try to remove reduce the size.

Can anybody give me some pointers on how to achieve that.



Related to your reference request: SHA512withRSA points to the RSA Signature Scheme with Appendix based on PKCS #1 v1.5 with SHA-512 hash function.

This means you’re looking for reference documentation describing RSA PKCS1 v1.5 (see: RFC2313) signatures with SHA512 (see: RFC6234) hash and X.509 encoding format.

Removing “overhead” from code

As for the part of your question on how to achieve the removal of overhead in your code: diving into that could quickly become off-topic for Crypto.SE and it would probably be more suitable for StackOverflow anyway. Nevertheless – since your question indicates you’re new to the reference documentations and RFCs describing SHA2, RSA, etc. – I would like to add my two cents to your code-modification idea…

Cryptographic implementations rarely contain or produce (what you call) “overhead”. Therefore, I would like to strongly discourage you from stripping or modifying any part of code that represents, interacts, or relates to cryptographical algorithms or schemes. Doing so has a high probability of introducing issues – which might range from simple software bugs, up to a dangerous situation where the removal of code is equal to the voiding (= removal) of cryptographic security. You surely don’t want the later to happen. Instead of fiddling with the code, you should simply rely a tested and well-vetted implementation. There are many of them out there, available in almost every programming language you could wish for.

  • 1
    $\begingroup$ Thank you for your time and writing me solid answer. I had this question on StackOverflow and was redirected here. The application which I am developing is a proof-of-concept only. I was expecting that SHA256withRSA will have approx 256 bits and SHA512 approx 512 bits. However the size of the signature is more than twice larger its size. What I will do now is try to simply do this manually - creating a SHA512 message digest and decrypt it with an RSA private key. I understand that the text-book RSA does this. I am aware of it might not being secure for this. $\endgroup$
    – KrNeki
    Sep 9 '14 at 21:41

Since your problem is the signature size, I recommend you consider elliptic curve signatures instead of trying to roll your own RSASSA implementation.

With RSA a 512-bit signature requires you to use a 512-bit modulus, which has been considered insecure for more than a decade. It's equivalent to something like 50-80 bit security at best. These days the minimum recommendations start above 1024, with 2048 considered a secure choice.

In comparison, a 256-bit elliptic curve should give you about 128-bit security. The size of signatures varies, but e.g. Ed25519 has 512-bit signatures. You should see what 256-bit curves your crypto libraries support and whether the signature sizes are acceptable. If you need to save a few more bytes, you can go down to a 192-bit curve without it being obviously insecure, but otherwise I would stick with 256 bits for some security margin.

  • $\begingroup$ My RSA key is 2048 bits, though my signature algorithm in java is SHA512withRSA. SHA is 512 bits, not my modulus. Or am I missing something? $\endgroup$
    – KrNeki
    Sep 11 '14 at 19:32
  • $\begingroup$ @KrNeki, With a 2048-bit RSA key the signatures are at least 2048 bits, regardless of which hash algorithm is used. My point was just that if you wanted 512-bit signatures, RSA would be insecure, while elliptic curves wouldn't. $\endgroup$
    – otus
    Sep 11 '14 at 20:57
  • $\begingroup$ You helped me a lot. I want shorter signatures with the same same security and elliptic curve has definitely a good advantage. CPU and memory are also not an issue with the system I am thinking of building, the only problem so far is that our Government only issues RSA certificates. Many thanks to you, I will write about this in my Thesis. $\endgroup$
    – KrNeki
    Sep 11 '14 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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