def __init__(self, devname = None): if devname is None: self.name = '/dev/urandom' else: self.name = devname f = open(self.name, 'rb', 0) fmode = os.fstat(f.fileno())[stat.ST_MODE] if not stat.S_ISCHR(fmode): f.close() raise TypeError('%r is not a character special device' % (self.name,)) self.__file = f BaseRNG.__init__(self)
def __init__(self, devname=None): if devname is None: self.name = '/dev/urandom' else: self.name = devname f = open(self.name, 'rb', 0) fmode = os.fstat(f.fileno())[stat.ST_MODE] if not stat.S_ISCHR(fmode): f.close() raise TypeError('%r is not a character special device' % (self.name, )) self.__file = f BaseRNG.__init__(self) return
def __init__(self, devname=None): if devname is None: self.name = "/dev/urandom" else: self.name = devname # Test that /dev/urandom is a character special device f = open(self.name, "rb", 0) fmode = os.fstat(f.fileno())[stat.ST_MODE] if not stat.S_ISCHR(fmode): f.close() raise TypeError("%r is not a character special device" % (self.name,)) self.__file = f BaseRNG.__init__(self)
def flush(self): """Work around weakness in Windows RNG. The CryptGenRandom mechanism in some versions of Windows allows an attacker to learn 128 KiB of past and future output. As a workaround, this function reads 128 KiB of 'random' data from Windows and discards it. For more information about the weaknesses in CryptGenRandom, see _Cryptanalysis of the Random Number Generator of the Windows Operating System_, by Leo Dorrendorf and Zvi Gutterman and Benny Pinkas http://eprint.iacr.org/2007/419 """ if self.closed: raise ValueError("I/O operation on closed file") data = self.__winrand.get_bytes(128*1024) assert (len(data) == 128*1024) BaseRNG.flush(self)
def flush(self): """Work around weakness in Windows RNG. The CryptGenRandom mechanism in some versions of Windows allows an attacker to learn 128 KiB of past and future output. As a workaround, this function reads 128 KiB of 'random' data from Windows and discards it. For more information about the weaknesses in CryptGenRandom, see _Cryptanalysis of the Random Number Generator of the Windows Operating System_, by Leo Dorrendorf and Zvi Gutterman and Benny Pinkas http://eprint.iacr.org/2007/419 """ if self.closed: raise ValueError("I/O operation on closed file") data = self.__winrand.get_bytes(128 * 1024) assert (len(data) == 128 * 1024) BaseRNG.flush(self)
def __init__(self): self._read = os.urandom BaseRNG.__init__(self)
def __init__(self): self.__winrand = winrandom.new() BaseRNG.__init__(self)
def flush(self): if self.closed: raise ValueError('I/O operation on closed file') data = self.__winrand.get_bytes(131072) BaseRNG.flush(self)
def flush(self): if self.closed: raise ValueError('I/O operation on closed file') data = self.__winrand.get_bytes(131072) assert len(data) == 131072 BaseRNG.flush(self)