Skip to content

Commit

Permalink
remove custom entropy option again (follow-up e0c38b3), because seeds…
Browse files Browse the repository at this point in the history
… can be extended with passphrase
  • Loading branch information
ecdsa committed Mar 14, 2018
1 parent 0f5cabc commit 5e5134b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
12 changes: 2 additions & 10 deletions lib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,13 @@ def setconfig(self, key, value):
return True

@command('')
def make_seed(self, nbits=132, entropy=1, language=None, segwit=False):
def make_seed(self, nbits=132, language=None, segwit=False):
"""Create a seed"""
from .mnemonic import Mnemonic
t = 'segwit' if segwit else 'standard'
s = Mnemonic(language).make_seed(t, nbits, custom_entropy=entropy)
s = Mnemonic(language).make_seed(t, nbits)
return s

@command('')
def check_seed(self, seed, entropy=1, language=None):
"""Check that a seed was generated with given entropy"""
from .mnemonic import Mnemonic
return Mnemonic(language).check_seed(seed, entropy)

@command('n')
def getaddresshistory(self, address):
"""Return the transaction history of any address. Note: This is a
Expand Down Expand Up @@ -697,7 +691,6 @@ def help(self):
'from_addr': ("-F", "Source address (must be a wallet address; use sweep to spend from non-wallet address)."),
'change_addr': ("-c", "Change address. Default is a spare address, or the source address if it's not in the wallet"),
'nbits': (None, "Number of bits of entropy"),
'entropy': (None, "Custom entropy"),
'segwit': (None, "Create segwit seed"),
'language': ("-L", "Default language for wordlist"),
'privkey': (None, "Private key. Set to '?' to get a prompt."),
Expand Down Expand Up @@ -726,7 +719,6 @@ def help(self):
'nbits': int,
'imax': int,
'year': int,
'entropy': int,
'tx': tx_from_str,
'pubkeys': json_loads,
'jsontx': json_loads,
Expand Down
23 changes: 8 additions & 15 deletions lib/mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,28 +157,21 @@ def mnemonic_decode(self, seed):
i = i*n + k
return i

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, seed_type='standard', num_bits=132, custom_entropy=1):
def make_seed(self, seed_type='standard', num_bits=132):
prefix = version.seed_prefix(seed_type)
# increase num_bits in order to obtain a uniform distibution for the last word
bpw = math.log(len(self.wordlist), 2)
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 = 1
while my_entropy < pow(2, n - bpw):
# rounding
n = int(math.ceil(num_bits/bpw) * bpw)
print_error("make_seed. prefix: '%s'"%prefix, "entropy: %d bits"%n)
entropy = 1
while entropy < pow(2, n - bpw):
# try again if seed would not contain enough words
my_entropy = ecdsa.util.randrange(pow(2, n))
entropy = ecdsa.util.randrange(pow(2, n))
nonce = 0
while True:
nonce += 1
i = custom_entropy * (my_entropy + nonce)
i = entropy + nonce
seed = self.mnemonic_encode(i)
assert i == self.mnemonic_decode(seed)
if is_old_seed(seed):
Expand Down

0 comments on commit 5e5134b

Please sign in to comment.