Skip to content

Commit 13eb92a

Browse files
committed
Add ECDSA adaptor signature APIs
This commit adds the ECDSA adaptor signature APIs: - Encrypted Signing Creates an adaptor signature, which includes a proof to verify the adaptor signature. - Encryption Verification Verifies that the adaptor decryption key can be extracted from the adaptor signature and the completed ECDSA signature. - Signature Decryption Derives an ECDSA signature from an adaptor signature and an adaptor decryption key. - Key Recovery Extracts the adaptor decryption key from the complete signature and the adaptor signature.
1 parent 4a470f0 commit 13eb92a

File tree

2 files changed

+392
-0
lines changed

2 files changed

+392
-0
lines changed

include/secp256k1_ecdsa_adaptor.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,104 @@ typedef int (*secp256k1_nonce_function_hardened_ecdsa_adaptor)(
5151
*/
5252
SECP256K1_API extern const secp256k1_nonce_function_hardened_ecdsa_adaptor secp256k1_nonce_function_ecdsa_adaptor;
5353

54+
/** Encrypted Signing
55+
*
56+
* Creates an adaptor signature, which includes a proof to verify the adaptor
57+
* signature.
58+
*
59+
* Returns: 1 on success, 0 on failure
60+
* Args: ctx: a secp256k1 context object, initialized for signing
61+
* (cannot be NULL)
62+
* Out: adaptor_sig162: pointer to 162 byte to store the returned signature
63+
* (cannot be NULL)
64+
* In: seckey32: pointer to 32 byte secret key that will be used for
65+
* signing (cannot be NULL)
66+
* enckey: pointer to the encryption public key (cannot be NULL)
67+
* msg32: pointer to the 32-byte message to sign (cannot be NULL)
68+
* noncefp: pointer to a nonce generation function. If NULL,
69+
* secp256k1_nonce_function_ecdsa_adaptor is used
70+
* ndata: pointer to arbitrary data used by the nonce generation
71+
* function (can be NULL). If it is non-NULL and
72+
* secp256k1_nonce_function_ecdsa_adaptor is used, then
73+
* ndata must be a pointer to 32-byte auxiliary randomness
74+
* as per BIP-340.
75+
*/
76+
SECP256K1_API int secp256k1_ecdsa_adaptor_encrypt(
77+
const secp256k1_context* ctx,
78+
unsigned char *adaptor_sig162,
79+
unsigned char *seckey32,
80+
const secp256k1_pubkey *enckey,
81+
const unsigned char *msg32,
82+
secp256k1_nonce_function_hardened_ecdsa_adaptor noncefp,
83+
void *ndata
84+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5);
85+
86+
/** Encryption Verification
87+
*
88+
* Verifies that the adaptor decryption key can be extracted from the adaptor signature
89+
* and the completed ECDSA signature.
90+
*
91+
* Returns: 1 on success, 0 on failure
92+
* Args: ctx: a secp256k1 context object, initialized for verification
93+
* (cannot be NULL)
94+
* In: adaptor_sig162: pointer to 162-byte signature to verify (cannot be NULL)
95+
* pubkey: pointer to the public key corresponding to the secret key
96+
* used for signing (cannot be NULL)
97+
* msg32: pointer to the 32-byte message (cannot be NULL)
98+
* enckey: pointer to the adaptor encryption public key (cannot be NULL)
99+
*/
100+
SECP256K1_API int secp256k1_ecdsa_adaptor_verify(
101+
const secp256k1_context* ctx,
102+
const unsigned char *adaptor_sig162,
103+
const secp256k1_pubkey *pubkey,
104+
const unsigned char *msg32,
105+
const secp256k1_pubkey *enckey
106+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5);
107+
108+
/** Signature Decryption
109+
*
110+
* Derives an ECDSA signature from an adaptor signature and an adaptor decryption key.
111+
*
112+
* Returns: 1 on success, 0 on failure
113+
* Args: ctx: a secp256k1 context object (cannot be NULL)
114+
* Out: sig: pointer to the ECDSA signature to create (cannot
115+
* be NULL)
116+
* In: deckey32: pointer to 32-byte decryption secret key for the adaptor
117+
* encryption public key (cannot be NULL)
118+
* adaptor_sig162: pointer to 162-byte byte adaptor sig (cannot be NULL)
119+
*/
120+
SECP256K1_API int secp256k1_ecdsa_adaptor_decrypt(
121+
const secp256k1_context* ctx,
122+
secp256k1_ecdsa_signature *sig,
123+
const unsigned char *deckey32,
124+
const unsigned char *adaptor_sig162
125+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
126+
127+
/** Decryption Key Recovery
128+
*
129+
* Extracts the adaptor decryption key from the complete signature and the adaptor
130+
* signature.
131+
*
132+
* Returns: 1 on success, 0 on failure
133+
* Args: ctx: a secp256k1 context object, initialized for signing
134+
* (cannot be NULL)
135+
* Out: deckey32: pointer to 32-byte adaptor decryption key for the adaptor
136+
* encryption public key (cannot be NULL)
137+
* In: sig: pointer to ECDSA signature to recover the adaptor decryption
138+
* key from (cannot be NULL)
139+
* adaptor_sig: pointer to adaptor signature to recover the adaptor
140+
* decryption key from (cannot be NULL)
141+
* enckey: pointer to the adaptor encryption public key
142+
* (cannot be NULL)
143+
*/
144+
SECP256K1_API int secp256k1_ecdsa_adaptor_recover(
145+
const secp256k1_context* ctx,
146+
unsigned char *deckey32,
147+
const secp256k1_ecdsa_signature *sig,
148+
const unsigned char *adaptor_sig162,
149+
const secp256k1_pubkey *enckey
150+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5);
151+
54152
#ifdef __cplusplus
55153
}
56154
#endif

0 commit comments

Comments
 (0)