Ejemplo n.º 1
0
    def testPRNGGetSetState(self):
        r = skein.Random(b"123", hasher=self.HASHER)
        r.random()
        r.gauss(0, 1)
        state = r.getstate()
        a = r.random()
        b = r.gauss(0, 1)

        r = skein.Random(b"123", hasher=self.HASHER)
        r.setstate(state)
        self.assertEqual(r.random(), a)
        self.assertEqual(r.gauss(0, 1), b)
Ejemplo n.º 2
0
 def test_getrandombits(self):
     r = skein.Random()
     for k in range(16):
         for _ in range(1000):
             x = r.getrandbits(k)
             self.assertGreaterEqual(x, 0)
             self.assertLess(x, 1 << k)
Ejemplo n.º 3
0
 def testPRNGStateInspection(self):
     r = skein.Random(b"x", hasher=self.HASHER)
     # check initial state
     state = r._state
     d = self.HASHER(bytes(self.STATE_BITS // 8) + b"x").digest()
     self.assertEqual(state, d)
     # check state after random() call
     r.random()
     t = skein.threefish(state, bytes(15) + bytes([63]))
     d = t.encrypt_block(bytes(self.STATE_BITS // 8))
     self.assertEqual(r._state, d)
Ejemplo n.º 4
0
 def testPRNGRandomStream(self):
     for i in range(0, 5000, 13):
         r = skein.Random(b"abc")
         self.assertEqual(
             r.read(i) + r.read(5000 - i),
             skein.Random(b"abc").read(5000))
Ejemplo n.º 5
0
 def testPRNGInit(self):
     skein.Random(hasher=self.HASHER)
     skein.Random(seed=42, hasher=self.HASHER)
     skein.Random(frozenset({1, 2, 3}), hasher=self.HASHER)
     skein.Random("str", hasher=self.HASHER)