@@ -650,13 +650,16 @@ 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 = None ):
654+ if rng is None :
655+ rng = Random ()
656+
654657 self .native_object = _ffi .new ("RsaKey *" )
655658 ret = _lib .wc_InitRsaKey (self .native_object , _ffi .NULL )
656659 if ret < 0 : # pragma: no cover
657660 raise WolfCryptError ("Invalid key error (%d)" % ret )
658661
659- self ._random = Random ()
662+ self ._random = rng
660663 if _lib .RSA_BLINDING_ENABLED :
661664 ret = _lib .wc_RsaSetRNG (self .native_object ,
662665 self ._random .native_object )
@@ -690,13 +693,13 @@ def _get_mgf(self):
690693
691694
692695 class RsaPublic (_Rsa ):
693- def __init__ (self , key = None , hash_type = None ):
696+ def __init__ (self , key = None , hash_type = None , rng = None ):
697+ super ().__init__ (rng )
698+
694699 if key is not None :
695700 key = t2b (key )
696701 self ._hash_type = hash_type
697702
698- _Rsa .__init__ (self )
699-
700703 idx = _ffi .new ("word32*" )
701704 idx [0 ] = 0
702705
@@ -842,9 +845,9 @@ def make_key(cls, size, rng=Random(), hash_type=None):
842845
843846 return rsa
844847
845- def __init__ (self , key = None , hash_type = None ): # pylint: disable=super-init-not-called
848+ def __init__ (self , key = None , hash_type = None , rng = None ): # pylint: disable=super-init-not-called
846849
847- _Rsa .__init__ (self ) # pylint: disable=non-parent-init-called
850+ _Rsa .__init__ (self , rng ) # pylint: disable=non-parent-init-called
848851 self ._hash_type = hash_type
849852 idx = _ffi .new ("word32*" )
850853 idx [0 ] = 0
0 commit comments