@@ -25,6 +25,22 @@ typedef int (*secp256k1_ecdh_hash_function)(
25
25
void * data
26
26
);
27
27
28
+ /** A pointer to a function that hashes an X coordinate to obtain an ECDH secret
29
+ *
30
+ * Returns: 1 if the point was successfully hashed.
31
+ * 0 will cause secp256k1_ecdh_xonly to fail and return 0.
32
+ * Other return values are not allowed, and the behaviour of
33
+ * secp256k1_ecdh_xonly is undefined for other return values.
34
+ * Out: output: pointer to an array to be filled by the function
35
+ * In: x32: pointer to a 32-byte x coordinate
36
+ * data: arbitrary data pointer that is passed through
37
+ */
38
+ typedef int (* secp256k1_ecdh_xonly_hash_function )(
39
+ unsigned char * output ,
40
+ const unsigned char * x32 ,
41
+ void * data
42
+ );
43
+
28
44
/** An implementation of SHA256 hash function that applies to compressed public key.
29
45
* Populates the output parameter with 32 bytes. */
30
46
SECP256K1_API const secp256k1_ecdh_hash_function secp256k1_ecdh_hash_function_sha256 ;
@@ -33,6 +49,10 @@ SECP256K1_API const secp256k1_ecdh_hash_function secp256k1_ecdh_hash_function_sh
33
49
* Populates the output parameter with 32 bytes. */
34
50
SECP256K1_API const secp256k1_ecdh_hash_function secp256k1_ecdh_hash_function_default ;
35
51
52
+ /** An implementation of SHA256 hash function that applies to the X coordinate.
53
+ * Populates the output parameter with 32 bytes. */
54
+ SECP256K1_API const secp256k1_ecdh_xonly_hash_function secp256k1_ecdh_xonly_hash_function_sha256 ;
55
+
36
56
/** Compute an EC Diffie-Hellman secret in constant time
37
57
*
38
58
* Returns: 1: exponentiation was successful
@@ -56,6 +76,33 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh(
56
76
void * data
57
77
) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
58
78
79
+ /** Compute an EC X-only Diffie-Hellman secret in constant time
80
+ *
81
+ * Returns: 1: exponentiation was successful
82
+ * 0: scalar was invalid (zero or overflow), input is not a valid X coordinate, or hashfp
83
+ * returned 0.
84
+ * Args: ctx: pointer to a context object.
85
+ * Out: output: pointer to an array to be filled by hashfp.
86
+ * In: xpubkey: a pointer to the 32-byte serialization of an x-only public key (see the
87
+ * extrakeys module for details).
88
+ * seckey: a 32-byte scalar with which to multiply the point.
89
+ * hashfp: pointer to a hash function. If NULL,
90
+ * secp256k1_ecdh_xonly+hash_function_sha256 is used
91
+ * (in which case, 32 bytes will be written to output).
92
+ * data: arbitrary data pointer that is passed through to hashfp
93
+ * (can be NULL for secp256k1_ecdh_xonly_hash_function_sha256).
94
+ *
95
+ * The function is constant time in seckey. It is not constant time in xpubkey, hashfp, or the output.
96
+ */
97
+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh_xonly (
98
+ const secp256k1_context * ctx ,
99
+ unsigned char * output ,
100
+ const unsigned char * xpubkey ,
101
+ const unsigned char * seckey ,
102
+ secp256k1_ecdh_xonly_hash_function hashfp ,
103
+ void * data
104
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
105
+
59
106
#ifdef __cplusplus
60
107
}
61
108
#endif
0 commit comments