Commit 7abe8305 authored by Geoff Thorpe's avatar Geoff Thorpe
Browse files

Ensure that the "ex_data" member of an RSA structure is initialised before

the RSA_METHOD's "init()" handler is called, and is cleaned up after the
RSA_METHOD's "finish()" handler is called. Custom RSA_METHODs may wish to
initialise contexts and other specifics in the RSA structure upon creation
and that was previously not possible - "ex_data" is where that stuff
should go and it was being initialised too late for it to be used.
parent 5acaa495
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -191,13 +191,13 @@ RSA *RSA_new_method(ENGINE *engine)
	ret->blinding=NULL;
	ret->bignum_data=NULL;
	ret->flags=meth->flags;
	CRYPTO_new_ex_data(rsa_meth,ret,&ret->ex_data);
	if ((meth->init != NULL) && !meth->init(ret))
		{
		CRYPTO_free_ex_data(rsa_meth, ret, &ret->ex_data);
		OPENSSL_free(ret);
		ret=NULL;
		}
	else
		CRYPTO_new_ex_data(rsa_meth,ret,&ret->ex_data);
	return(ret);
	}

@@ -221,13 +221,13 @@ void RSA_free(RSA *r)
		}
#endif

	CRYPTO_free_ex_data(rsa_meth,r,&r->ex_data);

	meth = ENGINE_get_RSA(r->engine);
	if (meth->finish != NULL)
		meth->finish(r);
	ENGINE_finish(r->engine);

	CRYPTO_free_ex_data(rsa_meth,r,&r->ex_data);

	if (r->n != NULL) BN_clear_free(r->n);
	if (r->e != NULL) BN_clear_free(r->e);
	if (r->d != NULL) BN_clear_free(r->d);