BIO_free(bf);
static EVP_PKEY *tpm_engine_load_key(ENGINE *e, const char *key_id,				     UI_METHOD *ui, void *cb_data){	TSS_HKEY hKey;	TSS_RESULT result;	BYTE blob_buf[4096];	UINT32 authusage;	RSA *rsa;	EVP_PKEY *pkey;	BIO *bf;	int rc;	DBG("%s", __FUNCTION__);	if (!key_id) {		TSSerr(TPM_F_TPM_ENGINE_LOAD_KEY, ERR_R_PASSED_NULL_PARAMETER);		return NULL;	}	if (!tpm_load_srk(ui)) {		TSSerr(TPM_F_TPM_ENGINE_LOAD_KEY, TPM_R_SRK_LOAD_FAILED);		return NULL;	}	if ((bf = BIO_new_file(key_id, "r")) == NULL) {		TSSerr(TPM_F_TPM_ENGINE_LOAD_KEY,		       TPM_R_FILE_NOT_FOUND);		return NULL;	}retry:	if ((rc = BIO_read(bf, &blob_buf[0], 4096)) < 0) {		TSSerr(TPM_F_TPM_ENGINE_LOAD_KEY,		       TPM_R_FILE_READ_FAILED);		return NULL;	} else if (rc == 0 && BIO_should_retry(bf)) {		goto retry;	}	DBG("Loading blob of size: %d", rc);	if ((result = p_tspi_Context_LoadKeyByBlob(hContext, hSRK, rc,					blob_buf, &hKey))) {		TSSerr(TPM_F_TPM_ENGINE_LOAD_KEY,		       TPM_R_REQUEST_FAILED);		return NULL;	}	if ((result = p_tspi_GetAttribUint32(hKey, TSS_TSPATTRIB_KEY_INFO,					     TSS_TSPATTRIB_KEYINFO_AUTHUSAGE,					     &authusage))) {		p_tspi_Context_CloseObject(hContext, hKey);		TSSerr(TPM_F_TPM_ENGINE_LOAD_KEY,		       TPM_R_REQUEST_FAILED);		return NULL;	}	if (authusage) {		TSS_HPOLICY hPolicy;		BYTE *auth;		if ((auth = calloc(1, 128)) == NULL) {			p_tspi_Context_CloseObject(hContext, hKey);			TSSerr(TPM_F_TPM_ENGINE_LOAD_KEY, ERR_R_MALLOC_FAILURE);			return NULL;		}		if (!tpm_engine_get_auth(ui, auth, 128,					 "TPM Key Password: ")) {			p_tspi_Context_CloseObject(hContext, hKey);			free(auth);			TSSerr(TPM_F_TPM_ENGINE_LOAD_KEY, TPM_R_REQUEST_FAILED);			return NULL;		}		if ((result = p_tspi_GetPolicyObject(hKey, TSS_POLICY_USAGE,						     &hPolicy))) {			p_tspi_Context_CloseObject(hContext, hKey);			free(auth);			TSSerr(TPM_F_TPM_ENGINE_LOAD_KEY, TPM_R_REQUEST_FAILED);			return 0;		}		if ((result = p_tspi_Policy_SetSecret(hPolicy,						      TSS_SECRET_MODE_PLAIN,						      strlen(auth), auth))) {			p_tspi_Context_CloseObject(hContext, hKey);			free(auth);			TSSerr(TPM_F_TPM_ENGINE_LOAD_KEY, TPM_R_REQUEST_FAILED);			return 0;		}		free(auth);	}	/* create the new objects to return */	if ((pkey = EVP_PKEY_new()) == NULL) {		p_tspi_Context_CloseObject(hContext, hKey);		TSSerr(TPM_F_TPM_ENGINE_LOAD_KEY, ERR_R_MALLOC_FAILURE);		return NULL;	}	pkey->type = EVP_PKEY_RSA;	if ((rsa = RSA_new()) == NULL) {		EVP_PKEY_free(pkey);		p_tspi_Context_CloseObject(hContext, hKey);		TSSerr(TPM_F_TPM_ENGINE_LOAD_KEY, ERR_R_MALLOC_FAILURE);		return NULL;	}	rsa->meth = &tpm_rsa;	/* call our local init function here */	rsa->meth->init(rsa);	pkey->pkey.rsa = rsa;	if (!fill_out_rsa_object(rsa, hKey)) {		EVP_PKEY_free(pkey);		RSA_free(rsa);		p_tspi_Context_CloseObject(hContext, hKey);		TSSerr(TPM_F_TPM_ENGINE_LOAD_KEY, TPM_R_REQUEST_FAILED);		return NULL;	}	return pkey;}