diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2016-01-22 13:11:22 +0100 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2016-01-22 13:14:40 +0100 |
commit | 2310b34bdb530e0bad793d42f589c9f848ff181b (patch) | |
tree | 7add9af08619ac491dadef6c0a9620794e5b68bd /tests | |
parent | 15b69b38568cfe883180c397d408207b456e0e06 (diff) | |
download | rsa-2310b34bdb530e0bad793d42f589c9f848ff181b.tar.gz |
Fix #19: Implemented blinding when decrypting.
This prevents side-channel (such as timing) attacks, see:
https://en.wikipedia.org/wiki/Blinding_%28cryptography%29
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_key.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/test_key.py b/tests/test_key.py new file mode 100644 index 0000000..df35335 --- /dev/null +++ b/tests/test_key.py @@ -0,0 +1,30 @@ +""" +Some tests for the rsa/key.py file. +""" + + +import unittest + +import rsa.key +import rsa.core + + +class BlindingTest(unittest.TestCase): + + def test_blinding(self): + """Test blinding and unblinding. + + This is basically the doctest of the PrivateKey.blind method, but then + implemented as unittest to allow running on different Python versions. + """ + + pk = rsa.key.PrivateKey(3727264081, 65537, 3349121513, 65063, 57287) + + message = 12345 + encrypted = rsa.core.encrypt_int(message, pk.e, pk.n) + + blinded = pk.blind(encrypted, 4134431) # blind before decrypting + decrypted = rsa.core.decrypt_int(blinded, pk.d, pk.n) + unblinded = pk.unblind(decrypted, 4134431) + + self.assertEqual(unblinded, message) |