creating public key from RSA private key
authorMartin Willi <martin@strongswan.org>
Tue, 18 Mar 2008 12:13:51 +0000 (12:13 -0000)
committerMartin Willi <martin@strongswan.org>
Tue, 18 Mar 2008 12:13:51 +0000 (12:13 -0000)
RSA key generation and signature test

src/charon/plugins/unit_tester/Makefile.am
src/charon/plugins/unit_tester/tests.h
src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c
src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c

index fb52443..9d9f4d7 100644 (file)
@@ -12,6 +12,7 @@ libcharon_unit_tester_la_SOURCES = unit_tester.c unit_tester.h \
   tests/test_curl.c \
   tests/test_mysql.c \
   tests/test_sqlite.c \
-  tests/test_mutex.c
+  tests/test_mutex.c \
+  tests/test_rsa_gen.c
 libcharon_unit_tester_la_LDFLAGS = -module
 
index 5def0b0..311ae71 100644 (file)
@@ -29,5 +29,6 @@ DEFINE_TEST("FIPS PRF", fips_prf_test, FALSE)
 DEFINE_TEST("CURL get", test_curl_get, FALSE)
 DEFINE_TEST("MySQL operations", test_mysql, FALSE)
 DEFINE_TEST("SQLite operations", test_sqlite, FALSE)
-DEFINE_TEST("mutex primitive", test_mutex, TRUE)
+DEFINE_TEST("mutex primitive", test_mutex, FALSE)
+DEFINE_TEST("RSA key generation", test_rsa_gen, TRUE)
 
index 2315df5..c9928e6 100644 (file)
@@ -144,10 +144,11 @@ static const asn1Object_t privkey_objects[] = {
 #define PRIV_KEY_ROOF                  16
 
 /**
- * defined in rsa_public_key.c
+ * shared functions, implemented in gmp_rsa_public_key.c
  */
 bool gmp_rsa_public_key_build_id(mpz_t n, mpz_t e, identification_t **keyid,
                                                                 identification_t **keyid_info);
+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
@@ -381,8 +382,7 @@ static identification_t* get_id(private_gmp_rsa_private_key_t *this,
  */
 static gmp_rsa_public_key_t* get_public_key(private_gmp_rsa_private_key_t *this)
 {
-       DBG1("creating RSA public key from private key not implemented");
-       return NULL;
+       return gmp_rsa_public_key_create_from_n_e(this->n, this->e);
 }
 
 /**
index 13ced71..6109828 100644 (file)
@@ -455,6 +455,26 @@ 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) / 8;
+       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 an ASN1 encoded blob
  */
 static gmp_rsa_public_key_t *load(chunk_t blob)