make sure seed last word is uniformly distributed. count prefix length as entropy
This commit is contained in:
parent
7982cadd22
commit
569a3b4fab
@ -160,13 +160,14 @@ class Mnemonic(object):
|
|||||||
return i % custom_entropy == 0
|
return i % custom_entropy == 0
|
||||||
|
|
||||||
def make_seed(self, num_bits=128, prefix=version.SEED_PREFIX, custom_entropy=1):
|
def make_seed(self, num_bits=128, prefix=version.SEED_PREFIX, custom_entropy=1):
|
||||||
n = int(math.ceil(math.log(custom_entropy,2)))
|
# increase num_bits in order to obtain a uniform distibution for the last word
|
||||||
# bits of entropy used by the prefix
|
bpw = math.log(len(self.wordlist), 2)
|
||||||
k = len(prefix)*4
|
num_bits = int(math.ceil(num_bits/bpw)) * bpw
|
||||||
# we add at least 16 bits
|
# handle custom entropy; make sure we add at least 16 bits
|
||||||
n_added = max(16, k + num_bits - n)
|
n_custom = int(math.ceil(math.log(custom_entropy, 2)))
|
||||||
print_error("make_seed", prefix, "adding %d bits"%n_added)
|
n = max(16, num_bits - n_custom)
|
||||||
my_entropy = ecdsa.util.randrange( pow(2, n_added) )
|
print_error("make_seed", prefix, "adding %d bits"%n)
|
||||||
|
my_entropy = ecdsa.util.randrange(pow(2, n))
|
||||||
nonce = 0
|
nonce = 0
|
||||||
while True:
|
while True:
|
||||||
nonce += 1
|
nonce += 1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user