On 3 October 2014 12:38, Robert Zillner <
robzi...@gmail.com> wrote:
>
> Hello,
>
> i´m trying to initialize a public key only in openssl to verify an external created signature of a message.
Not sure why this is an openssl-testing question...but anyway...
>
>
> The private key is not available because an external signature device signs the message. The public key is available
> in hex format (x + y).
Do you mean a string containing only the hex characters
0-9,a-z,A-Z....or do you actually mean an octet string?
>
>
> My problem is that i don´t know how to initialize only a public key and to verify the signature in openssl.
>
> The used curve for the sifgnature is "sect283k1"
>
> Can anyone help me?
>
> This is my current try:
>
> EC_KEY *key;
> if(NULL == (key = EC_KEY_new_by_curve_name(NID_sect283k1)))
> cout << "Generating instance of key failed! \r" << endl;
> EC_GROUP *ec_group = EC_GROUP_new_by_curve_name(NID_sect283k1);
> EC_KEY_set_group(key, ec_group);
> EC_POINT *publ;
>
EC_KEY_new_by_curve_name implicitly sets the group, so you don't need
to do this bit.
>
> publ = EC_POINT_hex2point(ec_group, (const char *)pubKey.data(), 0, NULL);
> if(EC_KEY_set_public_key(key, publ) != 1)
> {
> cout << "Setting failed !" << endl;
> }
>
Its not clear from your description of the problem whether this works
or not - it looks ok. If you're actually dealing with an octet string
then you would need to use EC_POINT_oct2point instead.
Assuming it works you might want to call EC_KEY_check_key at this
point to make sure its sane.
Next step is to create an EVP_PKEY object. Use:
int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey,EC_KEY *key);
Then use the standard EVP routines for verifying a signature. See:
http://wiki.openssl.org/index.php/EVP_Signing_and_Verifying
Hope that helps
Matt