Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #19: Implemented blinding when decrypting.
This prevents side-channel (such as timing) attacks, see: https://en.wikipedia.org/wiki/Blinding_%28cryptography%29
- Loading branch information
1 parent
15b69b3
commit 2310b34
Showing
4 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |