Any tip would be appreciated.
What I want is to serialize an EC public key and send it in a small header. Therefore, I wouldn't go for i2d and d2i since they give large byte arrays including EC_KEY and needed group parameters(u can save group parameters on the other side and skip sending them and have much smaller byte array to send).
I want to use i2o and o2i and I know that in receiving side there should be an EC_KEY object containing the group paramaters so I can use o2i on that and create a public key (like a duplicated public key of in sender side) to verify the signature. But it just gives me error. Here is my effort all done in a single main. Headers, sockets and etc are not included.
unsigned char hash[] = "c7fbca202a95a570285e3d700eb04ca2";
EC_KEY *eckey=EC_KEY_new_by_curve_name(NID_secp224k1);
//a key which has the group elements but it's actually empty...??right?
EC_KEY *reckey= EC_KEY_dup(eckey);
EC_KEY_generate_key(eckey);
unsigned char *penc = NULL, *p;
penc = (unsigned char*)OPENSSL_malloc(57);
cout << "pub_len: "<< i2o_ECPublicKey(eckey, &penc) <<endl;
unsigned char* signaturee = new unsigned char[66] ;
unsigned int y = ECDSA_size(eckey);
int n = ECDSA_sign(0,(const unsigned char*)hash,sizeof(hash),signaturee,&y,eckey);
printf("result of signing: %d\n", n);
int f = ECDSA_verify(0,(const unsigned char*)hash,sizeof(hash),(const unsigned char*)signaturee,(int)y,eckey);
printf("result of verification: %d\n", f);
reckey = o2i_ECPublicKey(&reckey, (const unsigned char**)&p, i2o_ECPublicKey(eckey, NULL));
cout << "here"<<endl;
int u = ECDSA_verify(0,(const unsigned char*)hash,sizeof(hash),(const unsigned char*)signaturee,(int)y,reckey);
cout << "here1"<<endl;
printf("result of verification2: %d\n", u)
RESULTS:
pub_len: 57
result of signing: 1
result of verification: 1
here
as you can see it can not verify with reckey. It even does not return me a '0'.