]> code.ossystems Code Review - meta-freescale.git/blob
931141de680bc0a240a0b91d5c443db2a3a6cf29
[meta-freescale.git] /
1 From c8a5f714d35c3bd63d2511ad69e0661a7d1d5dcd Mon Sep 17 00:00:00 2001
2 From: Cristian Stoica <cristian.stoica@nxp.com>
3 Date: Tue, 9 Feb 2016 11:53:22 +0200
4 Subject: [PATCH 43/48] cryptodev: check for errors inside
5  cryptodev_dh_compute_key
6
7 Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
8 ---
9  crypto/engine/eng_cryptodev.c | 15 +++++++++++----
10  1 file changed, 11 insertions(+), 4 deletions(-)
11
12 diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c
13 index 8e84972..55b2047 100644
14 --- a/crypto/engine/eng_cryptodev.c
15 +++ b/crypto/engine/eng_cryptodev.c
16 @@ -4043,11 +4043,15 @@ cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
17      memset(&kop, 0, sizeof kop);
18      kop.crk_op = CRK_DH_COMPUTE_KEY;
19      /* inputs: dh->priv_key pub_key dh->p key */
20 -    spcf_bn2bin(dh->p, &p, &p_len);
21 -    spcf_bn2bin_ex(pub_key, &padded_pub_key, &p_len);
22 -    if (bn2crparam(dh->priv_key, &kop.crk_param[0]))
23 +    if (spcf_bn2bin(dh->p, &p, &p_len) != 0) {
24          goto sw_try;
25 -
26 +    }
27 +    if (spcf_bn2bin_ex(pub_key, &padded_pub_key, &p_len) != 0) {
28 +        goto sw_try;
29 +    }
30 +    if (bn2crparam(dh->priv_key, &kop.crk_param[0]) != 0) {
31 +        goto sw_try;
32 +    }
33      kop.crk_param[1].crp_p = padded_pub_key;
34      kop.crk_param[1].crp_nbits = p_len * 8;
35      kop.crk_param[2].crp_p = p;
36 @@ -4074,10 +4078,13 @@ cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
37      kop.crk_param[3].crp_p = NULL;
38      zapparams(&kop);
39      return (dhret);
40 +
41   sw_try:
42      {
43          const DH_METHOD *meth = DH_OpenSSL();
44  
45 +        free(p);
46 +        free(padded_pub_key);
47          dhret = (meth->compute_key) (key, pub_key, dh);
48      }
49      return (dhret);
50 -- 
51 2.7.0
52