mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-27 16:48:09 +00:00
54f1599a5a
This clarifies the intent: the project is licenced under terms of LGPL version 3 only, but the standard headers cover only "3 or later", so we had to rewrite them. In the same step, we removed author information from individual files in favor of "SatoshiLabs and contributors", and include an AUTHORS file that lists the contributors. Apologies to those whose names are missing; please contact us if you wish to add your info to the AUTHORS file.
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
# This file is part of the Trezor project.
|
|
#
|
|
# Copyright (C) 2012-2018 SatoshiLabs and contributors
|
|
#
|
|
# This library is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
# as published by the Free Software Foundation.
|
|
#
|
|
# This library is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Lesser General Public License for more details.
|
|
#
|
|
# You should have received a copy of the License along with this library.
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
|
|
|
import math
|
|
from .common import TrezorTest
|
|
|
|
import trezorlib.messages as proto
|
|
|
|
|
|
def entropy(data):
|
|
counts = {}
|
|
for c in data:
|
|
if c in counts:
|
|
counts[c] += 1
|
|
else:
|
|
counts[c] = 1
|
|
e = 0
|
|
for _, v in counts.items():
|
|
p = 1.0 * v / len(data)
|
|
e -= p * math.log(p, 256)
|
|
return e
|
|
|
|
|
|
class TestMsgGetentropy(TrezorTest):
|
|
|
|
def test_entropy(self):
|
|
for l in [0, 1, 2, 3, 4, 5, 8, 9, 16, 17, 32, 33, 64, 65, 128, 129, 256, 257, 512, 513, 1024]:
|
|
with self.client:
|
|
self.client.set_expected_responses([proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall), proto.Entropy()])
|
|
ent = self.client.get_entropy(l)
|
|
assert len(ent) == l
|
|
print('entropy = ', entropy(ent))
|