-
Notifications
You must be signed in to change notification settings - Fork 217
Add an experimental schnorr signature adaptor module #268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
555abe5
e0b87db
ed3e2ae
9735b05
8c9e169
2aa074d
094b863
344620e
bf0b7f4
69a5471
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#ifndef SECP256K1_SCHNORR_ADAPTOR_H | ||
#define SECP256K1_SCHNORR_ADAPTOR_H | ||
|
||
#include "secp256k1.h" | ||
#include "secp256k1_extrakeys.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** A pointer to a function to deterministically generate a nonce. | ||
* | ||
* Same as secp256k1_schnorrsig_nonce function with the exception of accepting an | ||
* additional adaptor point argument. | ||
* | ||
* Returns: 1 if a nonce was successfully generated. 0 will cause signing to | ||
* return an error. | ||
* Out: nonce32: pointer to a 32-byte array to be filled by the function | ||
* In: msg32: the 32-byte message being verified (will not be NULL) | ||
* key32: pointer to a 32-byte secret key (will not be NULL) | ||
* adaptor33: the 33-byte serialized adaptor point (will not be NULL) | ||
* xonly_pk32: the 32-byte serialized xonly pubkey corresponding to key32 | ||
* (will not be NULL) | ||
* algo: pointer to an array describing the signature | ||
* algorithm (will not be NULL) | ||
* algolen: the length of the algo array | ||
* data: arbitrary data pointer that is passed through | ||
* | ||
* Except for test cases, this function should compute some cryptographic hash of | ||
* the message, the key, the adaptor point, the pubkey, the algorithm description, and data. | ||
*/ | ||
typedef int (*secp256k1_adaptor_nonce_function_hardened)( | ||
unsigned char *nonce32, | ||
const unsigned char *msg32, | ||
const unsigned char *key32, | ||
const unsigned char *adaptor33, | ||
const unsigned char *xonly_pk32, | ||
const unsigned char *algo, | ||
size_t algolen, | ||
void *data | ||
); | ||
|
||
/** A Schnorr Adaptor nonce generation function. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we could just remove the reference to BIP340, instead of the whole paragraph. Something like: A Schnorr Adaptor nonce generation function. If a data pointer is passed, it is assumed to be a pointer to 32 bytes of auxiliary random data. If the data pointer is NULL, the nonce derivation procedure sets the auxiliary random data to zero. The algo argument must be non-NULL, otherwise the function will fail and return 0. The hash will be tagged with algo. Therefore, algo must be set to "SchnorrAdaptor/nonce" and algolen to 20. |
||
SECP256K1_API const secp256k1_adaptor_nonce_function_hardened secp256k1_nonce_function_schnorr_adaptor; | ||
|
||
/** Create a Schnorr adaptor signature. | ||
ZhePang marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to replace the term "adaptor signature" with "pre-signature" to be consistent with the literature (see #268 (comment))? |
||
* | ||
* This function only signs 32-byte messages. If you have messages of a | ||
* different size (or the same size but without a context-specific tag | ||
* prefix), it is recommended to create a 32-byte message hash with | ||
* secp256k1_tagged_sha256 and then sign the hash. Tagged hashing allows | ||
* providing an context-specific tag for domain separation. This prevents | ||
* signatures from being valid in multiple contexts by accident. | ||
* | ||
* Returns 1 on success, 0 on failure. | ||
* Args: ctx: pointer to a context object (not secp256k1_context_static). | ||
* Out: presig65: pointer to a 65-byte array to store the adaptor signature. | ||
* In: msg32: the 32-byte message being signed. | ||
* keypair: pointer to an initialized keypair. | ||
* adaptor: pointer to an adaptor point. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: 344620e renamed |
||
* aux_rand32: 32 bytes of fresh randomness. While recommended to provide | ||
* this, it is only supplemental to security and can be NULL. A | ||
* NULL argument is treated the same as an all-zero one. See | ||
* BIP-340 "Default Signing" for a full explanation of this | ||
* argument and for guidance if randomness is expensive. | ||
*/ | ||
SECP256K1_API int secp256k1_schnorr_adaptor_presign( | ||
const secp256k1_context *ctx, | ||
unsigned char *presig65, | ||
const unsigned char *msg32, | ||
const secp256k1_keypair *keypair, | ||
const secp256k1_pubkey *adaptor, | ||
const unsigned char *aux_rand32 | ||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5); | ||
|
||
/** Extract an adaptor point from the signature. | ||
* | ||
* Returns 1 on success, 0 on failure. | ||
* Args: ctx: pointer to a context object. | ||
* Out: adaptor33: pointer to an adaptor point. | ||
* In: presig65: pointer to a 65-byte adaptor signature. | ||
* msg32: the 32-byte message being signed. | ||
* pubkey: pointer to an x-only public key to verify with | ||
*/ | ||
SECP256K1_API int secp256k1_schnorr_adaptor_extract( | ||
const secp256k1_context *ctx, | ||
secp256k1_pubkey *adaptor, | ||
const unsigned char *presig65, | ||
const unsigned char *msg32, | ||
const secp256k1_xonly_pubkey *pubkey | ||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5); | ||
|
||
/** Adapt an adaptor signature to result in a Schnorr signature. | ||
* | ||
* Returns 1 on success, 0 on failure. | ||
* Args: ctx: pointer to a context object. | ||
* Out: sig64: pointer to a 64-byte array to store the adapted Schnorr signature. | ||
* In: presig65: pointer to a 65-byte adaptor signature. | ||
* secadaptor: pointer to a 32-byte secadaptor. | ||
*/ | ||
SECP256K1_API int secp256k1_schnorr_adaptor_adapt( | ||
const secp256k1_context *ctx, | ||
unsigned char *sig64, | ||
const unsigned char *presig65, | ||
const unsigned char *secadaptor | ||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); | ||
|
||
/** Extract the secadaptor from a valid adaptor signature and a Schnorr signature. | ||
* | ||
* Returns 1 on success, 0 on failure. | ||
* Args: ctx: pointer to a context object. | ||
* Out: secadaptor: pointer to a 32-byte array to store the secadaptor. | ||
* In: presig65: pointer to a 65-byte adaptor signature. | ||
* sig64: pointer to a 64-byte adapted Schnorr signature. | ||
*/ | ||
SECP256K1_API int secp256k1_schnorr_adaptor_extract_sec( | ||
const secp256k1_context *ctx, | ||
unsigned char *secadaptor, | ||
const unsigned char *presig65, | ||
const unsigned char *sig64 | ||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* SECP256K1_SCHNORR_ADAPTOR_H */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include_HEADERS += include/secp256k1_schnorr_adaptor.h | ||
noinst_HEADERS += src/modules/schnorr_adaptor/main_impl.h | ||
noinst_HEADERS += src/modules/schnorr_adaptor/tests_impl.h |
Uh oh!
There was an error while loading. Please reload this page.