How to access different fields of typedef struct evp_pkey_st EVP_PKEY.

Tomas Mraz tomas at openssl.org
Tue Apr 20 11:06:37 UTC 2021


On Tue, 2021-04-20 at 10:45 +0000, Kumar Mishra, Sanjeev wrote:
> Hi,
> I am not getting different functions in OpenSSL 3.0 for accessing
> different fields of typedef struct evp_pkey_st EVP_PKEY. For Example
> - code is like this -
> EVP_PKEY * privKey;
> -----
> -----
> if ( BN_cmp(privKey->pkey.rsa->n, pubKey->pkey.rsa->n) != 0 )

If you just want to compare private and public key whether the public
key component match, you can use:

 if (EVP_PKEY_eq(pubKey, privKey) != 1) {
     /* keys do not match */
 }

> ----
> ----
> else if ((privKey->type == EVP_PKEY_EC) && (pubKey->type ==
> EVP_PKEY_EC))

You can use EVP_PKEY_base_id(key) to get the type however it would be
even better to use
 EVP_PKEY_is_a(privKey, "EC") && EVP_PKEY_is_a(pubKey, "EC")


-- 
Tomáš Mráz
No matter how far down the wrong road you've gone, turn back.
                                              Turkish proverb
[You'll know whether the road is wrong if you carefully listen to your
conscience.]




More information about the openssl-users mailing list