Openssl 3.0.0. EVP_PKEY RSA is NULL

Ken Goldman kgoldman at
Tue Sep 14 23:19:11 UTC 2021

I am doing the following, but the EVP_PKEY->pkey->rsa is null.
Am I misusing the API or missing a step?

(error checking removed)

     EVP_PKEY		*rsa_pub_key = NULL;
     EVP_PKEY_CTX 	*ctx = NULL;
     OSSL_PARAM_BLD 	*param_bld = NULL;
     OSSL_PARAM 		*params = NULL;

     BIGNUM *    n = NULL;
     BIGNUM *    e = NULL;

[these bignums are initialized using bin2bn]

	param_bld = OSSL_PARAM_BLD_new();
	irc = OSSL_PARAM_BLD_push_BN(param_bld, "n", n);
	irc = OSSL_PARAM_BLD_push_BN(param_bld, "e", e);
	params = OSSL_PARAM_BLD_to_param(param_bld);

(do I perhaps need an 'end'?

	ctx = EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL);
	irc = EVP_PKEY_fromdata_init(ctx);
	irc = EVP_PKEY_fromdata(ctx, (EVP_PKEY **)rsa_pub_key,		/* freed by caller */
				EVP_PKEY_PUBLIC_KEY, params);

Probing rsa_pub_key here in the debugger.

type = 6
references = 1
rsa = 0  (probably NULL)

More information about the openssl-users mailing list