def test_several_lengths(self): prng = SHAKE128.new().update(b('Test')) for length in range(1, 100): base = Integer.from_bytes(prng.read(length)) modulus2 = Integer.from_bytes(prng.read(length)) | 1 exponent2 = Integer.from_bytes(prng.read(length)) expected = pow(base, exponent2, modulus2) result = monty_pow(base, exponent2, modulus2) self.assertEqual(result, expected)
def new_test(self, data=data, result=tv.md): hobj = SHAKE128.new(data=data) digest = hobj.read(len(result)) self.assertEqual(digest, result)
def get_tag_random(tag, length): return SHAKE128.new(data=tobytes(tag)).read(length)
def create_rng(tag): rng = StrongRandom(SHAKE128.new(data=tag)) return rng
def get_fixed_prng(): return SHAKE128.new().update(b("SEED")).read
# # The image size is 640x480. My PS3 Eye cam only hase 1 byte per pixel # of color depth, which is 307,200 bytes per frame. # # The raw entropy of each frame, with the camera cooled to 20 degrees # Celsius and no light entering the lens, is about 0.11 bits per byte, # +/- 0.02 bits per byte. This provides about 33,792-bits of entropy # per frame, or 4,224 bytes per frame. # # The security margin of SHAKE128 is the min(d/2, 128), where "d" is # our digest. So by outputting 4096 bytes, my collision security margin # is between 128-bits to 32,768-bits with SHAKE128. Preimage and 2nd # preimage collision resistance will have the full 4,096 bytes. # # The XOF hashes all 307,200 bytes but outputs a conservative 4 KB. shake = SHAKE128.new(data=key) shake.update(bytes(frame)) digest = shake.read(32+4096) # 32-byte key, 4096-byte output # Fast key erasure - https://blog.cr.yp.to/20170723-random.html # Ensures that if two frames are ever exactly identical, they will be # keyed differently, ensuring unique outputs key = digest[:32] data = digest[32:] cv2.imshow('webcam noise', frame) if cv2.waitKey(1) & 0xff == 27: break fifo.write(data) fifo.flush()