2018-02-02 17:29:52 +00:00
|
|
|
#!/usr/bin/env python3
|
2017-02-28 18:11:00 +00:00
|
|
|
# example usage: ./rng_entropy_collector.py stm32_rng_1.dat 1048576
|
|
|
|
# note: for reading large amounts of entropy, compile a firmware
|
|
|
|
# that has DEBUG_RNG == 1 as that will disable the user button
|
|
|
|
# push confirmation
|
|
|
|
|
|
|
|
import io
|
|
|
|
import sys
|
2019-02-27 03:07:32 +00:00
|
|
|
from trezorlib import misc, ui
|
2017-02-28 18:11:00 +00:00
|
|
|
from trezorlib.client import TrezorClient
|
2018-03-05 16:30:44 +00:00
|
|
|
from trezorlib.transport import get_transport
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2017-02-28 18:11:00 +00:00
|
|
|
|
|
|
|
def main():
|
2018-03-05 16:30:44 +00:00
|
|
|
try:
|
2019-02-27 03:07:32 +00:00
|
|
|
client = TrezorClient(get_transport(), ui=ui.ClickUI())
|
2018-03-05 16:30:44 +00:00
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
2017-02-28 18:11:00 +00:00
|
|
|
return
|
|
|
|
|
2017-06-23 19:31:42 +00:00
|
|
|
arg1 = sys.argv[1] # output file
|
|
|
|
arg2 = int(sys.argv[2], 10) # total number of how many bytes of entropy to read
|
|
|
|
step = 1024 if arg2 >= 1024 else arg2 # trezor will only return 1KB at a time
|
2017-02-28 18:11:00 +00:00
|
|
|
|
|
|
|
with io.open(arg1, 'wb') as f:
|
2018-02-02 17:29:52 +00:00
|
|
|
for i in range(0, arg2, step):
|
2019-02-27 03:07:32 +00:00
|
|
|
entropy = misc.get_entropy(client, step)
|
2017-02-28 18:11:00 +00:00
|
|
|
f.write(entropy)
|
|
|
|
|
|
|
|
client.close()
|
|
|
|
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2017-02-28 18:11:00 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|