Can anyone help me, I am try to take a public key and private key, and create a split address public key, here is my code :
The out put is a char ptr which I convert to const after.
char* convert_public_key_and_private_wif_to_pubkey(const char* pub_key, const char* priv_key) {
EC_GROUP* ecgrp;
EC_KEY* miner_key;
EC_POINT* tmpg;
EC_POINT* ppnt;
BIGNUM order;
BIGNUM cofactor;
BIGNUM bnbase;
BIGNUM bnpriv;
unsigned char eckey_buf[128], *pend;
// Init BiGNUMs
BN_init(&bnbase);
BN_init(&order);
BN_init(&cofactor);
BN_init(&bnpriv);
// Set Bignum Base.
BN_set_word(&bnbase, 58);
// Init Context.
BN_CTX bnctx = BN_CTX_new();
// Init Curve.
ecgrp = EC_GROUP_new_by_curve_name(NID_secp256k1);
miner_key = EC_KEY_new_by_curve_name(NID_secp256k1);
// Init Group from Public Key.
tmpg = EC_POINT_hex2point(ecgrp, pub_key, NULL, NULL);
// Get group order.
EC_GROUP_get_order(ecgrp, &order, NULL);
// Get Cofactor.
EC_GROUP_get_cofactor(ecgrp, &cofactor, NULL);
// Set Generator.
EC_GROUP_set_generator(ecgrp, tmpg, &order, &cofactor);
// Init Key.
EC_KEY bnkey = EC_KEY_new();
// Set key group.
EC_KEY_set_group(bnkey, ecgrp);
EC_GROUP pgroup = EC_KEY_get0_group(miner_key);
ppnt = EC_POINT_new(pgroup);
// Precompute.
EC_KEY_precompute_mult(bnkey, bnctx);
// Set private key.
BN_init(&bnpriv);
BN_bin2bn(priv_key, 64, &bnpriv);
EC_KEY_set_private_key(miner_key, bnpriv);
EC_POINT_mul(pgroup, ppnt, miner_key, NULL, NULL, NULL);
EC_KEY_set_public_key(miner_key, ppnt);
// Add keys together.
BN_mod_add(&order,
EC_KEY_get0_private_key(bnkey),
EC_KEY_get0_private_key(miner_key),
&cofactor,
bnctx);
// Get and return public key.
pend = eckey_buf;
i2o_ECPublicKey(bnkey, &pend);
return pend;
}
I get the following errors :
util.c:48:5: error: variable 'bnctx' has initializer but incomplete type
BN_CTX bnctx = BN_CTX_new();
^
util.c:48:12: error: storage size of 'bnctx' isn't known
BN_CTX bnctx = BN_CTX_new();
^
util.c:67:5: error: variable 'bnkey' has initializer but incomplete type
EC_KEY bnkey = EC_KEY_new();
^
util.c:67:12: error: storage size of 'bnkey' isn't known
EC_KEY bnkey = EC_KEY_new();
^
util.c:71:5: error: variable 'pgroup' has initializer but incomplete type
EC_GROUP pgroup = EC_KEY_get0_group(miner_key);
^
util.c:71:14: error: storage size of 'pgroup' isn't known
EC_GROUP pgroup = EC_KEY_get0_group(miner_key);
^
util.c:79:15: warning: pointer targets in passing argument 1 of 'BN_bin2bn' differ in signedness [-Wpointer-sign]
BN_bin2bn(priv_key, 64, &bnpriv);
^
In file included from util.c:5:0:
/usr/include/openssl/bn.h:442:9: note: expected 'const unsigned char *' but argument is of type 'const char *'
BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
^
util.c:80:39: error: incompatible type for argument 2 of 'EC_KEY_set_private_key'
EC_KEY_set_private_key(miner_key, bnpriv);
^
In file included from util.c:6:0:
/usr/include/openssl/ec.h:819:5: note: expected 'const BIGNUM * {aka const struct bignum_st *}' but argument is of type 'BIGNUM {aka struct bignum_st}'
int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);
^
util.c:81:32: warning: passing argument 3 of 'EC_POINT_mul' from incompatible pointer type [-Wincompatible-pointer-types]
EC_POINT_mul(pgroup, ppnt, miner_key, NULL, NULL, NULL);
^
In file included from util.c:6:0:
/usr/include/openssl/ec.h:685:5: note: expected 'const BIGNUM * {aka const struct bignum_st *}' but argument is of type 'EC_KEY * {aka struct ec_key_st *}'
int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n,
^
util.c:94:12: warning: pointer targets in return differ in signedness [-Wpointer-sign]
return pend;
^
util.c:71:14: warning: unused variable 'pgroup' [-Wunused-variable]
EC_GROUP pgroup = EC_KEY_get0_group(miner_key);
^
util.c:67:12: warning: unused variable 'bnkey' [-Wunused-variable]
EC_KEY bnkey = EC_KEY_new();
^
util.c:48:12: warning: unused variable 'bnctx' [-Wunused-variable]
BN_CTX bnctx = BN_CTX_new();
^
make: *** [
BUILD FAILED (exit value 2, total time: 8s)
I took code from the first page and parts from vanitygen, I cannot find the vanityminer code correctly so anyhelp would be appreciated !