rmsg.buf = tempbuf; rmsg.size = 1024;
static int hwcrhk_rsa_mod_exp(BIGNUM *r, const BIGNUM *I, RSA *rsa)	{	char tempbuf[1024];	HWCryptoHook_ErrMsgBuf rmsg;	HWCryptoHook_RSAKeyHandle *hptr;	int to_return = 0, ret;	if(!hwcrhk_context)		{		HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_NOT_INITIALISED);		goto err;		}	/* This provides support for nForce keys.  Since that's opaque data	   all we do is provide a handle to the proper key and let HWCryptoHook	   take care of the rest. */	if ((hptr = (HWCryptoHook_RSAKeyHandle *) RSA_get_ex_data(rsa, hndidx_rsa))		!= NULL)		{		HWCryptoHook_MPI m_a, m_r;		if(!rsa->n)			{			HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP,				HWCRHK_R_MISSING_KEY_COMPONENTS);			goto err;			}		rmsg.buf = tempbuf;		rmsg.size = 1024;		/* Prepare the params */		bn_expand2(r, rsa->n->top); /* Check for error !! */		BN2MPI(m_a, I);		MPI2BN(r, m_r);		/* Perform the operation */		ret = p_hwcrhk_RSA(m_a, *hptr, &m_r, &rmsg);		/* Convert the response */		r->top = m_r.size / sizeof(BN_ULONG);		bn_fix_top(r);		if (ret < 0)			{			/* FIXME: When this error is returned, HWCryptoHook is			   telling us that falling back to software computation			   might be a good thing. */			if(ret == HWCRYPTOHOOK_ERROR_FALLBACK)				{				HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP,					HWCRHK_R_REQUEST_FALLBACK);				}			else				{				HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP,					HWCRHK_R_REQUEST_FAILED);				}			ERR_add_error_data(1,rmsg.buf);			goto err;			}		}	else		{		HWCryptoHook_MPI m_a, m_p, m_q, m_dmp1, m_dmq1, m_iqmp, m_r;		if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)			{			HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP,				HWCRHK_R_MISSING_KEY_COMPONENTS);			goto err;			}		rmsg.buf = tempbuf;		rmsg.size = 1024;		/* Prepare the params */		bn_expand2(r, rsa->n->top); /* Check for error !! */		BN2MPI(m_a, I);		BN2MPI(m_p, rsa->p);		BN2MPI(m_q, rsa->q);		BN2MPI(m_dmp1, rsa->dmp1);		BN2MPI(m_dmq1, rsa->dmq1);		BN2MPI(m_iqmp, rsa->iqmp);		MPI2BN(r, m_r);		/* Perform the operation */		ret = p_hwcrhk_ModExpCRT(hwcrhk_context, m_a, m_p, m_q,			m_dmp1, m_dmq1, m_iqmp, &m_r, NULL);		/* Convert the response */		r->top = m_r.size / sizeof(BN_ULONG);		bn_fix_top(r);		if (ret < 0)			{			/* FIXME: When this error is returned, HWCryptoHook is			   telling us that falling back to software computation			   might be a good thing. */			if(ret == HWCRYPTOHOOK_ERROR_FALLBACK)				{				HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP,					HWCRHK_R_REQUEST_FALLBACK);				}			else				{				HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP,					HWCRHK_R_REQUEST_FAILED);				}			ERR_add_error_data(1,rmsg.buf);			goto err;			}		}	/* If we're here, we must be here with some semblance of success :-) */	to_return = 1;err:	return to_return;	}