aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2009-08-18 09:58:12 +0200
committerMartin Willi <martin@strongswan.org>2009-08-26 11:23:51 +0200
commit831520d895f2bd1b5068ea76b01e16cff5caa87e (patch)
treeae986da9213d20cdec07defb8d9564e2be522751 /src
parent8380503168bbed036679883d488bd52eca688f18 (diff)
downloadstrongswan-831520d895f2bd1b5068ea76b01e16cff5caa87e.tar.bz2
strongswan-831520d895f2bd1b5068ea76b01e16cff5caa87e.tar.xz
gmp uses component builder to build public- from private-key
Diffstat (limited to 'src')
-rw-r--r--src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c64
-rw-r--r--src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c20
2 files changed, 37 insertions, 47 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)
diff --git a/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c b/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c
index a627135f6..96e168777 100644
--- a/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c
+++ b/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c
@@ -569,26 +569,6 @@ bool gmp_rsa_public_key_build_id(mpz_t n, mpz_t e, identification_t **keyid,
}
/**
- * Create a public key from mpz values, used in gmp_rsa_private_key
- */
-gmp_rsa_public_key_t *gmp_rsa_public_key_create_from_n_e(mpz_t n, mpz_t e)
-{
- private_gmp_rsa_public_key_t *this = gmp_rsa_public_key_create_empty();
-
- mpz_init_set(this->n, n);
- mpz_init_set(this->e, e);
-
- this->k = (mpz_sizeinbase(this->n, 2) + 7) / BITS_PER_BYTE;
- if (!gmp_rsa_public_key_build_id(this->n, this->e,
- &this->keyid, &this->keyid_info))
- {
- destroy(this);
- return NULL;
- }
- return &this->public;
-}
-
-/**
* Load a public key from n and e
*/
static gmp_rsa_public_key_t *load(chunk_t n, chunk_t e)