user137492: In the open source (https://github.com/bitcoin/bitcoin/tree/master/src/crypto) there are these algrithms that as I know connected with gerenation the new keys and master key. So I try to understand what exactly each algorithm does and how they related in Bitcoin Core.

user137501: HMAC in the name stands for "Hash-based Message Authentication Code" and the hmac_sha_512 is used to generate keys in hierarchic-deterministic BIP-0032 wallets, and to generate a master key from the seed phrase (BIP-0039), for example here.
HKDF in the name stands for "Hash-based Key-Derivation Function", and there's a comment in the code which describes it:

A rfc5869 HKDF implementation with HMAC_SHA256 and fixed key output length of 32 bytes (L=32)

If you look at rfc5869 specification, it uses some HMAC as a primitive in the key derivation scheme, and in hkdf_sha256 the hmac_sha_256 is the primitive i.e. hmac_sha_256 is used for hkdf_sha256. The hmac_sha_256 is also used in httprpc.cpp and torcontrol.cpp.
But what is hkdf_sha256 used for? It doesn't seem to be used anywhere.

user208: They implement 3 distinct cryptographic schemes:

HMAC-SHA256 is a MAC (message authentication code, or a keyed hash function) based on SHA-256. It is used in the RFC6979 nonce generation function for deterministic ECDSA signing.
HMAC-SHA512 is a MAC based on SHA-512. It is used in the BIP32 key derivation logic.
HKDF-SHA256 is a (symmetric) key derivation function (KDF) based on HMAC-256. It is currently unused, but was added in anticipation of being used in the BIP324 (v2 P2P transport layer) implementation.


137492: <p>In the open source (<a href="https://github.com/bitcoin/bitcoin/tree/master/src/crypto" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/tree/master/src/crypto</a>) there are these algrithms that as I know connected with gerenation the new keys and master key. So I try to understand what exactly each algorithm does and how they related in Bitcoin Core.</p>
 137501: <p>HMAC in the name stands for <a href="https://en.wikipedia.org/wiki/HMAC" rel="nofollow noreferrer">&quot;<strong>H</strong>ash-based <strong>M</strong>essage <strong>A</strong>uthentication <strong>C</strong>ode&quot;</a> and the hmac_sha_512 is used to <a href="https://en.bitcoin.it/wiki/BIP_0032#Specification:_Key_derivation" rel="nofollow noreferrer">generate keys</a> in hierarchic-deterministic BIP-0032 wallets, and to <a href="https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki#from-mnemonic-to-seed" rel="nofollow noreferrer">generate a master key</a> from the seed phrase (BIP-0039), for example <a href="https://github.com/bitcoin/bitcoin/blob/93999a5fbe317852307455b6a42d137cc08a0edc/src/key.cpp#L348" rel="nofollow noreferrer">here</a>.</p>
<p>HKDF in the name stands for <a href="https://su21.cs161.org/proj2/crypto/hkdf.html" rel="nofollow noreferrer">&quot;<strong>H</strong>ash-based <strong>K</strong>ey-<strong>D</strong>erivation <strong>F</strong>unction&quot;</a>, and there's a comment in the code which describes it:</p>
<blockquote>
<p>A rfc5869 HKDF implementation with HMAC_SHA256 and fixed key output length of 32 bytes (L=32)</p>
</blockquote>
<p>If you look at <a href="https://www.rfc-editor.org/rfc/rfc5869" rel="nofollow noreferrer">rfc5869 specification</a>, it uses some HMAC as a primitive in the key derivation scheme, and in <code>hkdf_sha256</code> the <code>hmac_sha_256</code> is the primitive i.e. <code>hmac_sha_256</code> is used for <code>hkdf_sha256</code>. The <code>hmac_sha_256</code> is also used in <a href="https://github.com/bitcoin/bitcoin/blob/0de36941eca1bff91420dd878eb097db2b1a596c/src/httprpc.cpp#L113" rel="nofollow noreferrer">httprpc.cpp</a> and <a href="https://github.com/bitcoin/bitcoin/blob/6dc3084eec912cf2abfe18d1c05655defaa45e20/src/torcontrol.cpp#L481" rel="nofollow noreferrer">torcontrol.cpp</a>.</p>
<p>But what is <code>hkdf_sha256</code> used for? It <a href="https://github.com/bitcoin/bitcoin/search?q=CHKDF_HMAC_SHA256_L32" rel="nofollow noreferrer">doesn't seem to be used anywhere</a>.</p>
 208: <p>They implement 3 distinct cryptographic schemes:</p>
<ul>
<li><code>HMAC-SHA256</code> is a MAC (message authentication code, or a keyed hash function) based on SHA-256. It is used in the RFC6979 nonce generation function for deterministic ECDSA signing.</li>
<li><code>HMAC-SHA512</code> is a MAC based on SHA-512. It is used in the BIP32 key derivation logic.</li>
<li><code>HKDF-SHA256</code> is a (symmetric) key derivation function (KDF) based on HMAC-256. It is currently unused, but was added in anticipation of being used in the BIP324 (v2 P2P transport layer) implementation.</li>
</ul>
