UltrafastSecp256k1 3.50.0
Ultra high-performance secp256k1 elliptic curve cryptography library
Loading...
Searching...
No Matches
hkdf.hpp
Go to the documentation of this file.
1#ifndef SECP256K1_HKDF_HPP
2#define SECP256K1_HKDF_HPP
3#pragma once
4
5// ============================================================================
6// HKDF-SHA256 (RFC 5869) + HMAC-SHA256
7// ============================================================================
8// Used by BIP-324 for key derivation from the ECDH shared secret.
9// Built on the existing SHA256 class — zero external dependencies.
10// ============================================================================
11
12#include <array>
13#include <cstdint>
14#include <cstddef>
15
16namespace secp256k1 {
17
18// -- HMAC-SHA256 --------------------------------------------------------------
19std::array<std::uint8_t, 32> hmac_sha256(
20 const std::uint8_t* key, std::size_t key_len,
21 const std::uint8_t* data, std::size_t data_len) noexcept;
22
23// -- HKDF-SHA256 Extract (RFC 5869 Section 2.2) ------------------------------
24// PRK = HMAC-SHA256(salt, IKM)
25// If salt is nullptr, uses a 32-byte zero string.
26std::array<std::uint8_t, 32> hkdf_sha256_extract(
27 const std::uint8_t* salt, std::size_t salt_len,
28 const std::uint8_t* ikm, std::size_t ikm_len) noexcept;
29
30// -- HKDF-SHA256 Expand (RFC 5869 Section 2.3) -------------------------------
31// OKM = T(1) || T(2) || ... truncated to out_len bytes
32// T(i) = HMAC-SHA256(PRK, T(i-1) || info || i)
33// out_len must be <= 255 * 32 = 8160 bytes.
34// Returns false if out_len is too large.
36 const std::uint8_t prk[32],
37 const std::uint8_t* info, std::size_t info_len,
38 std::uint8_t* out, std::size_t out_len) noexcept;
39
40} // namespace secp256k1
41
42#endif // SECP256K1_HKDF_HPP
std::array< std::uint8_t, 32 > hmac_sha256(const std::uint8_t *key, std::size_t key_len, const std::uint8_t *data, std::size_t data_len) noexcept
std::array< std::uint8_t, 32 > hkdf_sha256_extract(const std::uint8_t *salt, std::size_t salt_len, const std::uint8_t *ikm, std::size_t ikm_len) noexcept
bool hkdf_sha256_expand(const std::uint8_t prk[32], const std::uint8_t *info, std::size_t info_len, std::uint8_t *out, std::size_t out_len) noexcept