diff --git a/shared/random.py b/shared/random.py index 8507ff1e..75aa55a5 100644 --- a/shared/random.py +++ b/shared/random.py @@ -7,8 +7,8 @@ import ngu # use this instead of rand%n randbelow = ngu.random.uniform -# for bytes -bytes = ngu.random.bytes +# for bytes, use ngu.random.byte(len) +#bytes = ngu.random.bytes # In-place list shuffle using Fisher-Yates algo # diff --git a/shared/seed.py b/shared/seed.py index 212005a9..651fc9bd 100644 --- a/shared/seed.py +++ b/shared/seed.py @@ -505,11 +505,13 @@ async def ephemeral_seed_generate_from_dice(nwords): await set_ephemeral_seed_words(words, meta='Dice') def generate_seed(): - seed = random.bytes(32) + # Generate 32 bytes of best-quality high entropy TRNG bytes. + + seed = ngu.random.bytes(32) assert len(set(seed)) > 4 # TRNG failure - # hash to mitigate possible bias in TRNG - seed = ngu.hash.sha256s(seed) - return seed + + # hash to mitigate any possible bias in TRNG + return ngu.hash.sha256d(seed) async def make_new_wallet(nwords): # Pick a new random seed. diff --git a/shared/xor_seed.py b/shared/xor_seed.py index 79cfb3f3..170ab486 100644 --- a/shared/xor_seed.py +++ b/shared/xor_seed.py @@ -86,7 +86,7 @@ Otherwise, press OK to continue.'''.format(n=num_parts), escape='2') parts = [] for i in range(num_parts-1): if use_rng: - here = random.bytes(vlen) + here = ngu.random.bytes(vlen) assert len(set(here)) > 4 # TRNG failure? mask = ngu.hash.sha256d(here) else: