1 #ifndef SECP256K1_ECDH_H
2 #define SECP256K1_ECDH_H
10 /** A pointer to a function that hashes an EC point to obtain an ECDH secret
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 of
15 * secp256k1_ecdh is undefined for other return values.
16 * Out: output: pointer to an array to be filled by the function
17 * In: x32: pointer to a 32-byte x coordinate
18 * y32: pointer to a 32-byte y coordinate
19 * data: arbitrary data pointer that is passed through
21 typedef int (*secp256k1_ecdh_hash_function)(
22 unsigned char *output,
23 const unsigned char *x32,
24 const unsigned char *y32,
28 /** An implementation of SHA256 hash function that applies to compressed public key.
29 * Populates the output parameter with 32 bytes. */
30 SECP256K1_API extern 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. */
34 SECP256K1_API extern const secp256k1_ecdh_hash_function secp256k1_ecdh_hash_function_default;
36 /** Compute an EC Diffie-Hellman secret in constant time
38 * Returns: 1: exponentiation was successful
39 * 0: scalar was invalid (zero or overflow) or hashfp returned 0
40 * Args: ctx: pointer to a context object (cannot be NULL)
41 * Out: output: pointer to an array to be filled by hashfp
42 * In: pubkey: a pointer to a secp256k1_pubkey containing an
43 * initialized public key
44 * seckey: a 32-byte scalar with which to multiply the point
45 * hashfp: pointer to a hash function. If NULL, secp256k1_ecdh_hash_function_sha256 is used
46 * (in which case, 32 bytes will be written to output)
47 * data: arbitrary data pointer that is passed through to hashfp
49 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh(
50 const secp256k1_context* ctx,
51 unsigned char *output,
52 const secp256k1_pubkey *pubkey,
53 const unsigned char *seckey,
54 secp256k1_ecdh_hash_function hashfp,
56 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
62 #endif /* SECP256K1_ECDH_H */