<p>There are two separate processes:</p>
<ul>
<li>BIP39 specifies how to go from a phrase/mnemonic to a seed, using 2048 iterations of HMAC-SHA512.</li>
<li>BIP32 specifies how to go from a seed to a master key (using another single HMAC-SHA512) and then how to derive child keys from that master key.</li>
</ul>
<p>Perhaps you were missing that the master key is distinct from the seed, and that computing the xprv from the seed thus involves yet another HMAC-SHA512 step?</p>

CC BY-SA 4.0
2021-12-03T21:05:28.933Z
2021-12-03T21:05:28.933Z
Pieter Wuille
<p>I've followed the bip32 and bip39 specifications for generating the 512-bit seed, however I didn't understand how to generate the xpriv from this. I've used the left 256 bits for the private key and right 256 bits for the chain code, however my private key bytes and chaincode differs from the test vector:</p>
<p>Using 512-bit seed:
&quot;d71de856f81a8acc65e6fc851a38d4d7ec216fd0796d0a6827a3ad6ed5511a30fa280f12eb2e47ed2ac03b5c462a0358d18d69fe4f985ec81778c1b370b652a8&quot;</p>
<pre><code>Desired Master Private Key bytes: &quot;2fd0c70b975d9a38f84fba956ed795075fe43a85a45336143fe855551f1356db&quot;
Desired Chaincode: &quot;51fd417898af090d1a4dc040f4427a7e6a4ad5fd4024ace7f068a167861e8655&quot;
Desired Xpriv: &quot;xprv9s21ZrQH143K2shfP28KM3nr5Ap1SXjz8gc2rAqqMEynmjt6o1qboCDpxckqXavCwdnYds6yBHZGKHv7ef2eTXy461PXUjBFQg6PrwY4Gzq&quot;
</code></pre>
<p>How do I obtain these values using the left 256 bits for the pk, and the right 256 bits for the chaincode?</p>
<p>Thanks.</p>

CC BY-SA 4.0
2021-12-03T20:00:03.823Z
Which test vectors exactly does this test case come from?
Pieter Wuille
CC BY-SA 4.0
2021-12-03T20:10:56.143Z
https://github.com/trezor/python-mnemonic/blob/master/vectors.json (test 3)
I obtained the seed and words from the entropy, then derived the chaincode and seed using Nbitcoin
Chiru
CC BY-SA 4.0
2021-12-03T20:12:58.937Z
My question was basically, how to use the seed to get the master key bytes and chaincode, sorry if it wasn't very clear
Chiru
CC BY-SA 4.0
2021-12-03T20:14:22.773Z
You're aware that according to BIP32, you need to use HMAC-SHA512 on the seed to compute the master key (see this section: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#master-key-generation)
Pieter Wuille
CC BY-SA 4.0
2021-12-03T20:16:38.623Z
I used HMAC-SHA512 to derive the seed from the entropy, you're saying I would need to do it again?
Chiru
CC BY-SA 4.0
2021-12-03T20:18:39.570Z
Yes, read the link I gave.
Pieter Wuille
CC BY-SA 4.0
2021-12-03T20:21:56.037Z
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/132029/discussion-between-chiru-and-pieter-wuille).
Chiru
<bip32-hd-wallets>
How to get extended key from 512-bit seed?
Chiru
# How to get extended key from 512-bit seed?

(Asked by: username_0 on 2021-12-03)

I've followed the bip32 and bip39 specifications for generating the 512-bit seed, however I didn't understand how to generate the xpriv from this. I've used the left 256 bits for the private key and right 256 bits for the chain code, however my private key bytes and chaincode differs from the test vector:

Using 512-bit seed:
"d71de856f81a8acc65e6fc851a38d4d7ec216fd0796d0a6827a3ad6ed5511a30fa280f12eb2e47ed2ac03b5c462a0358d18d69fe4f985ec81778c1b370b652a8"

```
Desired Master Private Key bytes: "2fd0c70b975d9a38f84fba956ed795075fe43a85a45336143fe855551f1356db"
Desired Chaincode: "51fd417898af090d1a4dc040f4427a7e6a4ad5fd4024ace7f068a167861e8655"
Desired Xpriv: "xprv9s21ZrQH143K2shfP28KM3nr5Ap1SXjz8gc2rAqqMEynmjt6o1qboCDpxckqXavCwdnYds6yBHZGKHv7ef2eTXy461PXUjBFQg6PrwY4Gzq"

```

How do I obtain these values using the left 256 bits for the pk, and the right 256 bits for the chaincode?

Thanks.

**Tags:** bip32-hd-wallets

> **Comments:**
> **username_1**: Which test vectors exactly does this test case come from?  
> **username_0**: https://github.com/trezor/python-mnemonic/blob/master/vectors.json (test 3) I obtained the seed and words from the entropy, then derived the chaincode and seed using Nbitcoin  
> **username_0**: My question was basically, how to use the seed to get the master key bytes and chaincode, sorry if it wasn't very clear  
> **username_1**: You're aware that according to BIP32, you need to use HMAC-SHA512 on the seed to compute the master key (see this section: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#master-key-generation)  
> **username_0**: I used HMAC-SHA512 to derive the seed from the entropy, you're saying I would need to do it again?  
> **username_1**: Yes, read the link I gave.  
> **username_0**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/132029/discussion-between-username_0-and-username_1-username_1).  

---

## 1 answers

### Answer by username_1 on 2021-12-03. Score: 2

There are two separate processes:

* BIP39 specifies how to go from a phrase/mnemonic to a seed, using 2048 iterations of HMAC-SHA512.
* BIP32 specifies how to go from a seed to a master key (using another single HMAC-SHA512) and then how to derive child keys from that master key.

Perhaps you were missing that the master key is distinct from the seed, and that computing the xprv from the seed thus involves yet another HMAC-SHA512 step?


---

