1
0

Revert "remove custom entropy option; nobody uses it"

This reverts commit e0c38b31b4.
This commit is contained in:
ThomasV
2016-10-20 10:22:17 +02:00
parent b907018a25
commit 9285a7198e
2 changed files with 21 additions and 5 deletions

View File

@@ -154,16 +154,24 @@ class Mnemonic(object):
i = i*n + k
return i
def make_seed(self, num_bits=128, prefix=version.SEED_PREFIX):
def check_seed(self, seed, custom_entropy):
assert is_new_seed(seed)
i = self.mnemonic_decode(seed)
return i % custom_entropy == 0
def make_seed(self, num_bits=128, prefix=version.SEED_PREFIX, custom_entropy=1):
# increase num_bits in order to obtain a uniform distibution for the last word
bpw = math.log(len(self.wordlist), 2)
n = int(math.ceil(num_bits/bpw)) * bpw
num_bits = int(math.ceil(num_bits/bpw)) * bpw
# handle custom entropy; make sure we add at least 16 bits
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))
nonce = 0
while True:
nonce += 1
i = my_entropy + nonce
i = custom_entropy * (my_entropy + nonce)
seed = self.mnemonic_encode(i)
assert i == self.mnemonic_decode(seed)
if is_old_seed(seed):