tfollow-up #4442 - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit ecf6ace975a2393696c43df6d00f46e6387fddcc DIR parent 469565c1881d3b73b065e3ce6092349523cda420 HTML Author: SomberNight <somber.night@protonmail.com> Date: Tue, 19 Jun 2018 19:26:13 +0200 follow-up #4442 Diffstat: M lib/bitcoin.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- DIR diff --git a/lib/bitcoin.py b/lib/bitcoin.py t@@ -540,12 +540,13 @@ def protect_against_invalid_ecpoint(func): # k = master private key (32 bytes) # c = master chain code (extra entropy for key derivation) (32 bytes) # n = the index of the key we want to derive. (only 32 bits will be used) -# If n is negative (i.e. the 32nd bit is set), the resulting private key's +# If n is hardened (i.e. the 32nd bit is set), the resulting private key's # corresponding public key can NOT be determined without the master private key. -# However, if n is positive, the resulting private key's corresponding +# However, if n is not hardened, the resulting private key's corresponding # public key can be determined without the master private key. @protect_against_invalid_ecpoint def CKD_priv(k, c, n): + if n < 0: raise ValueError('the bip32 index needs to be non-negative') is_prime = n & BIP32_PRIME return _CKD_priv(k, c, bfh(rev_hex(int_to_hex(n,4))), is_prime) t@@ -571,9 +572,10 @@ def _CKD_priv(k, c, s, is_prime): # c = master chain code # n = index of key we want to derive # This function allows us to find the nth public key, as long as n is -# non-negative. If n is negative, we need the master private key to find it. +# not hardened. If n is hardened, we need the master private key to find it. @protect_against_invalid_ecpoint def CKD_pub(cK, c, n): + if n < 0: raise ValueError('the bip32 index needs to be non-negative') if n & BIP32_PRIME: raise Exception() return _CKD_pub(cK, c, bfh(rev_hex(int_to_hex(n,4))))