]> code.ossystems Code Review - meta-freescale.git/blob
879d5c2cd334240f8c1e8a8c0b296ed96b4238da
[meta-freescale.git] /
1 From 73115f243f0a65326888537f125e31f28c9f570d 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 7c391d6..753e326 100644
14 --- a/crypto/engine/eng_cryptodev.c
15 +++ b/crypto/engine/eng_cryptodev.c
16 @@ -4056,11 +4056,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 @@ -4087,10 +4091,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.3
52