|
|
|
@ -156,7 +156,7 @@ int secp256k1_ecdsa_privkey_tweak_add(unsigned char *seckey, const unsigned char
|
|
|
|
|
secp256k1_num_t sec;
|
|
|
|
|
secp256k1_num_init(&sec);
|
|
|
|
|
if (ret) {
|
|
|
|
|
secp256k1_num_set_bin(&term, seckey, 32);
|
|
|
|
|
secp256k1_num_set_bin(&sec, seckey, 32);
|
|
|
|
|
secp256k1_num_add(&sec, &sec, &term);
|
|
|
|
|
secp256k1_num_mod(&sec, &secp256k1_ge_consts->order);
|
|
|
|
|
if (secp256k1_num_is_zero(&sec))
|
|
|
|
@ -198,34 +198,34 @@ int secp256k1_ecdsa_pubkey_tweak_add(unsigned char *pubkey, int pubkeylen, const
|
|
|
|
|
|
|
|
|
|
int secp256k1_ecdsa_privkey_tweak_mul(unsigned char *seckey, const unsigned char *tweak) {
|
|
|
|
|
int ret = 1;
|
|
|
|
|
secp256k1_num_t term;
|
|
|
|
|
secp256k1_num_init(&term);
|
|
|
|
|
secp256k1_num_set_bin(&term, tweak, 32);
|
|
|
|
|
if (secp256k1_num_is_zero(&term))
|
|
|
|
|
secp256k1_num_t factor;
|
|
|
|
|
secp256k1_num_init(&factor);
|
|
|
|
|
secp256k1_num_set_bin(&factor, tweak, 32);
|
|
|
|
|
if (secp256k1_num_is_zero(&factor))
|
|
|
|
|
ret = 0;
|
|
|
|
|
if (secp256k1_num_cmp(&term, &secp256k1_ge_consts->order) >= 0)
|
|
|
|
|
if (secp256k1_num_cmp(&factor, &secp256k1_ge_consts->order) >= 0)
|
|
|
|
|
ret = 0;
|
|
|
|
|
secp256k1_num_t sec;
|
|
|
|
|
secp256k1_num_init(&sec);
|
|
|
|
|
if (ret) {
|
|
|
|
|
secp256k1_num_set_bin(&term, seckey, 32);
|
|
|
|
|
secp256k1_num_mod_mul(&sec, &sec, &term, &secp256k1_ge_consts->order);
|
|
|
|
|
secp256k1_num_set_bin(&sec, seckey, 32);
|
|
|
|
|
secp256k1_num_mod_mul(&sec, &sec, &factor, &secp256k1_ge_consts->order);
|
|
|
|
|
}
|
|
|
|
|
if (ret)
|
|
|
|
|
secp256k1_num_get_bin(seckey, 32, &sec);
|
|
|
|
|
secp256k1_num_free(&sec);
|
|
|
|
|
secp256k1_num_free(&term);
|
|
|
|
|
secp256k1_num_free(&factor);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int secp256k1_ecdsa_pubkey_tweak_mul(unsigned char *pubkey, int pubkeylen, const unsigned char *tweak) {
|
|
|
|
|
int ret = 1;
|
|
|
|
|
secp256k1_num_t term;
|
|
|
|
|
secp256k1_num_init(&term);
|
|
|
|
|
secp256k1_num_set_bin(&term, tweak, 32);
|
|
|
|
|
if (secp256k1_num_is_zero(&term))
|
|
|
|
|
secp256k1_num_t factor;
|
|
|
|
|
secp256k1_num_init(&factor);
|
|
|
|
|
secp256k1_num_set_bin(&factor, tweak, 32);
|
|
|
|
|
if (secp256k1_num_is_zero(&factor))
|
|
|
|
|
ret = 0;
|
|
|
|
|
if (secp256k1_num_cmp(&term, &secp256k1_ge_consts->order) >= 0)
|
|
|
|
|
if (secp256k1_num_cmp(&factor, &secp256k1_ge_consts->order) >= 0)
|
|
|
|
|
ret = 0;
|
|
|
|
|
secp256k1_ge_t p;
|
|
|
|
|
if (ret) {
|
|
|
|
@ -238,14 +238,14 @@ int secp256k1_ecdsa_pubkey_tweak_mul(unsigned char *pubkey, int pubkeylen, const
|
|
|
|
|
secp256k1_num_set_int(&zero, 0);
|
|
|
|
|
secp256k1_gej_t pt;
|
|
|
|
|
secp256k1_gej_set_ge(&pt, &p);
|
|
|
|
|
secp256k1_ecmult(&pt, &pt, &term, &zero);
|
|
|
|
|
secp256k1_ecmult(&pt, &pt, &factor, &zero);
|
|
|
|
|
secp256k1_num_free(&zero);
|
|
|
|
|
secp256k1_ge_set_gej(&p, &pt);
|
|
|
|
|
int oldlen = pubkeylen;
|
|
|
|
|
secp256k1_ecdsa_pubkey_serialize(&p, pubkey, &pubkeylen, oldlen <= 33);
|
|
|
|
|
assert(pubkeylen == oldlen);
|
|
|
|
|
}
|
|
|
|
|
secp256k1_num_free(&term);
|
|
|
|
|
secp256k1_num_free(&factor);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|