7#ifndef SECP256K1_MODULE_EXTRAKEYS_MAIN_H
8#define SECP256K1_MODULE_EXTRAKEYS_MAIN_H
30 if (!secp256k1_fe_set_b32(&x, input32)) {
33 if (!secp256k1_ge_set_xo_var(&pk, &x, 0)) {
36 if (!secp256k1_ge_is_in_correct_subgroup(&pk)) {
39 secp256k1_xonly_pubkey_save(
pubkey, &pk);
51 if (!secp256k1_xonly_pubkey_load(ctx, &pk,
pubkey)) {
54 secp256k1_fe_get_b32(output32, &pk.
x);
59 unsigned char out[2][32];
64 pk[0] = pk0; pk[1] = pk1;
65 for (i = 0; i < 2; i++) {
78 memset(out[i], 0,
sizeof(out[i]));
81 return secp256k1_memcmp_var(out[0], out[1],
sizeof(out[1]));
91 if (secp256k1_fe_is_odd(&
r->y)) {
92 secp256k1_fe_negate(&
r->y, &
r->y, 1);
106 if (!secp256k1_pubkey_load(ctx, &pk,
pubkey)) {
109 tmp = secp256k1_extrakeys_ge_even_y(&pk);
110 if (pk_parity != NULL) {
113 secp256k1_xonly_pubkey_save(xonly_pubkey, &pk);
122 memset(output_pubkey, 0,
sizeof(*output_pubkey));
126 if (!secp256k1_xonly_pubkey_load(ctx, &pk, internal_pubkey)
127 || !secp256k1_ec_pubkey_tweak_add_helper(&pk, tweak32)) {
130 secp256k1_pubkey_save(output_pubkey, &pk);
136 unsigned char pk_expected32[32];
143 if (!secp256k1_xonly_pubkey_load(ctx, &pk, internal_pubkey)
144 || !secp256k1_ec_pubkey_tweak_add_helper(&pk, tweak32)) {
147 secp256k1_fe_normalize_var(&pk.
x);
148 secp256k1_fe_normalize_var(&pk.
y);
149 secp256k1_fe_get_b32(pk_expected32, &pk.
x);
151 return secp256k1_memcmp_var(&pk_expected32, tweaked_pubkey32, 32) == 0
152 && secp256k1_fe_is_odd(&pk.
y) == tweaked_pk_parity;
156 secp256k1_scalar_get_b32(&keypair->
data[0], sk);
164 ret = secp256k1_scalar_set_b32_seckey(sk, &keypair->
data[0]);
167 secp256k1_declassify(ctx, &
ret,
sizeof(
ret));
182 ret = secp256k1_pubkey_load(ctx, pk,
pubkey);
184 ret =
ret && secp256k1_keypair_seckey_load(ctx, sk, keypair);
187 *pk = secp256k1_ge_const_g;
189 *sk = secp256k1_scalar_one;
201 memset(keypair, 0,
sizeof(*keypair));
205 ret = secp256k1_ec_pubkey_create_helper(&ctx->
ecmult_gen_ctx, &sk, &pk, seckey32);
206 secp256k1_keypair_save(keypair, &sk, &pk);
207 secp256k1_memczero(keypair,
sizeof(*keypair), !
ret);
209 secp256k1_scalar_clear(&sk);
242 if (!secp256k1_keypair_load(ctx, NULL, &pk, keypair)) {
245 tmp = secp256k1_extrakeys_ge_even_y(&pk);
246 if (pk_parity != NULL) {
249 secp256k1_xonly_pubkey_save(
pubkey, &pk);
264 ret = secp256k1_keypair_load(ctx, &sk, &pk, keypair);
265 memset(keypair, 0,
sizeof(*keypair));
267 y_parity = secp256k1_extrakeys_ge_even_y(&pk);
269 secp256k1_scalar_negate(&sk, &sk);
272 ret &= secp256k1_ec_seckey_tweak_add_helper(&sk, tweak32);
273 ret &= secp256k1_ec_pubkey_tweak_add_helper(&pk, tweak32);
275 secp256k1_declassify(ctx, &
ret,
sizeof(
ret));
277 secp256k1_keypair_save(keypair, &sk, &pk);
280 secp256k1_scalar_clear(&sk);
int secp256k1_keypair_create(const secp256k1_context *ctx, secp256k1_keypair *keypair, const unsigned char *seckey32)
int secp256k1_keypair_xonly_tweak_add(const secp256k1_context *ctx, secp256k1_keypair *keypair, const unsigned char *tweak32)
int secp256k1_xonly_pubkey_tweak_add_check(const secp256k1_context *ctx, const unsigned char *tweaked_pubkey32, int tweaked_pk_parity, const secp256k1_xonly_pubkey *internal_pubkey, const unsigned char *tweak32)
int secp256k1_xonly_pubkey_tweak_add(const secp256k1_context *ctx, secp256k1_pubkey *output_pubkey, const secp256k1_xonly_pubkey *internal_pubkey, const unsigned char *tweak32)
int secp256k1_xonly_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output32, const secp256k1_xonly_pubkey *pubkey)
int secp256k1_keypair_sec(const secp256k1_context *ctx, unsigned char *seckey, const secp256k1_keypair *keypair)
int secp256k1_keypair_xonly_pub(const secp256k1_context *ctx, secp256k1_xonly_pubkey *pubkey, int *pk_parity, const secp256k1_keypair *keypair)
int secp256k1_xonly_pubkey_from_pubkey(const secp256k1_context *ctx, secp256k1_xonly_pubkey *xonly_pubkey, int *pk_parity, const secp256k1_pubkey *pubkey)
int secp256k1_keypair_pub(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const secp256k1_keypair *keypair)
int secp256k1_xonly_pubkey_parse(const secp256k1_context *ctx, secp256k1_xonly_pubkey *pubkey, const unsigned char *input32)
int secp256k1_xonly_pubkey_cmp(const secp256k1_context *ctx, const secp256k1_xonly_pubkey *pk0, const secp256k1_xonly_pubkey *pk1)
#define VERIFY_CHECK(cond)
secp256k1_ecmult_gen_context ecmult_gen_ctx
memset(pInfo->slotDescription, ' ', 64)
memcpy((char *) pInfo->slotDescription, s, l)