remove random.bytes, use ngu.random.bytes directly instead

This commit is contained in:
Peter D. Gray 2024-01-10 11:35:27 -05:00
parent d31fee5d22
commit 024655be6b
No known key found for this signature in database
GPG Key ID: A2DCD558C2BE5D7C
3 changed files with 9 additions and 7 deletions

View File

@ -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
#

View File

@ -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.

View File

@ -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: