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


Python FortunaAccumulator.FortunaAccumulator方法代碼示例

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


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

示例1: test_FortunaPool

# 需要導入模塊: from Crypto.Random.Fortuna import FortunaAccumulator [as 別名]
# 或者: from Crypto.Random.Fortuna.FortunaAccumulator import FortunaAccumulator [as 別名]
def test_FortunaPool(self):
        """FortunaAccumulator.FortunaPool"""
        pool = FortunaAccumulator.FortunaPool()
        self.assertEqual(0, pool.length)
        self.assertEqual("5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456", pool.hexdigest())

        pool.append(b('abc'))

        self.assertEqual(3, pool.length)
        self.assertEqual("4f8b42c22dd3729b519ba6f68d2da7cc5b2d606d05daed5ad5128cc03e6c6358", pool.hexdigest())

        pool.append(b("dbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"))

        self.assertEqual(56, pool.length)
        self.assertEqual(b('0cffe17f68954dac3a84fb1458bd5ec99209449749b2b308b7cb55812f9563af'), b2a_hex(pool.digest()))

        pool.reset()

        self.assertEqual(0, pool.length)

        pool.append(b('a') * 10**6)

        self.assertEqual(10**6, pool.length)
        self.assertEqual(b('80d1189477563e1b5206b2749f1afe4807e5705e8bd77887a60187a712156688'), b2a_hex(pool.digest())) 
開發者ID:adde88,項目名稱:hostapd-mana,代碼行數:26,代碼來源:test_FortunaAccumulator.py

示例2: reinit

# 需要導入模塊: from Crypto.Random.Fortuna import FortunaAccumulator [as 別名]
# 或者: from Crypto.Random.Fortuna.FortunaAccumulator import FortunaAccumulator [as 別名]
def reinit(self):
        """Initialize the random number generator and seed it with entropy from
        the operating system.
        """

        # Save the pid (helps ensure that Crypto.Random.atfork() gets called)
        self._pid = os.getpid()

        # Collect entropy from the operating system and feed it to
        # FortunaAccumulator
        self._ec.reinit()

        # Override FortunaAccumulator's 100ms minimum re-seed interval.  This
        # is necessary to avoid a race condition between this function and
        # self.read(), which that can otherwise cause forked child processes to
        # produce identical output.  (e.g. CVE-2013-1445)
        #
        # Note that if this function can be called frequently by an attacker,
        # (and if the bits from OSRNG are insufficiently random) it will weaken
        # Fortuna's ability to resist a state compromise extension attack.
        self._fa._forget_last_reseed() 
開發者ID:lycclsltt,項目名稱:watchmen,代碼行數:23,代碼來源:_UserFriendlyRNG.py

示例3: test_accumulator_pool_length

# 需要導入模塊: from Crypto.Random.Fortuna import FortunaAccumulator [as 別名]
# 或者: from Crypto.Random.Fortuna.FortunaAccumulator import FortunaAccumulator [as 別名]
def test_accumulator_pool_length(self):
        """FortunaAccumulator.FortunaAccumulator minimum pool length"""
        fa = FortunaAccumulator.FortunaAccumulator()

        # This test case is hard-coded to assume that FortunaAccumulator.min_pool_size is 64.
        self.assertEqual(fa.min_pool_size, 64)

        # The PRNG should not allow us to get random data from it yet
        self.assertRaises(AssertionError, fa.random_data, 1)

        # Add 60 bytes, 4 at a time (2 header + 2 payload) to each of the 32 pools
        for i in range(15):
            for p in range(32):
                # Add the bytes to the pool
                fa.add_random_event(2, p, b("XX"))

                # The PRNG should not allow us to get random data from it yet
                self.assertRaises(AssertionError, fa.random_data, 1)

        # Add 4 more bytes to pool 0
        fa.add_random_event(2, 0, b("XX"))

        # We should now be able to get data from the accumulator
        fa.random_data(1) 
開發者ID:lycclsltt,項目名稱:watchmen,代碼行數:26,代碼來源:test_FortunaAccumulator.py

示例4: __init__

# 需要導入模塊: from Crypto.Random.Fortuna import FortunaAccumulator [as 別名]
# 或者: from Crypto.Random.Fortuna.FortunaAccumulator import FortunaAccumulator [as 別名]
def __init__(self):
        self.closed = False
        self._fa = FortunaAccumulator.FortunaAccumulator()
        self._ec = _EntropyCollector(self._fa)
        self.reinit() 
開發者ID:adde88,項目名稱:hostapd-mana,代碼行數:7,代碼來源:_UserFriendlyRNG.py

示例5: setUp

# 需要導入模塊: from Crypto.Random.Fortuna import FortunaAccumulator [as 別名]
# 或者: from Crypto.Random.Fortuna.FortunaAccumulator import FortunaAccumulator [as 別名]
def setUp(self):
        global FortunaAccumulator
        from Crypto.Random.Fortuna import FortunaAccumulator 
開發者ID:adde88,項目名稱:hostapd-mana,代碼行數:5,代碼來源:test_FortunaAccumulator.py

示例6: test_which_pools

# 需要導入模塊: from Crypto.Random.Fortuna import FortunaAccumulator [as 別名]
# 或者: from Crypto.Random.Fortuna.FortunaAccumulator import FortunaAccumulator [as 別名]
def test_which_pools(self):
        """FortunaAccumulator.which_pools"""

        # which_pools(0) should fail
        self.assertRaises(AssertionError, FortunaAccumulator.which_pools, 0)

        self.assertEqual(FortunaAccumulator.which_pools(1), [0])
        self.assertEqual(FortunaAccumulator.which_pools(2), [0, 1])
        self.assertEqual(FortunaAccumulator.which_pools(3), [0])
        self.assertEqual(FortunaAccumulator.which_pools(4), [0, 1, 2])
        self.assertEqual(FortunaAccumulator.which_pools(5), [0])
        self.assertEqual(FortunaAccumulator.which_pools(6), [0, 1])
        self.assertEqual(FortunaAccumulator.which_pools(7), [0])
        self.assertEqual(FortunaAccumulator.which_pools(8), [0, 1, 2, 3])
        for i in range(1, 32):
            self.assertEqual(FortunaAccumulator.which_pools(2L**i-1), [0])
            self.assertEqual(FortunaAccumulator.which_pools(2L**i), range(i+1))
            self.assertEqual(FortunaAccumulator.which_pools(2L**i+1), [0])
        self.assertEqual(FortunaAccumulator.which_pools(2L**31), range(32))
        self.assertEqual(FortunaAccumulator.which_pools(2L**32), range(32))
        self.assertEqual(FortunaAccumulator.which_pools(2L**33), range(32))
        self.assertEqual(FortunaAccumulator.which_pools(2L**34), range(32))
        self.assertEqual(FortunaAccumulator.which_pools(2L**35), range(32))
        self.assertEqual(FortunaAccumulator.which_pools(2L**36), range(32))
        self.assertEqual(FortunaAccumulator.which_pools(2L**64), range(32))
        self.assertEqual(FortunaAccumulator.which_pools(2L**128), range(32)) 
開發者ID:adde88,項目名稱:hostapd-mana,代碼行數:28,代碼來源:test_FortunaAccumulator.py


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