Decoding of a BIP39 phrase: why pbkdf2_hmac
and bip39 vs. Ian Coleman Bip39 Tool
When trying to convert a BIP39 sentence into a seed, the XPRV root key and the XPRV private key, you can find discrepancies between the PBKDF2_HMAC
tool output and the Ian Coleman BIP39 tool. In this article, we will deepen the differences and explore why these inconsistencies occur.
Understanding the sentences BIP39
BIP39 (Bitcoin 39 improvement proposal) is a standardized way to represent Bitcoin addresses in a man -readable format. A BIP39 phrase consists of words that, when concatenated and with hash using the Sha-256 (with a salt), produce the private key. The resulting sequence is divided into four parts: a prefix, a seed, an XPRV root and another XPRV root.
The function pbkdf2_hmac
The PBKDF2_HMAC
function, implemented in the Python Bitcoin Library (Bcrypt
, included in Bitcoin software), uses a password-based key derivation function (PBKDF) for HASH a pre-computed salt values table. This function can be used as a pre-processing step for BIP39 sentences.
However, pbkdf2_hmac
produces an output that is not the same as Ian Coleman’s BIP39 tool. There are several reasons for this:
* HASH SCHEME : PBKDF2_HMAC
uses the Sha-236 with a sentence-derived salt value, while Ian Coleman’s BIP39 tool generates its own salt values based on the input sentence.
* Salt Generation : While both tools generate salts, they can produce slightly different values. This can lead to differences in the resulting hash.
The Ian Coleman Bip39 tool
Ian Coleman’s BIP39 tool provides a more direct way to convert phrases to private keys, generating salt values directly from the input sentence and the hash using the Sha-256. The output is then divided into the seed, root XPRV and additional roots of XPRV.
Why the difference?
The differences arise from two main factors:
- Salt Generation : As mentioned earlier, both tools generate salts differently, which affects the final values of hash.
- Hash Scheme: The
pbkdf2_hmac 'function uses the sha-256 with a pre-computed table of sentence-derived values, while the Ian Coleman tool generates its own salt values based on the sentence input.
Conclusion
Although both tools can be used to convert BIP39 phrases to private keys, there are differences in their implementation. If you are working with multiple implementations or need more accurate control over the hash process, consider using a tool that adheres to the Ian Coleman method. However, for most purposes,pbkdf2_hmaccan still produce acceptable results.
Example Code
Here is an example of how you can use both tools:
Python
import bitcoin
BIP39 phrase
Phrase = “Prefer to offer puppy imitate pink banana, because the lyrics of whale thought of art”
Ian Coleman Bip39 Tool
Salt = bitcoin.crypto.geneate_salt (sentence)
Private_key = bitcoin.crypto.pbkdf2_hmac (salt, ‘0000’, 65536, sha_256)
Output for both tools can be different
Print (private_key.hex ())
must print a hash with the correct salt and output
Using 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 ‘))))
`
Remember that the actual output may vary due to differences in salt generation and hash schemes.
Leave a Reply