Apply a change by Toomas Kiisk <vix@cyber.ee>:
* Fix a crashbug and a logic bug in hwcrhk_load_pubkey()
This commit is contained in:
parent
60a9cbdf28
commit
e4f165e71e
1 changed files with 14 additions and 10 deletions
|
@ -359,7 +359,7 @@ static int get_context(HWCryptoHook_ContextHandle *hac)
|
||||||
HWCryptoHook_ErrMsgBuf rmsg;
|
HWCryptoHook_ErrMsgBuf rmsg;
|
||||||
|
|
||||||
rmsg.buf = tempbuf;
|
rmsg.buf = tempbuf;
|
||||||
rmsg.size = 1024;
|
rmsg.size = sizeof(tempbuf);
|
||||||
|
|
||||||
*hac = p_hwcrhk_Init(&hwcrhk_globals, sizeof(hwcrhk_globals), &rmsg,
|
*hac = p_hwcrhk_Init(&hwcrhk_globals, sizeof(hwcrhk_globals), &rmsg,
|
||||||
NULL);
|
NULL);
|
||||||
|
@ -576,8 +576,12 @@ static EVP_PKEY *hwcrhk_load_privkey(const char *key_id,
|
||||||
EVP_PKEY *res = NULL;
|
EVP_PKEY *res = NULL;
|
||||||
HWCryptoHook_MPI e, n;
|
HWCryptoHook_MPI e, n;
|
||||||
HWCryptoHook_RSAKeyHandle *hptr;
|
HWCryptoHook_RSAKeyHandle *hptr;
|
||||||
|
char tempbuf[1024];
|
||||||
HWCryptoHook_ErrMsgBuf rmsg;
|
HWCryptoHook_ErrMsgBuf rmsg;
|
||||||
|
|
||||||
|
rmsg.buf = tempbuf;
|
||||||
|
rmsg.size = sizeof(tempbuf);
|
||||||
|
|
||||||
if(!hwcrhk_context)
|
if(!hwcrhk_context)
|
||||||
{
|
{
|
||||||
ENGINEerr(ENGINE_F_HWCRHK_LOAD_PRIVKEY,
|
ENGINEerr(ENGINE_F_HWCRHK_LOAD_PRIVKEY,
|
||||||
|
@ -665,9 +669,12 @@ static EVP_PKEY *hwcrhk_load_pubkey(const char *key_id, const char *passphrase)
|
||||||
res->pkey.rsa = RSA_new();
|
res->pkey.rsa = RSA_new();
|
||||||
res->pkey.rsa->n = rsa->n;
|
res->pkey.rsa->n = rsa->n;
|
||||||
res->pkey.rsa->e = rsa->e;
|
res->pkey.rsa->e = rsa->e;
|
||||||
|
rsa->n = NULL;
|
||||||
|
rsa->e = NULL;
|
||||||
CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);
|
CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);
|
||||||
RSA_free(rsa);
|
RSA_free(rsa);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
ENGINEerr(ENGINE_F_HWCRHK_LOAD_PUBKEY,
|
ENGINEerr(ENGINE_F_HWCRHK_LOAD_PUBKEY,
|
||||||
ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED);
|
ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED);
|
||||||
|
@ -695,7 +702,7 @@ static int hwcrhk_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
|
||||||
|
|
||||||
to_return = 0; /* expect failure */
|
to_return = 0; /* expect failure */
|
||||||
rmsg.buf = tempbuf;
|
rmsg.buf = tempbuf;
|
||||||
rmsg.size = 1024;
|
rmsg.size = sizeof(tempbuf);
|
||||||
|
|
||||||
if(!hwcrhk_context)
|
if(!hwcrhk_context)
|
||||||
{
|
{
|
||||||
|
@ -745,6 +752,9 @@ static int hwcrhk_rsa_mod_exp(BIGNUM *r, BIGNUM *I, RSA *rsa)
|
||||||
HWCryptoHook_RSAKeyHandle *hptr;
|
HWCryptoHook_RSAKeyHandle *hptr;
|
||||||
int to_return = 0, ret;
|
int to_return = 0, ret;
|
||||||
|
|
||||||
|
rmsg.buf = tempbuf;
|
||||||
|
rmsg.size = sizeof(tempbuf);
|
||||||
|
|
||||||
if(!hwcrhk_context)
|
if(!hwcrhk_context)
|
||||||
{
|
{
|
||||||
ENGINEerr(ENGINE_F_HWCRHK_MOD_EXP,ENGINE_R_NOT_INITIALISED);
|
ENGINEerr(ENGINE_F_HWCRHK_MOD_EXP,ENGINE_R_NOT_INITIALISED);
|
||||||
|
@ -766,9 +776,6 @@ static int hwcrhk_rsa_mod_exp(BIGNUM *r, BIGNUM *I, RSA *rsa)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
rmsg.buf = tempbuf;
|
|
||||||
rmsg.size = 1024;
|
|
||||||
|
|
||||||
/* Prepare the params */
|
/* Prepare the params */
|
||||||
bn_expand2(r, rsa->n->top); /* Check for error !! */
|
bn_expand2(r, rsa->n->top); /* Check for error !! */
|
||||||
BN2MPI(m_a, I);
|
BN2MPI(m_a, I);
|
||||||
|
@ -809,9 +816,6 @@ static int hwcrhk_rsa_mod_exp(BIGNUM *r, BIGNUM *I, RSA *rsa)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
rmsg.buf = tempbuf;
|
|
||||||
rmsg.size = 1024;
|
|
||||||
|
|
||||||
/* Prepare the params */
|
/* Prepare the params */
|
||||||
bn_expand2(r, rsa->n->top); /* Check for error !! */
|
bn_expand2(r, rsa->n->top); /* Check for error !! */
|
||||||
BN2MPI(m_a, I);
|
BN2MPI(m_a, I);
|
||||||
|
@ -876,7 +880,7 @@ static int hwcrhk_rand_bytes(unsigned char *buf, int num)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
rmsg.buf = tempbuf;
|
rmsg.buf = tempbuf;
|
||||||
rmsg.size = 1024;
|
rmsg.size = sizeof(tempbuf);
|
||||||
|
|
||||||
if(!hwcrhk_context)
|
if(!hwcrhk_context)
|
||||||
{
|
{
|
||||||
|
@ -922,7 +926,7 @@ static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
rmsg.buf = tempbuf;
|
rmsg.buf = tempbuf;
|
||||||
rmsg.size = 1024;
|
rmsg.size = sizeof(tempbuf);
|
||||||
|
|
||||||
hptr = (HWCryptoHook_RSAKeyHandle *) item;
|
hptr = (HWCryptoHook_RSAKeyHandle *) item;
|
||||||
if(!hptr) return;
|
if(!hptr) return;
|
||||||
|
|
Loading…
Reference in a new issue