I am trying to compute public key from given secret by openssl. I get this error:
main.c:27: error: incomplete definition of type 'struct ec_key_st'
printf("d: %s\n", BN_bn2hex(eckey->priv_key));
~~~~~^
Here is my code:
#include <stdio.h>
#include <openssl/ec.h>
#include <openssl/ecdsa.h>
#include <openssl/bn.h>
#include <openssl/obj_mac.h>
int main()
{
BN_CTX *ctx = BN_CTX_new();
EC_KEY *eckey = EC_KEY_new();
EC_GROUP *group = EC_GROUP_new_by_curve_name(NID_secp256k1);
EC_KEY_set_group(eckey, group);
BIGNUM *prv = BN_new();
BN_hex2bn(&prv, "b14fac12b3fa7dd6f2562a18d554fcd6818137ebb7e0d119ab0776d6407664f9");
EC_KEY_set_private_key(eckey, prv);
EC_POINT *Q = EC_POINT_new(group);
EC_POINT_mul(group, Q, prv, NULL, NULL, ctx);
EC_KEY_set_public_key(eckey, Q);
if (EC_KEY_check_key(eckey))
printf("Key succesfully checked.\n");
printf("d: %s\n", BN_bn2hex(eckey->priv_key));
printf("X: %s\n", BN_bn2hex(&eckey->pub_key->X));
printf("Y: %s\n", BN_bn2hex(&eckey->pub_key->Y));
EC_GROUP_free (group); group = NULL;
EC_KEY_free (eckey); eckey = NULL;
return 0;
}
What is wrong with the above code? If I remove printf lines, it works fine. I would appreciate if anybody helps me getting rid of this error.