Skip to content

Commit 176bfb1

Browse files
committed
Separate helper function for ec_pubkey_tweak_add
This is in preparation for allowing code reuse by xonly tweak add functions
1 parent 4cd2ee4 commit 176bfb1

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/secp256k1.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -631,25 +631,26 @@ int secp256k1_ec_privkey_tweak_add(const secp256k1_context* ctx, unsigned char *
631631
return secp256k1_ec_seckey_tweak_add(ctx, seckey, tweak);
632632
}
633633

634+
static int secp256k1_ec_pubkey_tweak_add_helper(const secp256k1_ecmult_context* ecmult_ctx, secp256k1_ge *p, const unsigned char *tweak) {
635+
secp256k1_scalar term;
636+
int overflow = 0;
637+
secp256k1_scalar_set_b32(&term, tweak, &overflow);
638+
return !overflow && secp256k1_eckey_pubkey_tweak_add(ecmult_ctx, p, &term);
639+
}
640+
634641
int secp256k1_ec_pubkey_tweak_add(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak) {
635642
secp256k1_ge p;
636-
secp256k1_scalar term;
637643
int ret = 0;
638-
int overflow = 0;
639644
VERIFY_CHECK(ctx != NULL);
640645
ARG_CHECK(secp256k1_ecmult_context_is_built(&ctx->ecmult_ctx));
641646
ARG_CHECK(pubkey != NULL);
642647
ARG_CHECK(tweak != NULL);
643648

644-
secp256k1_scalar_set_b32(&term, tweak, &overflow);
645-
ret = !overflow && secp256k1_pubkey_load(ctx, &p, pubkey);
649+
ret = secp256k1_pubkey_load(ctx, &p, pubkey);
646650
memset(pubkey, 0, sizeof(*pubkey));
651+
ret = ret && secp256k1_ec_pubkey_tweak_add_helper(&ctx->ecmult_ctx, &p, tweak);
647652
if (ret) {
648-
if (secp256k1_eckey_pubkey_tweak_add(&ctx->ecmult_ctx, &p, &term)) {
649-
secp256k1_pubkey_save(pubkey, &p);
650-
} else {
651-
ret = 0;
652-
}
653+
secp256k1_pubkey_save(pubkey, &p);
653654
}
654655

655656
return ret;

0 commit comments

Comments
 (0)