plug memory leaks
This commit is contained in:
@@ -155,16 +155,13 @@ static int
|
|||||||
ltm_dh_compute_key(unsigned char *shared, const BIGNUM * pub, DH *dh)
|
ltm_dh_compute_key(unsigned char *shared, const BIGNUM * pub, DH *dh)
|
||||||
{
|
{
|
||||||
mp_int s, priv_key, p, peer_pub;
|
mp_int s, priv_key, p, peer_pub;
|
||||||
size_t size = 0;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (dh->pub_key == NULL || dh->g == NULL || dh->priv_key == NULL)
|
if (dh->pub_key == NULL || dh->g == NULL || dh->priv_key == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
mp_init(&p);
|
mp_init_multi(&s, &priv_key, &p, &peer_pub, NULL);
|
||||||
BN2mpz(&p, dh->p);
|
BN2mpz(&p, dh->p);
|
||||||
|
|
||||||
mp_init(&peer_pub);
|
|
||||||
BN2mpz(&peer_pub, pub);
|
BN2mpz(&peer_pub, pub);
|
||||||
|
|
||||||
/* check if peers pubkey is reasonable */
|
/* check if peers pubkey is reasonable */
|
||||||
@@ -172,30 +169,28 @@ ltm_dh_compute_key(unsigned char *shared, const BIGNUM * pub, DH *dh)
|
|||||||
|| mp_cmp(&peer_pub, &p) >= 0
|
|| mp_cmp(&peer_pub, &p) >= 0
|
||||||
|| mp_cmp_d(&peer_pub, 1) <= 0)
|
|| mp_cmp_d(&peer_pub, 1) <= 0)
|
||||||
{
|
{
|
||||||
mp_zero(&p);
|
ret = -1;
|
||||||
mp_zero(&peer_pub);
|
goto out;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_init(&priv_key);
|
|
||||||
BN2mpz(&priv_key, dh->priv_key);
|
BN2mpz(&priv_key, dh->priv_key);
|
||||||
|
|
||||||
mp_init(&s);
|
mp_init(&s);
|
||||||
|
|
||||||
ret = mp_exptmod(&peer_pub, &priv_key, &p, &s);
|
ret = mp_exptmod(&peer_pub, &priv_key, &p, &s);
|
||||||
|
|
||||||
mp_zero(&p);
|
if (ret != 0) {
|
||||||
mp_zero(&peer_pub);
|
ret = -1;
|
||||||
mp_zero(&priv_key);
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (ret != 0)
|
ret = mp_unsigned_bin_size(&s);
|
||||||
return -1;
|
|
||||||
|
|
||||||
size = mp_unsigned_bin_size(&s);
|
|
||||||
mp_to_unsigned_bin(&s, shared);
|
mp_to_unsigned_bin(&s, shared);
|
||||||
mp_zero(&s);
|
|
||||||
|
|
||||||
return size;
|
out:
|
||||||
|
mp_zero_multi(&s, &priv_key, &p, &peer_pub, NULL);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
Reference in New Issue
Block a user