]> code.ossystems Code Review - meta-freescale.git/blob
218accb181bccabb4f3c8fa38904be24f3dd8144
[meta-freescale.git] /
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
6
7 Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
8 ---
9  crypto/engine/eng_cryptodev.c | 33 +++++++++++++++++++++++++--------
10  1 file changed, 25 insertions(+), 8 deletions(-)
11
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)
19  {
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 =
24          NULL, *c = NULL;
25  
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) {
28          return (0);
29      }
30  
31 +    kop = malloc(sizeof(struct crypt_kop));
32 +    if (kop == NULL) {
33 +        goto err;
34 +    }
35 +
36      kop->crk_oparams = 0;
37      kop->crk_status = 0;
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) {
47 +        goto err;
48 +    }
49 +    if (spcf_bn2bin(rsa->p, &p, &p_len) != 0) {
50 +        goto err;
51 +    }
52 +    if (spcf_bn2bin(rsa->q, &q, &q_len) != 0) {
53 +        goto err;
54 +    }
55 +    if (spcf_bn2bin_ex(rsa->dmp1, &dp, &p_len) != 0) {
56 +        goto err;
57 +    }
58 +    if (spcf_bn2bin_ex(rsa->iqmp, &c, &p_len) != 0) {
59 +        goto err;
60 +    }
61 +    if (spcf_bn2bin_ex(rsa->dmq1, &dq, &q_len) != 0) {
62 +        goto err;
63 +    }
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;
67 -- 
68 2.7.0
69