Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/modules/schnorr/main_impl.h
Show All 29 Lines | |||||
int secp256k1_schnorr_sign( | int secp256k1_schnorr_sign( | ||||
const secp256k1_context *ctx, | const secp256k1_context *ctx, | ||||
unsigned char *sig64, | unsigned char *sig64, | ||||
const unsigned char *msg32, | const unsigned char *msg32, | ||||
const unsigned char *seckey, | const unsigned char *seckey, | ||||
secp256k1_nonce_function noncefp, | secp256k1_nonce_function noncefp, | ||||
const void *ndata | const void *ndata | ||||
) { | ) { | ||||
secp256k1_scalar sec, non; | secp256k1_scalar sec; | ||||
secp256k1_pubkey pubkey; | secp256k1_pubkey pubkey; | ||||
secp256k1_ge p; | secp256k1_ge p; | ||||
int ret = 0; | int ret = 0; | ||||
VERIFY_CHECK(ctx != NULL); | VERIFY_CHECK(ctx != NULL); | ||||
ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); | ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)); | ||||
ARG_CHECK(msg32 != NULL); | ARG_CHECK(msg32 != NULL); | ||||
ARG_CHECK(sig64 != NULL); | ARG_CHECK(sig64 != NULL); | ||||
ARG_CHECK(seckey != NULL); | ARG_CHECK(seckey != NULL); | ||||
if (!secp256k1_ec_pubkey_create(ctx, &pubkey, seckey)) { | if (!secp256k1_ec_pubkey_create(ctx, &pubkey, seckey)) { | ||||
return 0; | return 0; | ||||
} | } | ||||
if (!secp256k1_schnorr_sig_generate_k(&non, msg32, seckey, noncefp, ndata)) { | |||||
secp256k1_scalar_clear(&non); | |||||
return 0; | |||||
} | |||||
secp256k1_pubkey_load(ctx, &p, &pubkey); | secp256k1_pubkey_load(ctx, &p, &pubkey); | ||||
secp256k1_scalar_set_b32(&sec, seckey, NULL); | secp256k1_scalar_set_b32(&sec, seckey, NULL); | ||||
ret = secp256k1_schnorr_sig_sign(&ctx->ecmult_gen_ctx, sig64, &sec, &p, &non, msg32); | ret = secp256k1_schnorr_sig_sign(&ctx->ecmult_gen_ctx, sig64, msg32, &sec, &p, noncefp, ndata); | ||||
if (!ret) { | if (!ret) { | ||||
memset(sig64, 0, 64); | memset(sig64, 0, 64); | ||||
} | } | ||||
secp256k1_scalar_clear(&non); | |||||
secp256k1_scalar_clear(&sec); | secp256k1_scalar_clear(&sec); | ||||
return ret; | return ret; | ||||
} | } | ||||
#endif | #endif |