Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/modules/recovery/main_impl.h
Show First 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | static int secp256k1_ecdsa_sig_recover(const secp256k1_ecmult_context *ctx, const secp256k1_scalar *sigr, const secp256k1_scalar* sigs, secp256k1_ge *pubkey, const secp256k1_scalar *message, int recid) { | ||||
secp256k1_scalar_mul(&u1, &rn, message); | secp256k1_scalar_mul(&u1, &rn, message); | ||||
secp256k1_scalar_negate(&u1, &u1); | secp256k1_scalar_negate(&u1, &u1); | ||||
secp256k1_scalar_mul(&u2, &rn, sigs); | secp256k1_scalar_mul(&u2, &rn, sigs); | ||||
secp256k1_ecmult(ctx, &qj, &xj, &u2, &u1); | secp256k1_ecmult(ctx, &qj, &xj, &u2, &u1); | ||||
secp256k1_ge_set_gej_var(pubkey, &qj); | secp256k1_ge_set_gej_var(pubkey, &qj); | ||||
return !secp256k1_gej_is_infinity(&qj); | return !secp256k1_gej_is_infinity(&qj); | ||||
} | } | ||||
int secp256k1_ecdsa_sign_recoverable(const secp256k1_context* ctx, secp256k1_ecdsa_recoverable_signature *signature, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void* noncedata) { | int secp256k1_ecdsa_sign_recoverable(const secp256k1_context* ctx, secp256k1_ecdsa_recoverable_signature *signature, const unsigned char *msghash32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void* noncedata) { | ||||
secp256k1_scalar r, s; | secp256k1_scalar r, s; | ||||
int ret, recid; | int ret, recid; | ||||
const unsigned char secp256k1_ecdsa_recoverable_algo16[17] = "ECDSA+Recovery "; | const unsigned char secp256k1_ecdsa_recoverable_algo16[17] = "ECDSA+Recovery "; | ||||
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(msghash32 != NULL); | ||||
ARG_CHECK(signature != NULL); | ARG_CHECK(signature != NULL); | ||||
ARG_CHECK(seckey != NULL); | ARG_CHECK(seckey != NULL); | ||||
ret = secp256k1_ecdsa_sign_inner(ctx, &r, &s, &recid, msg32, seckey, noncefp, secp256k1_ecdsa_recoverable_algo16, noncedata); | ret = secp256k1_ecdsa_sign_inner(ctx, &r, &s, &recid, msghash32, seckey, noncefp, secp256k1_ecdsa_recoverable_algo16, noncedata); | ||||
secp256k1_ecdsa_recoverable_signature_save(signature, &r, &s, recid); | secp256k1_ecdsa_recoverable_signature_save(signature, &r, &s, recid); | ||||
return ret; | return ret; | ||||
} | } | ||||
int secp256k1_ecdsa_recover(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const secp256k1_ecdsa_recoverable_signature *signature, const unsigned char *msg32) { | int secp256k1_ecdsa_recover(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const secp256k1_ecdsa_recoverable_signature *signature, const unsigned char *msghash32) { | ||||
secp256k1_ge q; | secp256k1_ge q; | ||||
secp256k1_scalar r, s; | secp256k1_scalar r, s; | ||||
secp256k1_scalar m; | secp256k1_scalar m; | ||||
int recid; | int recid; | ||||
VERIFY_CHECK(ctx != NULL); | VERIFY_CHECK(ctx != NULL); | ||||
ARG_CHECK(secp256k1_ecmult_context_is_built(&ctx->ecmult_ctx)); | ARG_CHECK(secp256k1_ecmult_context_is_built(&ctx->ecmult_ctx)); | ||||
ARG_CHECK(msg32 != NULL); | ARG_CHECK(msghash32 != NULL); | ||||
ARG_CHECK(signature != NULL); | ARG_CHECK(signature != NULL); | ||||
ARG_CHECK(pubkey != NULL); | ARG_CHECK(pubkey != NULL); | ||||
secp256k1_ecdsa_recoverable_signature_load(ctx, &r, &s, &recid, signature); | secp256k1_ecdsa_recoverable_signature_load(ctx, &r, &s, &recid, signature); | ||||
VERIFY_CHECK(recid >= 0 && recid < 4); /* should have been caught in parse_compact */ | VERIFY_CHECK(recid >= 0 && recid < 4); /* should have been caught in parse_compact */ | ||||
secp256k1_scalar_set_b32(&m, msg32, NULL); | secp256k1_scalar_set_b32(&m, msghash32, NULL); | ||||
if (secp256k1_ecdsa_sig_recover(&ctx->ecmult_ctx, &r, &s, &q, &m, recid)) { | if (secp256k1_ecdsa_sig_recover(&ctx->ecmult_ctx, &r, &s, &q, &m, recid)) { | ||||
secp256k1_pubkey_save(pubkey, &q); | secp256k1_pubkey_save(pubkey, &q); | ||||
return 1; | return 1; | ||||
} else { | } else { | ||||
memset(pubkey, 0, sizeof(*pubkey)); | memset(pubkey, 0, sizeof(*pubkey)); | ||||
return 0; | return 0; | ||||
} | } | ||||
} | } | ||||
#endif /* SECP256K1_MODULE_RECOVERY_MAIN_H */ | #endif /* SECP256K1_MODULE_RECOVERY_MAIN_H */ |