summaryrefslogtreecommitdiffstats
path: root/recipes-connectivity/openssl/openssl-qoriq/qoriq/0042-cryptodev-check-for-errors-inside-cryptodev_rsa_mod_.patch
blob: 218accb181bccabb4f3c8fa38904be24f3dd8144 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
From 402a2e4da471728fa537462d7a13aa35955cd6d8 Mon Sep 17 00:00:00 2001
From: Cristian Stoica <cristian.stoica@nxp.com>
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 <cristian.stoica@nxp.com>
---
 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