aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c')
-rw-r--r--src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c64
1 files changed, 37 insertions, 27 deletions
diff --git a/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c b/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c
index 527c2e325..97322289b 100644
--- a/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c
+++ b/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c
@@ -115,7 +115,6 @@ struct private_gmp_rsa_private_key_t {
extern bool gmp_rsa_public_key_build_id(mpz_t n, mpz_t e,
identification_t **keyid,
identification_t **keyid_info);
-extern gmp_rsa_public_key_t *gmp_rsa_public_key_create_from_n_e(mpz_t n, mpz_t e);
/**
* Auxiliary function overwriting private key material with zero bytes
@@ -382,11 +381,46 @@ static identification_t* get_id(private_gmp_rsa_private_key_t *this,
}
/**
+ * Convert a MP integer into a chunk_t
+ */
+chunk_t gmp_mpz_to_chunk(const mpz_t value)
+{
+ chunk_t n;
+
+ n.len = 1 + mpz_sizeinbase(value, 2) / BITS_PER_BYTE;
+ n.ptr = mpz_export(NULL, NULL, 1, n.len, 1, 0, value);
+ if (n.ptr == NULL)
+ { /* if we have zero in "value", gmp returns NULL */
+ n.len = 0;
+ }
+ return n;
+}
+
+/**
+ * Convert a MP integer into a DER coded ASN.1 object
+ */
+chunk_t gmp_mpz_to_asn1(const mpz_t value)
+{
+ return asn1_wrap(ASN1_INTEGER, "m", gmp_mpz_to_chunk(value));
+}
+
+/**
* Implementation of gmp_rsa_private_key.get_public_key.
*/
-static gmp_rsa_public_key_t* get_public_key(private_gmp_rsa_private_key_t *this)
+static public_key_t* get_public_key(private_gmp_rsa_private_key_t *this)
{
- return gmp_rsa_public_key_create_from_n_e(this->n, this->e);
+ chunk_t n, e;
+ public_key_t *public;
+
+ n = gmp_mpz_to_chunk(this->n);
+ e = gmp_mpz_to_chunk(this->e);
+
+ public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
+ BUILD_RSA_MODULUS, n, BUILD_RSA_PUB_EXP, e, BUILD_END);
+ chunk_free(&n);
+ chunk_free(&e);
+
+ return public;
}
/**
@@ -442,30 +476,6 @@ static bool belongs_to(private_gmp_rsa_private_key_t *this, public_key_t *public
}
/**
- * Convert a MP integer into a chunk_t
- */
-chunk_t gmp_mpz_to_chunk(const mpz_t value)
-{
- chunk_t n;
-
- n.len = 1 + mpz_sizeinbase(value, 2) / BITS_PER_BYTE;
- n.ptr = mpz_export(NULL, NULL, 1, n.len, 1, 0, value);
- if (n.ptr == NULL)
- { /* if we have zero in "value", gmp returns NULL */
- n.len = 0;
- }
- return n;
-}
-
-/**
- * Convert a MP integer into a DER coded ASN.1 object
- */
-chunk_t gmp_mpz_to_asn1(const mpz_t value)
-{
- return asn1_wrap(ASN1_INTEGER, "m", gmp_mpz_to_chunk(value));
-}
-
-/**
* Implementation of private_key_t.get_encoding.
*/
static chunk_t get_encoding(private_gmp_rsa_private_key_t *this)