summaryrefslogtreecommitdiff
path: root/rsa/pkcs1.py
diff options
context:
space:
mode:
Diffstat (limited to 'rsa/pkcs1.py')
-rw-r--r--rsa/pkcs1.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/rsa/pkcs1.py b/rsa/pkcs1.py
index bb08f4d..41f543c 100644
--- a/rsa/pkcs1.py
+++ b/rsa/pkcs1.py
@@ -294,6 +294,7 @@ def verify(message, signature, pub_key):
:param signature: the signature block, as created with :py:func:`rsa.sign`.
:param pub_key: the :py:class:`rsa.PublicKey` of the person signing the message.
:raise VerificationError: when the signature doesn't match the message.
+ :returns: the name of the used hash.
"""
@@ -314,7 +315,26 @@ def verify(message, signature, pub_key):
if expected != clearsig:
raise VerificationError('Verification failed')
- return True
+ return method_name
+
+
+def find_signature_hash(signature, pub_key):
+ """Returns the hash name detected from the signature.
+
+ If you also want to verify the message, use :py:func:`rsa.verify()` instead.
+ It also returns the name of the used hash.
+
+ :param signature: the signature block, as created with :py:func:`rsa.sign`.
+ :param pub_key: the :py:class:`rsa.PublicKey` of the person signing the message.
+ :returns: the name of the used hash.
+ """
+
+ keylength = common.byte_size(pub_key.n)
+ encrypted = transform.bytes2int(signature)
+ decrypted = core.decrypt_int(encrypted, pub_key.e, pub_key.n)
+ clearsig = transform.int2bytes(decrypted, keylength)
+
+ return _find_method_hash(clearsig)
def yield_fixedblocks(infile, blocksize):