diff options
author | Justin Simon <jls5177@gmail.com> | 2017-05-07 04:39:47 -0500 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2017-05-07 11:39:47 +0200 |
commit | 425eb24854f1c3397aaaba61fa1cf71c76b27c4b (patch) | |
tree | 824a0e34f6bc4e88bbbb6bfa7e2f7a80d5399aa3 /tests | |
parent | 000e84a97a8ab25a5d9b4185a2e02efc033f7e8a (diff) | |
download | rsa-git-425eb24854f1c3397aaaba61fa1cf71c76b27c4b.tar.gz |
Support signing a pre-calculated hash (#87)
* Split the hashing out of the sign method
This code change adds support to split the hashing of a message
and the actual signing of the message.
* Updating unit test and documentation
This commit updates the unit test and usage docs. In addition,
This change removes a redundant error check inside rsa.sign().
* Refactore unit tests and code comments
Removed the print statements from the unit test and refactored a
few code comments to improve readability.
* Rename hash function
The new hash function had the same name as a function in the
standard library. This commit changes the name to avoid conflicts.
* Rename hash function to compute_hash()
This commit renames the hash function to compute_hash().
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_pkcs1.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_pkcs1.py b/tests/test_pkcs1.py index a8afea7..a96c8be 100644 --- a/tests/test_pkcs1.py +++ b/tests/test_pkcs1.py @@ -111,3 +111,24 @@ class SignatureTest(unittest.TestCase): signature2 = pkcs1.sign(message, self.priv, 'SHA-1') self.assertEqual(signature1, signature2) + + def test_split_hash_sign(self): + """Hashing and then signing should match with directly signing the message. """ + + message = b'je moeder' + msg_hash = pkcs1.compute_hash(message, 'SHA-256') + signature1 = pkcs1.sign_hash(msg_hash, self.priv, 'SHA-256') + + # Calculate the signature using the unified method + signature2 = pkcs1.sign(message, self.priv, 'SHA-256') + + self.assertEqual(signature1, signature2) + + def test_hash_sign_verify(self): + """Test happy flow of hash, sign, and verify""" + + message = b'je moeder' + msg_hash = pkcs1.compute_hash(message, 'SHA-256') + signature = pkcs1.sign_hash(msg_hash, self.priv, 'SHA-256') + + self.assertTrue(pkcs1.verify(message, signature, self.pub)) |