summaryrefslogtreecommitdiffstats
path: root/recipes-connectivity/openssl/openssl-qoriq/qoriq/0043-cryptodev-check-for-errors-inside-cryptodev_dh_compu.patch
blob: 879d5c2cd334240f8c1e8a8c0b296ed96b4238da (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
From 73115f243f0a65326888537f125e31f28c9f570d Mon Sep 17 00:00:00 2001
From: Cristian Stoica <cristian.stoica@nxp.com>
Date: Tue, 9 Feb 2016 11:53:22 +0200
Subject: [PATCH 43/48] cryptodev: check for errors inside
 cryptodev_dh_compute_key

Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
---
 crypto/engine/eng_cryptodev.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c
index 7c391d6..753e326 100644
--- a/crypto/engine/eng_cryptodev.c
+++ b/crypto/engine/eng_cryptodev.c
@@ -4056,11 +4056,15 @@ cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
     memset(&kop, 0, sizeof kop);
     kop.crk_op = CRK_DH_COMPUTE_KEY;
     /* inputs: dh->priv_key pub_key dh->p key */
-    spcf_bn2bin(dh->p, &p, &p_len);
-    spcf_bn2bin_ex(pub_key, &padded_pub_key, &p_len);
-    if (bn2crparam(dh->priv_key, &kop.crk_param[0]))
+    if (spcf_bn2bin(dh->p, &p, &p_len) != 0) {
         goto sw_try;
-
+    }
+    if (spcf_bn2bin_ex(pub_key, &padded_pub_key, &p_len) != 0) {
+        goto sw_try;
+    }
+    if (bn2crparam(dh->priv_key, &kop.crk_param[0]) != 0) {
+        goto sw_try;
+    }
     kop.crk_param[1].crp_p = padded_pub_key;
     kop.crk_param[1].crp_nbits = p_len * 8;
     kop.crk_param[2].crp_p = p;
@@ -4087,10 +4091,13 @@ cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
     kop.crk_param[3].crp_p = NULL;
     zapparams(&kop);
     return (dhret);
+
  sw_try:
     {
         const DH_METHOD *meth = DH_OpenSSL();
 
+        free(p);
+        free(padded_pub_key);
         dhret = (meth->compute_key) (key, pub_key, dh);
     }
     return (dhret);
-- 
2.7.3