1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-18 10:32:02 +00:00

test_entropy does not need load_device

This commit is contained in:
Pavol Rusnak 2014-02-06 00:34:58 +01:00
parent 1716093dbb
commit 07137cae91

View File

@ -5,27 +5,21 @@ import math
from trezorlib import messages_pb2 as messages from trezorlib import messages_pb2 as messages
def entropy(data): def entropy(data):
counts = {}
for c in data:
if c in counts:
counts[c] += 1
else:
counts[c] = 1
e = 0 e = 0
for i in range(256): for k,v in counts.iteritems():
p = 0 p = 1.0 * v / len(data)
for c in data:
if ord(c) == i:
p += 1
if p == 0:
continue
p = 1.0 * p / len(data)
e -= p * math.log(p, 256) e -= p * math.log(p, 256)
return e return e
class TestEntropy(common.TrezorTest): class TestEntropy(common.TrezorTest):
def test_entropy(self): def test_entropy(self):
self.client.load_device_by_mnemonic(mnemonic=self.mnemonic1,
pin='',
passphrase_protection=False,
label='test',
language='english')
for l in [0, 1, 2, 3, 4, 5, 8, 9, 16, 17, 32, 33, 64, 65, 128, 129, 256, 257, 512, 513, 1024]: for l in [0, 1, 2, 3, 4, 5, 8, 9, 16, 17, 32, 33, 64, 65, 128, 129, 256, 257, 512, 513, 1024]:
ent = self.client.get_entropy(l) ent = self.client.get_entropy(l)
self.assertTrue(len(ent) >= l) self.assertTrue(len(ent) >= l)