From 402a2e4da471728fa537462d7a13aa35955cd6d8 Mon Sep 17 00:00:00 2001 From: Cristian Stoica Date: Tue, 9 Feb 2016 11:47:52 +0200 Subject: [PATCH 42/48] cryptodev: check for errors inside cryptodev_rsa_mod_exp_async Signed-off-by: Cristian Stoica --- crypto/engine/eng_cryptodev.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c index 695848d..8e84972 100644 --- a/crypto/engine/eng_cryptodev.c +++ b/crypto/engine/eng_cryptodev.c @@ -2109,25 +2109,42 @@ static int cryptodev_rsa_mod_exp_async(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx, struct pkc_cookie_s *cookie) { - struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); + struct crypt_kop *kop; int ret = 1, f_len, p_len, q_len; unsigned char *f = NULL, *p = NULL, *q = NULL, *dp = NULL, *dq = NULL, *c = NULL; - if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp || !kop) { + if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) { return (0); } + kop = malloc(sizeof(struct crypt_kop)); + if (kop == NULL) { + goto err; + } + kop->crk_oparams = 0; kop->crk_status = 0; kop->crk_op = CRK_MOD_EXP_CRT; f_len = BN_num_bytes(rsa->n); - spcf_bn2bin_ex(I, &f, &f_len); - spcf_bn2bin(rsa->p, &p, &p_len); - spcf_bn2bin(rsa->q, &q, &q_len); - spcf_bn2bin_ex(rsa->dmp1, &dp, &p_len); - spcf_bn2bin_ex(rsa->iqmp, &c, &p_len); - spcf_bn2bin_ex(rsa->dmq1, &dq, &q_len); + if (spcf_bn2bin_ex(I, &f, &f_len) != 0) { + goto err; + } + if (spcf_bn2bin(rsa->p, &p, &p_len) != 0) { + goto err; + } + if (spcf_bn2bin(rsa->q, &q, &q_len) != 0) { + goto err; + } + if (spcf_bn2bin_ex(rsa->dmp1, &dp, &p_len) != 0) { + goto err; + } + if (spcf_bn2bin_ex(rsa->iqmp, &c, &p_len) != 0) { + goto err; + } + if (spcf_bn2bin_ex(rsa->dmq1, &dq, &q_len) != 0) { + goto err; + } /* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */ kop->crk_param[0].crp_p = p; kop->crk_param[0].crp_nbits = p_len * 8; -- 2.7.0