summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2021-02-14 12:20:57 +0100
committerSybren A. Stüvel <sybren@stuvel.eu>2021-02-15 21:32:23 +0100
commit88418f04d7fd543f55604b862d0a77e5bd84bae6 (patch)
tree1b46bafcc0ac9528dae94db1b09bf8786f1eaa9b /tests
parent3af4e6512690aab6e5bb30c47cf125bb8eb41d89 (diff)
downloadrsa-git-88418f04d7fd543f55604b862d0a77e5bd84bae6.tar.gz
Fix threading issue introduced in 4.7
Computing the blinding factor and its inverse was done in a thread-unsafe manner. Locking the computation & update of the blinding factors, and passing these around in frame- and stack-bound data, solves this. This fixes part of the issues reported in sybrenstuvel/python-rsa#173, but there is more going on in that particular report.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_key.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/tests/test_key.py b/tests/test_key.py
index b00e26d..75e6e12 100644
--- a/tests/test_key.py
+++ b/tests/test_key.py
@@ -21,19 +21,19 @@ class BlindingTest(unittest.TestCase):
message = 12345
encrypted = rsa.core.encrypt_int(message, pk.e, pk.n)
- blinded_1 = pk.blind(encrypted) # blind before decrypting
+ blinded_1, unblind_1 = pk.blind(encrypted) # blind before decrypting
decrypted = rsa.core.decrypt_int(blinded_1, pk.d, pk.n)
- unblinded_1 = pk.unblind(decrypted)
+ unblinded_1 = pk.unblind(decrypted, unblind_1)
self.assertEqual(unblinded_1, message)
# Re-blinding should use a different blinding factor.
- blinded_2 = pk.blind(encrypted) # blind before decrypting
+ blinded_2, unblind_2 = pk.blind(encrypted) # blind before decrypting
self.assertNotEqual(blinded_1, blinded_2)
# The unblinding should still work, though.
decrypted = rsa.core.decrypt_int(blinded_2, pk.d, pk.n)
- unblinded_2 = pk.unblind(decrypted)
+ unblinded_2 = pk.unblind(decrypted, unblind_2)
self.assertEqual(unblinded_2, message)
@@ -69,10 +69,9 @@ class KeyGenTest(unittest.TestCase):
# This exponent will cause two other primes to be generated.
exponent = 136407
- (p, q, e, d) = rsa.key.gen_keys(64,
- accurate=False,
- getprime_func=getprime,
- exponent=exponent)
+ (p, q, e, d) = rsa.key.gen_keys(
+ 64, accurate=False, getprime_func=getprime, exponent=exponent
+ )
self.assertEqual(39317, p)
self.assertEqual(33107, q)