Skip to content

Commit 3f5fd16

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 5b13e52 commit 3f5fd16

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
@@ -651,13 +651,13 @@ class _Rsa(object): # pylint: disable=too-few-public-methods
651651
_mgf = None
652652
_hash_type = None
653653

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

660-
self._random = Random()
660+
self._random = rng
661661
if _lib.RSA_BLINDING_ENABLED:
662662
ret = _lib.wc_RsaSetRNG(self.native_object,
663663
self._random.native_object)
@@ -691,12 +691,14 @@ def _get_mgf(self):
691691

692692

693693
class RsaPublic(_Rsa):
694-
def __init__(self, key=None, hash_type=None):
694+
def __init__(self, key=None, hash_type=None, rng=None):
695695
if key != None:
696696
key = t2b(key)
697697
self._hash_type = hash_type
698+
if rng is None:
699+
rng = Random()
698700

699-
_Rsa.__init__(self)
701+
_Rsa.__init__(self, rng)
700702

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

0 commit comments

Comments
 (0)