summaryrefslogtreecommitdiffhomepage
path: root/rsa.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2017-05-26 21:08:43 +0800
committerMatt Johnston <matt@ucc.asn.au>2017-05-26 21:08:43 +0800
commitc38927da47fa3c96cdcc7e4c81d9068bf01bf1fb (patch)
treec24afd4e5b05f485e6b42663d5dfdb335dc8117d /rsa.c
parent7ab8f61974601444046888da07f211c44e55e5a5 (diff)
add m_mp_free_multi, be more careful freeing when failing to load keys
Diffstat (limited to 'rsa.c')
-rw-r--r--rsa.c28
1 files changed, 3 insertions, 25 deletions
diff --git a/rsa.c b/rsa.c
index c09447f..1eac8ec 100644
--- a/rsa.c
+++ b/rsa.c
@@ -72,8 +72,7 @@ int buf_get_rsa_pub_key(buffer* buf, dropbear_rsa_key *key) {
ret = DROPBEAR_SUCCESS;
out:
if (ret == DROPBEAR_FAILURE) {
- m_free(key->e);
- m_free(key->n);
+ m_mp_free_multi(&key->e, &key->n, NULL);
}
return ret;
}
@@ -121,9 +120,7 @@ int buf_get_rsa_priv_key(buffer* buf, dropbear_rsa_key *key) {
ret = DROPBEAR_SUCCESS;
out:
if (ret == DROPBEAR_FAILURE) {
- m_free(key->d);
- m_free(key->p);
- m_free(key->q);
+ m_mp_free_multi(&key->d, &key->p, &key->q, NULL);
}
TRACE(("leave buf_get_rsa_priv_key"))
return ret;
@@ -139,26 +136,7 @@ void rsa_key_free(dropbear_rsa_key *key) {
TRACE2(("leave rsa_key_free: key == NULL"))
return;
}
- if (key->d) {
- mp_clear(key->d);
- m_free(key->d);
- }
- if (key->e) {
- mp_clear(key->e);
- m_free(key->e);
- }
- if (key->n) {
- mp_clear(key->n);
- m_free(key->n);
- }
- if (key->p) {
- mp_clear(key->p);
- m_free(key->p);
- }
- if (key->q) {
- mp_clear(key->q);
- m_free(key->q);
- }
+ m_mp_free_multi(&key->d, &key->e, &key->p, &key->q, &key->n, NULL);
m_free(key);
TRACE2(("leave rsa_key_free"))
}