0

I am trying to convert a raw EC key and EVP_PKEY structure. The process seems straightforward but am running into issues.

Here is the code I am using --

unsigned char tmpPubKey[] = {
        0x04, 0xbf, 0x7a, 0x7f, 0xf3, 0x62, 0x8f, 0x91, 0xcd, 0xa5,
        0x57, 0x41, 0x57, 0x63, 0x4d, 0x59, 0x45, 0xc8, 0xb2, 0x6d,
        0x71, 0xf6, 0xe0, 0x6a, 0x79, 0x2d, 0x36, 0x2f, 0x16, 0xb1, 
        0xc0, 0xd0, 0xc8, 0xa7, 0x2a, 0x9d, 0xe8, 0x30, 0x9c, 0xc6, 
        0xa5, 0x70, 0xa5, 0xb2, 0x04, 0x21, 0x4d, 0x30, 0xfe, 0x59, 
        0x3a, 0x41, 0xd0, 0xc8, 0x8e, 0x33, 0xf3, 0xa2, 0x2e, 0x6b, 
        0x09, 0x78, 0x0d, 0x48, 0x98
};
EC_GROUP *g = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1);;
EC_POINT *p = EC_POINT_new(g);
EC_KEY  *k = EC_KEY_new();
error = EC_POINT_oct2point(g, p, tmpPubKey, sizeof(tmpPubKey), NULL);
error = EC_KEY_set_public_key(k, p);
error = EVP_PKEY_set1_EC_KEY(nodePubKey, k);

This should work from what I have looked up. But its not working

I get this error "EC_POINT_new:passed a null parameter" on calling EC_POINT_oct2point()

The key used is correct as I have generated in manually and exported it.

Can some one tell me what I am missing?

  • 1
    This is a programming Q and probably belongs on SO instead. ec.h doesn't say so, but you must set the group with EC_KEY_set_group before you set the pubkey with EC_KEY_set_public_key – dave_thompson_085 May 9 at 11:01
  • Thank you for your help. I missed that completely. I knew I had to do it but somehow didn't see that I didn't add it in code. – SFlow May 9 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.