Added a MODP_CUSTOM DH group which takes g and p as constructor arguments
authorMartin Willi <martin@revosec.ch>
Thu, 2 Sep 2010 17:06:34 +0000 (19:06 +0200)
committerMartin Willi <martin@revosec.ch>
Thu, 2 Sep 2010 17:33:08 +0000 (19:33 +0200)
src/libstrongswan/crypto/crypto_factory.c
src/libstrongswan/crypto/crypto_factory.h
src/libstrongswan/crypto/diffie_hellman.c
src/libstrongswan/crypto/diffie_hellman.h

index 60cd148..f2f0198 100644 (file)
@@ -308,7 +308,7 @@ METHOD(crypto_factory_t, create_rng, rng_t*,
 }
 
 METHOD(crypto_factory_t, create_dh, diffie_hellman_t*,
-       private_crypto_factory_t *this, diffie_hellman_group_t group)
+       private_crypto_factory_t *this, diffie_hellman_group_t group, ...)
 {
        enumerator_t *enumerator;
        entry_t *entry;
@@ -320,7 +320,21 @@ METHOD(crypto_factory_t, create_dh, diffie_hellman_t*,
        {
                if (entry->algo == group)
                {
-                       diffie_hellman = entry->create_dh(group);
+                       if (group == MODP_CUSTOM)
+                       {
+                               va_list args;
+                               chunk_t g, p;
+
+                               va_start(args, group);
+                               g = va_arg(args, chunk_t);
+                               p = va_arg(args, chunk_t);
+                               va_end(args);
+                               diffie_hellman = entry->create_dh(MODP_CUSTOM, g, p);
+                       }
+                       else
+                       {
+                               diffie_hellman = entry->create_dh(group);
+                       }
                        if (diffie_hellman)
                        {
                                break;
index 7fe43c7..ff06eda 100644 (file)
@@ -65,8 +65,11 @@ typedef rng_t* (*rng_constructor_t)(rng_quality_t quality);
 
 /**
  * Constructor function for diffie hellman
+ *
+ * The DH constructor accepts additional arguments for:
+ * - MODP_CUSTOM: chunk_t generator, chunk_t prime
  */
-typedef diffie_hellman_t* (*dh_constructor_t)(diffie_hellman_group_t group);
+typedef diffie_hellman_t* (*dh_constructor_t)(diffie_hellman_group_t group, ...);
 
 /**
  * Handles crypto modules and creates instances.
@@ -129,11 +132,13 @@ struct crypto_factory_t {
        /**
         * Create a diffie hellman instance.
         *
+        * Additional arguments are passed to the DH constructor.
+        *
         * @param group                 diffie hellman group
         * @return                              diffie_hellman_t instance, NULL if not supported
         */
        diffie_hellman_t* (*create_dh)(crypto_factory_t *this,
-                                                                  diffie_hellman_group_t group);
+                                                                  diffie_hellman_group_t group, ...);
 
        /**
         * Register a crypter constructor.
index 9bd8991..e367560 100644 (file)
@@ -38,9 +38,10 @@ ENUM_NEXT(diffie_hellman_group_names, MODP_1024_160, ECP_224_BIT, ECP_521_BIT,
        "MODP_2048_256",
        "ECP_192",
        "ECP_224");
-ENUM_NEXT(diffie_hellman_group_names, MODP_NULL, MODP_NULL, ECP_224_BIT,
-       "MODP_NULL");
-ENUM_END(diffie_hellman_group_names, MODP_NULL);
+ENUM_NEXT(diffie_hellman_group_names, MODP_NULL, MODP_CUSTOM, ECP_224_BIT,
+       "MODP_NULL",
+       "MODP_CUSTOM");
+ENUM_END(diffie_hellman_group_names, MODP_CUSTOM);
 
 
 /**
index cdc9c78..b9816df 100644 (file)
@@ -57,6 +57,8 @@ enum diffie_hellman_group_t {
        ECP_224_BIT   = 26,
        /** insecure NULL diffie hellman group for testing, in PRIVATE USE */
        MODP_NULL = 1024,
+       /** MODP group with custon generator, prime */
+       MODP_CUSTOM = 1025,
 };
 
 /**