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.
2 Answers
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.
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.