diff --git a/wolfcrypt/ciphers.py b/wolfcrypt/ciphers.py index 105224e..0bfc287 100644 --- a/wolfcrypt/ciphers.py +++ b/wolfcrypt/ciphers.py @@ -651,13 +651,13 @@ class _Rsa(object): # pylint: disable=too-few-public-methods _mgf = None _hash_type = None - def __init__(self): + def __init__(self, rng=Random()): self.native_object = _ffi.new("RsaKey *") ret = _lib.wc_InitRsaKey(self.native_object, _ffi.NULL) if ret < 0: # pragma: no cover raise WolfCryptError("Invalid key error (%d)" % ret) - self._random = Random() + self._random = rng if _lib.RSA_BLINDING_ENABLED: ret = _lib.wc_RsaSetRNG(self.native_object, self._random.native_object) @@ -691,12 +691,14 @@ def _get_mgf(self): class RsaPublic(_Rsa): - def __init__(self, key=None, hash_type=None): + def __init__(self, key=None, hash_type=None, rng=None): if key != None: key = t2b(key) self._hash_type = hash_type + if rng is None: + rng = Random() - _Rsa.__init__(self) + _Rsa.__init__(self, rng) idx = _ffi.new("word32*") idx[0] = 0