1 From 402a2e4da471728fa537462d7a13aa35955cd6d8 Mon Sep 17 00:00:00 2001
2 From: Cristian Stoica <cristian.stoica@nxp.com>
3 Date: Tue, 9 Feb 2016 11:47:52 +0200
4 Subject: [PATCH 42/48] cryptodev: check for errors inside
5 cryptodev_rsa_mod_exp_async
7 Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
9 crypto/engine/eng_cryptodev.c | 33 +++++++++++++++++++++++++--------
10 1 file changed, 25 insertions(+), 8 deletions(-)
12 diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c
13 index 695848d..8e84972 100644
14 --- a/crypto/engine/eng_cryptodev.c
15 +++ b/crypto/engine/eng_cryptodev.c
16 @@ -2109,25 +2109,42 @@ static int
17 cryptodev_rsa_mod_exp_async(BIGNUM *r0, const BIGNUM *I, RSA *rsa,
18 BN_CTX *ctx, struct pkc_cookie_s *cookie)
20 - struct crypt_kop *kop = malloc(sizeof(struct crypt_kop));
21 + struct crypt_kop *kop;
22 int ret = 1, f_len, p_len, q_len;
23 unsigned char *f = NULL, *p = NULL, *q = NULL, *dp = NULL, *dq =
26 - if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp || !kop) {
27 + if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) {
31 + kop = malloc(sizeof(struct crypt_kop));
38 kop->crk_op = CRK_MOD_EXP_CRT;
39 f_len = BN_num_bytes(rsa->n);
40 - spcf_bn2bin_ex(I, &f, &f_len);
41 - spcf_bn2bin(rsa->p, &p, &p_len);
42 - spcf_bn2bin(rsa->q, &q, &q_len);
43 - spcf_bn2bin_ex(rsa->dmp1, &dp, &p_len);
44 - spcf_bn2bin_ex(rsa->iqmp, &c, &p_len);
45 - spcf_bn2bin_ex(rsa->dmq1, &dq, &q_len);
46 + if (spcf_bn2bin_ex(I, &f, &f_len) != 0) {
49 + if (spcf_bn2bin(rsa->p, &p, &p_len) != 0) {
52 + if (spcf_bn2bin(rsa->q, &q, &q_len) != 0) {
55 + if (spcf_bn2bin_ex(rsa->dmp1, &dp, &p_len) != 0) {
58 + if (spcf_bn2bin_ex(rsa->iqmp, &c, &p_len) != 0) {
61 + if (spcf_bn2bin_ex(rsa->dmq1, &dq, &q_len) != 0) {
64 /* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */
65 kop->crk_param[0].crp_p = p;
66 kop->crk_param[0].crp_nbits = p_len * 8;