Reputation: 124
Python 3 lib I am using:RSA stuvel
In this library the sign function first generates a hash and then signs it. Any way I can get it to sign a message without hashing it first?
Alternatively any other library available which can do the same?
Upvotes: 3
Views: 653
Reputation: 93948
There is a function here: Package Crypto :: Package PublicKey :: Module RSA :: Class _RSAobj sign
.
But note that usually the signature generation is over a hash, extended by an DER encoded structure indicating the hash, which is in turn padded and turned into a number to form the input to the actual modular exponentiation operation. This method just performs the last step; you'd have to do the other ones yourself, and note that they are required from a security perspective.
This is all specified in the PKCS#1 specifications. Note that this is tricky stuff, you may want to copy it from an open source implementation. Or you could just provide it a hash, which is a very good idea - to hash the message first.
There is also the retracted ISO/IEC 9796 which describes signatures with message recovery, which is what you may be after. I don't see an implementation in Python directly. Be sure what you are doing before using a library even if you find it though.
Good luck!
Upvotes: 1