I provide this sample application to show my problem
#include <stdio.h> #include <stdlib.h> #include <openssl/ec.h> #include <openssl/bn.h> int main() { EC_KEY *pkey = NULL; EC_POINT *pub_key = NULL; const EC_GROUP *group = NULL; BIGNUM start; BIGNUM *res; BN_CTX *ctx; BN_init(&start); ctx = BN_CTX_new(); res = &start; BN_hex2bn(&res,"3D79F601620A6D05DB7FED883AB8BCD08A9101B166BC60166869DA5FC08D936E"); pkey = EC_KEY_new_by_curve_name(NID_secp256k1); group = EC_KEY_get0_group(pkey); pub_key = EC_POINT_new(group); EC_KEY_set_private_key(pkey, res); assert(EC_POINT_bn2point(group,res, pub_key, ctx)); // Null here EC_KEY_set_public_key(pkey, pub_key); return 0; }
What I'm trying to do is display the public key from the private key (there must be an elliptical private key). I did not know how to do this until I ran into a similar problem.
How can I pass arbitrary OpenSSL data for use when signing an ECDSA?
This is where I showed myself how to get the public key and use EC_POINT_bn2point instead of hex2point, which internally executes BN_hex2bn according to the OpenSSL source code.
So why does EC_POINT_bn2point return NULL? I'm seriously thinking of recompiling OpenSSL and putting some debugging routines to find out why it fails.
source share