Catégories
CRYPTOCURRENCY

Bitcoin: python « pbkdf2_hmac » function doesn’t return same as Ian Coleman BIP39 tool. Why?

Decoding of a BIP39 sentence: why pbkdf2_hmac and bip39 vs. the bip39 tool of Ian Coleman

When you get attached to converting a beep39 in this article,

Understand the BIP39 sentences

BIP39 (Bitcoin Improvement proposal 39) is a standardized means of representing Bitcoin addresses in a format refers to humans. A BIP39 sentence consists of words which, when crushed and chopped using SHA-256 (with a salt), produce the product key. A prefix, an XPRV root and another XPRV root.

** The function pbkdf2_hmac

The pbkdf2_hmacfunction, implemented in the Python Bitcoin library (Bcrypt, which is included with Bitcoin software), uses a password keyword derivation function (PBKDF) to have a precomputious table of salt values . This function can be used

However,pbkdf2_hmacproduces an output that is not the same thing as the BIP39 tool from Ian Coleman. There are several reasons for this:

* hash diagram :pbkdf2_hmacuses Sha-256 with a salt value derived from the sentence itself, where

* Generation of salt

: Although the two tools generate salts, they can produce slightly different values. This could result in differences in the resulting hash.

The Ian Coleman BIP39 tool

Ian Coleman's BIP39 tool offers a simpler way to convert sentences into private keys by generating salt values ​​directly from the input The output is then divided into seeds, XPRV root and additional XPRV roots.

** Why the difference?

The differences arise from two main factors:

1 and 1

2

Conclusion

BIP39 sentences in private keys, there are differences in their implementation. If you, however, for most of the purposes,pbkdf2_hmaccould still produce acceptable results.

Code example

Here is an example of how you can use both tools:

Python

Bitcoin Import

Bitcoin: python

BIP39 sentence

sentence = "prefabricated puppy equipment imitates pink banana because the whale letter thought of noisy illustrations"

Ian Coleman BIP39 tool

Salt = bitcoin.crypto.generate_salt (sentence)

private_key = bitcoin.crypto.pbkdf2_hmac (salt, '0000', 65536, sha_256)

The output of the two tools may be different

Print (Private_Key.hex ())

should print a hatch with salt and correct output

Use of Ian Coleman's method to get the seed

Seed = int.from_bytes (bitcoin.crypto.pbkdf2_hmac (b'0000 ', phrase.encode (), 65536, sha_256) .Hex (),' Big ')

` ‘

.

BITCOIN OPEN CHANNELS WITH

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *