vidyadhar
vidyadhar

Reputation: 1

Trying to decrypt data using tpm private key with openssl API's But ossl_ctx is not compatible with EVP_KEY_decrypt_init(ctx)

OSSL_STORE_CTX *ctx = OSSL_STORE_open(tpm_key_path, nullptr, nullptr, nullptr, nullptr);

OSSL_STORE_INFO *info;

while (!OSSL_STORE_eof(ctx)) { if ((info = OSSL_STORE_load(ctx)) == nullptr) { printf("Failed in OSSL_STORE_load : %d",res); } if ((key = OSSL_STORE_INFO_get1_PKEY(info)) == nullptr) { printf("Failed in OSSL_STORE_INFO_get1_PKEY : %d",res); } break; }

if(key) { if (ctx) { EVP_PKEY_decrypt_init(ctx); EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, NULL) EVP_PKEY_CTX_set_rsa_padding(ctx, padding); } }

error: cannot convert ‘OSSL_STORE_CTX*’ {aka ‘ossl_store_ctx_st*’} to ‘EVP_PKEY_CTX*’ {aka ‘evp_pkey_ctx_st*’} 335 | EVP_PKEY_decrypt_init(ctx); | ^~~ | | | OSSL_STORE_CTX* {aka ossl_store_ctx_st*}

Upvotes: -2

Views: 195

Answers (1)

Shane Powell
Shane Powell

Reputation: 14138

You need to use EVP_PKEY_CTX_new to create a EVP_PKEY_CTX* from the EVP_PKEY* value.

e.g.

EVP_PKEY_CTX* pctx = EVP_PKEY_CTX_new(key, nullptr);
if (pctx)
{
    EVP_PKEY_decrypt_init(pctx);

Upvotes: 0

Related Questions