diff --git a/bignum.c b/bignum.c
index 886568d5d99a5d04bd96e9ceade2dda3e6e142ac..e9810b3ec4fdb1c91d3a0e66f5b533f227a176c9 100644
--- a/bignum.c
+++ b/bignum.c
@@ -52,6 +52,22 @@ void m_mp_init_multi(mp_int *mp, ...)
     va_end(args);
 }
 
+void m_mp_alloc_init_multi(mp_int **mp, ...) 
+{
+    mp_int** cur_arg = mp;
+    va_list args;
+
+    va_start(args, mp);        /* init args to next argument from caller */
+    while (cur_arg != NULL) {
+    	*cur_arg = m_malloc(sizeof(mp_int));
+        if (mp_init(*cur_arg) != MP_OKAY) {
+			dropbear_exit("Mem alloc error");
+        }
+        cur_arg = va_arg(args, mp_int**);
+    }
+    va_end(args);
+}
+
 void bytes_to_mp(mp_int *mp, const unsigned char* bytes, unsigned int len) {
 
 	if (mp_read_unsigned_bin(mp, (unsigned char*)bytes, len) != MP_OKAY) {
diff --git a/bignum.h b/bignum.h
index 11353c653056461bf3821aa85a18e589b3859b51..f9710d72872da574ab78c5b99b70a47e884c4006 100644
--- a/bignum.h
+++ b/bignum.h
@@ -30,6 +30,7 @@
 
 void m_mp_init(mp_int *mp);
 void m_mp_init_multi(mp_int *mp, ...) ATTRIB_SENTINEL;
+void m_mp_alloc_init_multi(mp_int **mp, ...) ATTRIB_SENTINEL;
 void bytes_to_mp(mp_int *mp, const unsigned char* bytes, unsigned int len);
 void hash_process_mp(const struct ltc_hash_descriptor *hash_desc, 
 				hash_state *hs, mp_int *mp);
diff --git a/common-kex.c b/common-kex.c
index 0cd3db38bd0ab0125f3ad575f047f9ac753a7e27..a32ca6d5cafba9412f10302859a0b02536519eb4 100644
--- a/common-kex.c
+++ b/common-kex.c
@@ -633,8 +633,7 @@ void kexdh_comb_key(struct kex_dh_param *param, mp_int *dh_pub_them,
 	}
 	
 	/* K = e^y mod p = f^x mod p */
-	ses.dh_K = (mp_int*)m_malloc(sizeof(mp_int));
-	m_mp_init(ses.dh_K);
+	m_mp_alloc_init_multi(&ses.dh_K, NULL);
 	if (mp_exptmod(dh_pub_them, &param->priv, &dh_p, ses.dh_K) != MP_OKAY) {
 		dropbear_exit("Diffie-Hellman error");
 	}
diff --git a/dss.c b/dss.c
index 9817392777cee4eeb0779cef68f756aa7c81f1ad..b3b2bb1eb04af159babff40058d7fd0ad905bdd9 100644
--- a/dss.c
+++ b/dss.c
@@ -47,11 +47,7 @@ int buf_get_dss_pub_key(buffer* buf, dropbear_dss_key *key) {
 
 	TRACE(("enter buf_get_dss_pub_key"))
 	dropbear_assert(key != NULL);
-	key->p = m_malloc(sizeof(mp_int));
-	key->q = m_malloc(sizeof(mp_int));
-	key->g = m_malloc(sizeof(mp_int));
-	key->y = m_malloc(sizeof(mp_int));
-	m_mp_init_multi(key->p, key->q, key->g, key->y, NULL);
+	m_mp_alloc_init_multi(&key->p, &key->q, &key->g, &key->y, NULL);
 	key->x = NULL;
 
 	buf_incrpos(buf, 4+SSH_SIGNKEY_DSS_LEN); /* int + "ssh-dss" */
@@ -87,8 +83,7 @@ int buf_get_dss_priv_key(buffer* buf, dropbear_dss_key *key) {
 		return DROPBEAR_FAILURE;
 	}
 
-	key->x = m_malloc(sizeof(mp_int));
-	m_mp_init(key->x);
+	m_mp_alloc_init_multi(&key->x, NULL);
 	ret = buf_getmpint(buf, key->x);
 	if (ret == DROPBEAR_FAILURE) {
 		m_free(key->x);
diff --git a/ecc.c b/ecc.c
index 03f88640f91c93b41e9f885d11bd9f9e4bf9aab3..3e0763c704190c6796a499e40de67bc4ac1df43d 100644
--- a/ecc.c
+++ b/ecc.c
@@ -72,11 +72,8 @@ struct dropbear_ecc_curve* curve_for_dp(const ltc_ecc_set_type *dp) {
 
 ecc_key * new_ecc_key(void) {
 	ecc_key *key = m_malloc(sizeof(*key));
-	key->pubkey.x = m_malloc(sizeof(mp_int));
-	key->pubkey.y = m_malloc(sizeof(mp_int));
-	key->pubkey.z = m_malloc(sizeof(mp_int));
-	key->k = m_malloc(sizeof(mp_int));
-	m_mp_init_multi(key->pubkey.x, key->pubkey.y, key->pubkey.z, key->k, NULL);
+	m_mp_alloc_init_multi(&key->pubkey.x, &key->pubkey.y, 
+		&key->pubkey.z, &key->k, NULL);
 	return key;
 }
 
@@ -92,7 +89,7 @@ static int ecc_is_point(ecc_key *key)
 	t1 = m_malloc(sizeof(mp_int));
 	t2 = m_malloc(sizeof(mp_int));
 	
-	m_mp_init_multi(prime, b, t1, t2, NULL);
+	m_mp_alloc_init_multi(&prime, &b, &t1, &t2, NULL);
 	
    /* load prime and b */
 	if ((err = mp_read_radix(prime, key->dp->prime, 16)) != CRYPT_OK)                          { goto error; }
diff --git a/gendss.c b/gendss.c
index be8f89f052cab9b2d08af39be569fa359aa6ca06..2785aecd69a94c438a5a1bdce0e5bf9c2cf8dc19 100644
--- a/gendss.c
+++ b/gendss.c
@@ -53,12 +53,7 @@ dropbear_dss_key * gen_dss_priv_key(unsigned int size) {
 
 	key = m_malloc(sizeof(*key));
 
-	key->p = (mp_int*)m_malloc(sizeof(mp_int));
-	key->q = (mp_int*)m_malloc(sizeof(mp_int));
-	key->g = (mp_int*)m_malloc(sizeof(mp_int));
-	key->y = (mp_int*)m_malloc(sizeof(mp_int));
-	key->x = (mp_int*)m_malloc(sizeof(mp_int));
-	m_mp_init_multi(key->p, key->q, key->g, key->y, key->x, NULL);
+	m_mp_alloc_init_multi(&key->p, &key->q, &key->g, &key->y, &key->x, NULL);
 	
 	getq(key);
 	getp(key, size/8);
diff --git a/genrsa.c b/genrsa.c
index 465502b18b7e5a163ab182326ac5ed3abe53679b..5df191e829dfc9f3e9e06b0c1ded2c6a79ed4d33 100644
--- a/genrsa.c
+++ b/genrsa.c
@@ -50,15 +50,8 @@ dropbear_rsa_key * gen_rsa_priv_key(unsigned int size) {
 	}
 
 	key = m_malloc(sizeof(*key));
-
-	key->e = (mp_int*)m_malloc(sizeof(mp_int));
-	key->n = (mp_int*)m_malloc(sizeof(mp_int));
-	key->d = (mp_int*)m_malloc(sizeof(mp_int));
-	key->p = (mp_int*)m_malloc(sizeof(mp_int));
-	key->q = (mp_int*)m_malloc(sizeof(mp_int));
-
-	m_mp_init_multi(key->e, key->n, key->d, key->p, key->q,
-			&pminus, &lcm, &qminus, NULL);
+	m_mp_alloc_init_multi(&key->e, &key->n, &key->d, &key->p, &key->q, NULL);
+	m_mp_init_multi(&pminus, &lcm, &qminus, NULL);
 
 	if (mp_set_int(key->e, RSA_E) != MP_OKAY) {
 		fprintf(stderr, "RSA generation failed\n");
diff --git a/rsa.c b/rsa.c
index 6fd30b87a7415f0d02af1f491680f7cd851325ad..92adee4b434f17cb2521fd007b24fded2558ab32 100644
--- a/rsa.c
+++ b/rsa.c
@@ -50,9 +50,7 @@ int buf_get_rsa_pub_key(buffer* buf, dropbear_rsa_key *key) {
     int ret = DROPBEAR_FAILURE;
 	TRACE(("enter buf_get_rsa_pub_key"))
 	dropbear_assert(key != NULL);
-	key->e = m_malloc(sizeof(mp_int));
-	key->n = m_malloc(sizeof(mp_int));
-	m_mp_init_multi(key->e, key->n, NULL);
+	m_mp_alloc_init_multi(&key->e, &key->n, NULL);
 	key->d = NULL;
 	key->p = NULL;
 	key->q = NULL;
@@ -98,8 +96,7 @@ int buf_get_rsa_priv_key(buffer* buf, dropbear_rsa_key *key) {
 	key->p = NULL;
 	key->q = NULL;
 
-	key->d = m_malloc(sizeof(mp_int));
-	m_mp_init(key->d);
+	m_mp_alloc_init_multi(&key->d);
 	if (buf_getmpint(buf, key->d) == DROPBEAR_FAILURE) {
 		TRACE(("leave buf_get_rsa_priv_key: d: ret == DROPBEAR_FAILURE"))
 	    goto out;
@@ -108,9 +105,7 @@ int buf_get_rsa_priv_key(buffer* buf, dropbear_rsa_key *key) {
 	if (buf->pos == buf->len) {
     	/* old Dropbear private keys didn't keep p and q, so we will ignore them*/
 	} else {
-		key->p = m_malloc(sizeof(mp_int));
-		key->q = m_malloc(sizeof(mp_int));
-		m_mp_init_multi(key->p, key->q, NULL);
+		m_mp_alloc_init_multi(&key->p, &key->q, NULL);
 
 		if (buf_getmpint(buf, key->p) == DROPBEAR_FAILURE) {
 			TRACE(("leave buf_get_rsa_priv_key: p: ret == DROPBEAR_FAILURE"))