Skip to content

Commit 193d327

Browse files
Make the random generator of _Rsa and RsaPublic configurable.
This was the only class that has hardcoded the random number generator in the implementation.
1 parent 4c1c578 commit 193d327

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

wolfcrypt/ciphers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,13 +650,13 @@ class _Rsa(object): # pylint: disable=too-few-public-methods
650650
_mgf = None
651651
_hash_type = None
652652

653-
def __init__(self):
653+
def __init__(self, rng=Random()):
654654
self.native_object = _ffi.new("RsaKey *")
655655
ret = _lib.wc_InitRsaKey(self.native_object, _ffi.NULL)
656656
if ret < 0: # pragma: no cover
657657
raise WolfCryptError("Invalid key error (%d)" % ret)
658658

659-
self._random = Random()
659+
self._random = rng
660660
if _lib.RSA_BLINDING_ENABLED:
661661
ret = _lib.wc_RsaSetRNG(self.native_object,
662662
self._random.native_object)
@@ -690,12 +690,14 @@ def _get_mgf(self):
690690

691691

692692
class RsaPublic(_Rsa):
693-
def __init__(self, key=None, hash_type=None):
693+
def __init__(self, key=None, hash_type=None, rng=None):
694694
if key is not None:
695695
key = t2b(key)
696696
self._hash_type = hash_type
697+
if rng is None:
698+
rng = Random()
697699

698-
_Rsa.__init__(self)
700+
_Rsa.__init__(self, rng)
699701

700702
idx = _ffi.new("word32*")
701703
idx[0] = 0

0 commit comments

Comments
 (0)