Browse Source

remove custom entropy option again (follow-up e0c38b3), because seeds can be extended with passphrase

3.2.x
ThomasV 7 years ago
parent
commit
5e5134b76f
  1. 12
      lib/commands.py
  2. 23
      lib/mnemonic.py

12
lib/commands.py

@ -159,19 +159,13 @@ class Commands:
return True return True
@command('') @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""" """Create a seed"""
from .mnemonic import Mnemonic from .mnemonic import Mnemonic
t = 'segwit' if segwit else 'standard' 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 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') @command('n')
def getaddresshistory(self, address): def getaddresshistory(self, address):
"""Return the transaction history of any address. Note: This is a """Return the transaction history of any address. Note: This is a
@ -697,7 +691,6 @@ command_options = {
'from_addr': ("-F", "Source address (must be a wallet address; use sweep to spend from non-wallet address)."), '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"), '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"), 'nbits': (None, "Number of bits of entropy"),
'entropy': (None, "Custom entropy"),
'segwit': (None, "Create segwit seed"), 'segwit': (None, "Create segwit seed"),
'language': ("-L", "Default language for wordlist"), 'language': ("-L", "Default language for wordlist"),
'privkey': (None, "Private key. Set to '?' to get a prompt."), 'privkey': (None, "Private key. Set to '?' to get a prompt."),
@ -726,7 +719,6 @@ arg_types = {
'nbits': int, 'nbits': int,
'imax': int, 'imax': int,
'year': int, 'year': int,
'entropy': int,
'tx': tx_from_str, 'tx': tx_from_str,
'pubkeys': json_loads, 'pubkeys': json_loads,
'jsontx': json_loads, 'jsontx': json_loads,

23
lib/mnemonic.py

@ -157,28 +157,21 @@ class Mnemonic(object):
i = i*n + k i = i*n + k
return i return i
def check_seed(self, seed, custom_entropy): def make_seed(self, seed_type='standard', num_bits=132):
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):
prefix = version.seed_prefix(seed_type) prefix = version.seed_prefix(seed_type)
# increase num_bits in order to obtain a uniform distibution for the last word # increase num_bits in order to obtain a uniform distibution for the last word
bpw = math.log(len(self.wordlist), 2) bpw = math.log(len(self.wordlist), 2)
num_bits = int(math.ceil(num_bits/bpw) * bpw) # rounding
# handle custom entropy; make sure we add at least 16 bits n = int(math.ceil(num_bits/bpw) * bpw)
n_custom = int(math.ceil(math.log(custom_entropy, 2))) print_error("make_seed. prefix: '%s'"%prefix, "entropy: %d bits"%n)
n = max(16, num_bits - n_custom) entropy = 1
print_error("make_seed", prefix, "adding %d bits"%n) while entropy < pow(2, n - bpw):
my_entropy = 1
while my_entropy < pow(2, n - bpw):
# try again if seed would not contain enough words # 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 nonce = 0
while True: while True:
nonce += 1 nonce += 1
i = custom_entropy * (my_entropy + nonce) i = entropy + nonce
seed = self.mnemonic_encode(i) seed = self.mnemonic_encode(i)
assert i == self.mnemonic_decode(seed) assert i == self.mnemonic_decode(seed)
if is_old_seed(seed): if is_old_seed(seed):

Loading…
Cancel
Save