commit 1fe18ab1cedbed9cc4f296e563fec1b2bdaa5619
parent c4e4d8a1dd08932f6054b91ca5c02052ee2bbbc9
Author: ThomasV <thomasv@electrum.org>
Date: Sat, 6 Jan 2018 12:51:30 +0100
Merge pull request #3611 from SomberNight/mnemonic_enforce_num_words
avoid shorter seeds 'by luck'
Diffstat:
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/mnemonic.py b/lib/mnemonic.py
@@ -171,7 +171,10 @@ class Mnemonic(object):
n_custom = int(math.ceil(math.log(custom_entropy, 2)))
n = max(16, num_bits - n_custom)
print_error("make_seed", prefix, "adding %d bits"%n)
- my_entropy = ecdsa.util.randrange(pow(2, n))
+ my_entropy = 1
+ while my_entropy < pow(2, n - bpw):
+ # try again if seed would not contain enough words
+ my_entropy = ecdsa.util.randrange(pow(2, n))
nonce = 0
while True:
nonce += 1