Browse Source

custom entropy in make_seed

283
ThomasV 11 years ago
parent
commit
b93cde14e7
  1. 26
      lib/wallet.py

26
lib/wallet.py

@ -1368,19 +1368,29 @@ class NewWallet(Deterministic_Wallet):
account = BIP32_Account({'xpub':xpub}) account = BIP32_Account({'xpub':xpub})
return account return account
def make_seed(self):
import mnemonic, ecdsa @classmethod
entropy = ecdsa.util.randrange( pow(2,160) ) def make_seed(self, custom_entropy=1):
import mnemonic
import ecdsa
import math
n = int(math.ceil(math.log(custom_entropy,2)))
n_added = max(16, 160-n)
print_error("make_seed: adding %d bits"%n_added)
my_entropy = ecdsa.util.randrange( pow(2, n_added) )
nonce = 0 nonce = 0
while True: while True:
ss = "%040x"%(entropy+nonce) s = "%x"% ( custom_entropy * (my_entropy + nonce))
s = hashlib.sha256(ss.decode('hex')).digest().encode('hex') if len(s) % 8:
# we keep only 13 words, that's approximately 139 bits of entropy s = "0"* (8 - len(s) % 8) + s
words = mnemonic.mn_encode(s)[0:13] words = mnemonic.mn_encode(s)
seed = ' '.join(words) seed = ' '.join(words)
# this removes 8 bits of entropy
if is_new_seed(seed): if is_new_seed(seed):
break # this will remove 8 bits of entropy break
nonce += 1 nonce += 1
print_error(seed)
return seed return seed
def prepare_seed(self, seed): def prepare_seed(self, seed):

Loading…
Cancel
Save