當前位置: 首頁>>代碼示例>>Python>>正文


Python winrandom.new方法代碼示例

本文整理匯總了Python中Crypto.Util.winrandom.new方法的典型用法代碼示例。如果您正苦於以下問題:Python winrandom.new方法的具體用法?Python winrandom.new怎麽用?Python winrandom.new使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Crypto.Util.winrandom的用法示例。


在下文中一共展示了winrandom.new方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: runTest

# 需要導入模塊: from Crypto.Util import winrandom [as 別名]
# 或者: from Crypto.Util.winrandom import new [as 別名]
def runTest(self):
        """winrandom: simple test"""
        # Import the winrandom module and try to use it
        from Crypto.Util import winrandom
        randobj = winrandom.new()
        x = randobj.get_bytes(16)
        y = randobj.get_bytes(16)
        self.assertNotEqual(x, y) 
開發者ID:adde88,項目名稱:hostapd-mana,代碼行數:10,代碼來源:test_winrandom.py

示例2: __init__

# 需要導入模塊: from Crypto.Util import winrandom [as 別名]
# 或者: from Crypto.Util.winrandom import new [as 別名]
def __init__(self, numbytes = 160, cipher=None, hash=None):
        if hash is None:
            from hashlib import sha1 as hash

        # The cipher argument is vestigial; it was removed from
        # version 1.1 so RandomPool would work even in the limited
        # exportable subset of the code
        if cipher is not None:
            warnings.warn("'cipher' parameter is no longer used")

        if isinstance(hash, types.StringType):
            # ugly hack to force __import__ to give us the end-path module
            hash = __import__('Crypto.Hash.'+hash,
                              None, None, ['new'])
            warnings.warn("'hash' parameter should now be a hashing module")

        self.bytes = numbytes
        self.bits = self.bytes*8
        self.entropy = 0
        self._hash = hash

        # Construct an array to hold the random pool,
        # initializing it to 0.
        self._randpool = array.array('B', [0]*self.bytes)

        self._event1 = self._event2 = 0
        self._addPos = 0
        self._getPos = hash().digest_size
        self._lastcounter=time.time()
        self.__counter = 0

        self._measureTickSize()        # Estimate timer resolution
        self._randomize() 
開發者ID:RunasSudo,項目名稱:helios-server-mixnet,代碼行數:35,代碼來源:randpool.py

示例3: _randomize

# 需要導入模塊: from Crypto.Util import winrandom [as 別名]
# 或者: from Crypto.Util.winrandom import new [as 別名]
def _randomize(self, N = 0, devname = '/dev/urandom'):
        """_randomize(N, DEVNAME:device-filepath)
        collects N bits of randomness from some entropy source (e.g.,
        /dev/urandom on Unixes that have it, Windows CryptoAPI
        CryptGenRandom, etc)
        DEVNAME is optional, defaults to /dev/urandom.  You can change it
        to /dev/random if you want to block till you get enough
        entropy.
        """
        data = ''
        if N <= 0:
            nbytes = int((self.bits - self.entropy)/8+0.5)
        else:
            nbytes = int(N/8+0.5)
        if winrandom:
            # Windows CryptGenRandom provides random data.
            data = winrandom.new().get_bytes(nbytes)
        # GAE fix, benadida
        #elif os.path.exists(devname):
        #    # Many OSes support a /dev/urandom device
        #    try:
        #        f=open(devname)
        #        data=f.read(nbytes)
        #        f.close()
        #    except IOError, (num, msg):
        #        if num!=2: raise IOError, (num, msg)
        #        # If the file wasn't found, ignore the error
        if data:
            self._addBytes(data)
            # Entropy estimate: The number of bits of
            # data obtained from the random source.
            self._updateEntropyEstimate(8*len(data))
        self.stir_n()                   # Wash the random pool 
開發者ID:RunasSudo,項目名稱:helios-server-mixnet,代碼行數:35,代碼來源:randpool.py

示例4: randomize

# 需要導入模塊: from Crypto.Util import winrandom [as 別名]
# 或者: from Crypto.Util.winrandom import new [as 別名]
def randomize(self, N = 0):
        "Adds N bits of entropy to random pool.  If N is 0, fill up pool."
        import os, string, time
        if N <= 0:
            bits = self.bits - self.entropy
        else:
            bits = N*8
        if bits == 0:
            return
        print bits,'bits of entropy are now required.  Please type on the keyboard'
        print 'until enough randomness has been accumulated.'
        kb = KeyboardEntry()
        s=''    # We'll save the characters typed and add them to the pool.
        hash = self._hash
        e = 0
        try:
            while e < bits:
                temp=str(bits-e).rjust(6)
                os.write(1, temp)
                s=s+kb.getch()
                e += self.add_event(s)
                os.write(1, 6*chr(8))
            self.add_event(s+hash.new(s).digest() )
        finally:
            kb.close()
        print '\n\007 Enough.  Please wait a moment.\n'
        self.stir_n()   # wash the random pool.
        kb.close(4) 
開發者ID:RunasSudo,項目名稱:helios-server-mixnet,代碼行數:30,代碼來源:randpool.py


注:本文中的Crypto.Util.winrandom.new方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。