Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3bf7b2e

Browse files
committed
Choose blinding factor relatively prime to N
This is a requirement for RSA blinding, but wasn't implemented yet.
1 parent4ed79bc commit3bf7b2e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

‎CHANGELOG.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ Python-RSA changelog
44
Version 4.3 - released 2020-06-12
55
----------------------------------------
66

7-
Version 4.3 is a re-tagged release of version 4.0. It is the last to support
8-
Python 2.7. This is now made explicit in the `python_requires` argument in
9-
`setup.py`.
7+
Version 4.3 isalmosta re-tagged release of version 4.0. It is the last to
8+
supportPython 2.7. This is now made explicit in the `python_requires` argument
9+
in`setup.py`.
1010

11-
There are no functional differences.
11+
Two security fixes have also been backported, so 4.3 = 4.0 + these two fixes.
12+
13+
- Choose blinding factor relatively prime to N. Thanks Christian Heimes for pointing this out.
1214

1315

1416
Version 4.0 - released 2018-09-16

‎rsa/key.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,13 @@ def __ne__(self, other):
417417
def__hash__(self):
418418
returnhash((self.n,self.e,self.d,self.p,self.q,self.exp1,self.exp2,self.coef))
419419

420+
def_get_blinding_factor(self):
421+
for_inrange(1000):
422+
blind_r=rsa.randnum.randint(self.n-1)
423+
ifrsa.prime.are_relatively_prime(self.n,blind_r):
424+
returnblind_r
425+
raiseRuntimeError('unable to find blinding factor')
426+
420427
defblinded_decrypt(self,encrypted):
421428
"""Decrypts the message using blinding to prevent side-channel attacks.
422429
@@ -427,7 +434,7 @@ def blinded_decrypt(self, encrypted):
427434
:rtype: int
428435
"""
429436

430-
blind_r=rsa.randnum.randint(self.n-1)
437+
blind_r=self._get_blinding_factor()
431438
blinded=self.blind(encrypted,blind_r)# blind before decrypting
432439
decrypted=rsa.core.decrypt_int(blinded,self.d,self.n)
433440

@@ -443,7 +450,7 @@ def blinded_encrypt(self, message):
443450
:rtype: int
444451
"""
445452

446-
blind_r=rsa.randnum.randint(self.n-1)
453+
blind_r=self._get_blinding_factor()
447454
blinded=self.blind(message,blind_r)# blind before encrypting
448455
encrypted=rsa.core.encrypt_int(blinded,self.d,self.n)
449456
returnself.unblind(encrypted,blind_r)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp