Bitcoin-Secp256k1
view release on metacpan or search on metacpan
Secp256k1.xs view on Meta::CPAN
croak("something went wrong while negating a pubkey");
}
# Adds a tweak to private key
SV*
_privkey_add(self, privkey, tweak)
SV *self
SV *privkey
SV *tweak
CODE:
secp256k1_perl *ctx = ctx_from_sv(self);
unsigned char *seckey_str = size_bytestr_from_sv(privkey, CURVE_SIZE, "private key");
unsigned char *tweak_str = size_bytestr_from_sv(tweak, CURVE_SIZE, "tweak");
unsigned char new_seckey[CURVE_SIZE];
copy_bytestr(new_seckey, seckey_str, CURVE_SIZE);
int result = secp256k1_ec_seckey_tweak_add(
ctx->ctx,
new_seckey,
tweak_str
);
if (!result) {
clean_secret(new_seckey, CURVE_SIZE);
croak("resulting added privkey is not valid");
}
RETVAL = newSVpv((char*) new_seckey, CURVE_SIZE);
clean_secret(new_seckey, CURVE_SIZE);
OUTPUT:
RETVAL
# Adds a tweak to public key
void
_pubkey_add(self, tweak)
SV *self
SV *tweak
CODE:
secp256k1_perl *ctx = ctx_from_sv(self);
unsigned char *tweak_str = size_bytestr_from_sv(tweak, CURVE_SIZE, "tweak");
int result = secp256k1_ec_pubkey_tweak_add(
ctx->ctx,
secp256k1_perl_first_pubkey(ctx),
tweak_str
);
if (!result) {
croak("resulting added pubkey is not valid");
}
# Multiplies private key by a tweak
SV*
_privkey_mul(self, privkey, tweak)
SV *self
SV *privkey
SV *tweak
CODE:
secp256k1_perl *ctx = ctx_from_sv(self);
unsigned char *seckey_str = size_bytestr_from_sv(privkey, CURVE_SIZE, "private_key");
unsigned char *tweak_str = size_bytestr_from_sv(tweak, CURVE_SIZE, "tweak");
unsigned char new_seckey[CURVE_SIZE];
copy_bytestr(new_seckey, seckey_str, CURVE_SIZE);
int result = secp256k1_ec_seckey_tweak_mul(
ctx->ctx,
new_seckey,
tweak_str
);
if (!result) {
clean_secret(new_seckey, CURVE_SIZE);
croak("multiplication arguments are not valid");
}
RETVAL = newSVpv((char*) new_seckey, CURVE_SIZE);
clean_secret(new_seckey, CURVE_SIZE);
OUTPUT:
RETVAL
# Multiplies public key by a tweak
void
_pubkey_mul(self, tweak)
SV *self
SV *tweak
CODE:
secp256k1_perl *ctx = ctx_from_sv(self);
unsigned char *tweak_str = size_bytestr_from_sv(tweak, CURVE_SIZE, "tweak");
int result = secp256k1_ec_pubkey_tweak_mul(
ctx->ctx,
secp256k1_perl_first_pubkey(ctx),
tweak_str
);
if (!result) {
croak("multiplication arguments are not valid");
}
# Combines public keys together
void
_pubkey_combine(self)
SV *self
CODE:
secp256k1_perl *ctx = ctx_from_sv(self);
if (ctx->pubkeys->item_count == 0) {
croak("there are no public keys to combine");
}
secp256k1_pubkey *result_pubkey = malloc(sizeof *result_pubkey);
if (!result_pubkey) {
croak("failed to allocate pubkey memory");
}
int result = secp256k1_ec_pubkey_combine(
ctx->ctx,
result_pubkey,
(const secp256k1_pubkey * const *) ctx->pubkeys->items,
( run in 0.885 second using v1.01-cache-2.11-cpan-8379b9b8ec2 )