summaryrefslogtreecommitdiff
path: root/source4/heimdal/lib/hcrypto/dh-ltm.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2010-11-11 11:27:33 +1100
committerAndrew Bartlett <abartlet@samba.org>2010-11-15 01:25:06 +0000
commit1342185e333cb8139b7a70b7fe43571bcc2716a7 (patch)
tree0e1cb8d3cfc437bd7cc3a97f2bdc472f54d95dbd /source4/heimdal/lib/hcrypto/dh-ltm.c
parent13fd22f61017124d2d4964db3e32c667d119b56c (diff)
downloadsamba-1342185e333cb8139b7a70b7fe43571bcc2716a7.tar.gz
samba-1342185e333cb8139b7a70b7fe43571bcc2716a7.tar.bz2
samba-1342185e333cb8139b7a70b7fe43571bcc2716a7.zip
s4:heimdal: import lorikeet-heimdal-201011102149 (commit 5734d03c20e104c8f45533d07f2a2cbbd3224f29)
Diffstat (limited to 'source4/heimdal/lib/hcrypto/dh-ltm.c')
-rw-r--r--source4/heimdal/lib/hcrypto/dh-ltm.c41
1 files changed, 16 insertions, 25 deletions
diff --git a/source4/heimdal/lib/hcrypto/dh-ltm.c b/source4/heimdal/lib/hcrypto/dh-ltm.c
index 6166100b08..f66cd5aff2 100644
--- a/source4/heimdal/lib/hcrypto/dh-ltm.c
+++ b/source4/heimdal/lib/hcrypto/dh-ltm.c
@@ -119,14 +119,12 @@ ltm_dh_generate_key(DH *dh)
res = mp_exptmod(&g, &priv_key, &p, &pub);
- mp_zero(&priv_key);
- mp_zero(&g);
- mp_zero(&p);
+ mp_clear_multi(&priv_key, &g, &p, NULL);
if (res != 0)
continue;
dh->pub_key = mpz2BN(&pub);
- mp_zero(&pub);
+ mp_clear(&pub);
if (dh->pub_key == NULL)
return 0;
@@ -155,16 +153,13 @@ static int
ltm_dh_compute_key(unsigned char *shared, const BIGNUM * pub, DH *dh)
{
mp_int s, priv_key, p, peer_pub;
- size_t size = 0;
int ret;
if (dh->pub_key == NULL || dh->g == NULL || dh->priv_key == NULL)
return -1;
- mp_init(&p);
+ mp_init_multi(&s, &priv_key, &p, &peer_pub, NULL);
BN2mpz(&p, dh->p);
-
- mp_init(&peer_pub);
BN2mpz(&peer_pub, pub);
/* check if peers pubkey is reasonable */
@@ -172,30 +167,26 @@ ltm_dh_compute_key(unsigned char *shared, const BIGNUM * pub, DH *dh)
|| mp_cmp(&peer_pub, &p) >= 0
|| mp_cmp_d(&peer_pub, 1) <= 0)
{
- mp_zero(&p);
- mp_zero(&peer_pub);
- return -1;
+ ret = -1;
+ goto out;
}
- mp_init(&priv_key);
BN2mpz(&priv_key, dh->priv_key);
- mp_init(&s);
-
ret = mp_exptmod(&peer_pub, &priv_key, &p, &s);
- mp_zero(&p);
- mp_zero(&peer_pub);
- mp_zero(&priv_key);
-
- if (ret != 0)
- return -1;
+ if (ret != 0) {
+ ret = -1;
+ goto out;
+ }
- size = mp_unsigned_bin_size(&s);
+ ret = mp_unsigned_bin_size(&s);
mp_to_unsigned_bin(&s, shared);
- mp_zero(&s);
- return size;
+ out:
+ mp_clear_multi(&s, &priv_key, &p, &peer_pub, NULL);
+
+ return ret;
}
static int
@@ -235,9 +226,9 @@ const DH_METHOD _hc_dh_ltm_method = {
};
/**
- * DH implementation using libimath.
+ * DH implementation using libtommath.
*
- * @return the DH_METHOD for the DH implementation using libimath.
+ * @return the DH_METHOD for the DH implementation using libtommath.
*
* @ingroup hcrypto_dh
*/