Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#ifndef SECP256K1_ECDH_H2#define SECP256K1_ECDH_H4#include "secp256k1.h"6#ifdef __cplusplus7extern "C" {8#endif10/** A pointer to a function that hashes an EC point to obtain an ECDH secret11*12* Returns: 1 if the point was successfully hashed.13* 0 will cause secp256k1_ecdh to fail and return 0.14* Other return values are not allowed, and the behaviour of15* secp256k1_ecdh is undefined for other return values.16* Out: output: pointer to an array to be filled by the function17* In: x32: pointer to a 32-byte x coordinate18* y32: pointer to a 32-byte y coordinate19* data: arbitrary data pointer that is passed through20*/21typedef int (*secp256k1_ecdh_hash_function)(22unsigned char *output,23const unsigned char *x32,24const unsigned char *y32,25void *data26);28/** An implementation of SHA256 hash function that applies to compressed public key.29* Populates the output parameter with 32 bytes. */30SECP256K1_API const secp256k1_ecdh_hash_function secp256k1_ecdh_hash_function_sha256;32/** A default ECDH hash function (currently equal to secp256k1_ecdh_hash_function_sha256).33* Populates the output parameter with 32 bytes. */34SECP256K1_API const secp256k1_ecdh_hash_function secp256k1_ecdh_hash_function_default;36/** Compute an EC Diffie-Hellman secret in constant time37*38* Returns: 1: exponentiation was successful39* 0: scalar was invalid (zero or overflow) or hashfp returned 040* Args: ctx: pointer to a context object.41* Out: output: pointer to an array to be filled by hashfp.42* In: pubkey: pointer to a secp256k1_pubkey containing an initialized public key.43* seckey: a 32-byte scalar with which to multiply the point.44* hashfp: pointer to a hash function. If NULL,45* secp256k1_ecdh_hash_function_sha256 is used46* (in which case, 32 bytes will be written to output).47* data: arbitrary data pointer that is passed through to hashfp48* (can be NULL for secp256k1_ecdh_hash_function_sha256).49*/50SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh(51const secp256k1_context *ctx,52unsigned char *output,53const secp256k1_pubkey *pubkey,54const unsigned char *seckey,55secp256k1_ecdh_hash_function hashfp,56void *data57) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);59#ifdef __cplusplus60}61#endif63#endif /* SECP256K1_ECDH_H */
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.