Hi,

I just created a key pair using:

  RSA *rsa = RSA_generate_key(bits, RSA_F4, NULL, NULL);
  assert(rsa);
  ...
  EVP_PKEY *pkey = EVP_PKEY_new();
  assert(EVP_PKEY_assign_RSA(pkey, rsa));

Now I want to get the public key in PEM format:

  assert(EVP_PKEY_type(pkey->type) == EVP_PKEY_RSA);
  RSA *rsa = EVP_PKEY_get1_RSA(pkey);
  assert(rsa);

However, EVP_PKEY_get1_RSA(pkey) returns 0 with the error message
  3073587352:error:0607907F:digital envelope 
routines:EVP_PKEY_get1_RSA:expecting an rsa key:p_lib.c:288:

I had a look at the implementation of this function and found this:

  if(pkey->type != EVP_PKEY_RSA) {
    EVPerr(EVP_F_EVP_PKEY_GET1_RSA, EVP_R_EXPECTING_AN_RSA_KEY);
    return NULL;
  }

Why does EVP_PKEY_get1_RSA() compare the pkey->type directly against 
EVP_PKEY_RSA? I had expected that it compares EVP_PKEY_type(pkey->type) against 
EVP_PKEY_RSA!?

This is confusing since the manpage states

>> EVP_PKEY_type() returns the type of key corresponding to the value type. The 
>> type of a key can be obtained with EVP_PKEY_type(pkey->type). The return 
>> value will be EVP_PKEY_RSA, EVP_PKEY_DSA, EVP_PKEY_DH or EVP_PKEY_EC for the 
>> corresponding key types or NID_undef if the key type is unassigned. 

Where is my error in reasoning?

Cheers,

Manuel
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to