Add features support to gmp plugin
authorMartin Willi <martin@revosec.ch>
Wed, 29 Jun 2011 12:51:44 +0000 (14:51 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 14 Oct 2011 08:05:45 +0000 (10:05 +0200)
src/libstrongswan/plugins/gmp/gmp_plugin.c

index 55ccd4a..d93aa14 100644 (file)
@@ -39,19 +39,85 @@ METHOD(plugin_t, get_name, char*,
        return "gmp";
 }
 
+METHOD(plugin_t, get_features, int,
+       private_gmp_plugin_t *this, plugin_feature_t *features[])
+{
+       static plugin_feature_t f[] = {
+               /* DH groups */
+               PLUGIN_REGISTER(DH, gmp_diffie_hellman_create),
+                       PLUGIN_PROVIDE(DH, MODP_2048_BIT),
+                               PLUGIN_DEPENDS(RNG, RNG_STRONG),
+                       PLUGIN_PROVIDE(DH, MODP_2048_224),
+                               PLUGIN_DEPENDS(RNG, RNG_STRONG),
+                       PLUGIN_PROVIDE(DH, MODP_2048_256),
+                               PLUGIN_DEPENDS(RNG, RNG_STRONG),
+                       PLUGIN_PROVIDE(DH, MODP_1536_BIT),
+                               PLUGIN_DEPENDS(RNG, RNG_STRONG),
+                       PLUGIN_PROVIDE(DH, MODP_3072_BIT),
+                               PLUGIN_DEPENDS(RNG, RNG_STRONG),
+                       PLUGIN_PROVIDE(DH, MODP_4096_BIT),
+                               PLUGIN_DEPENDS(RNG, RNG_STRONG),
+                       PLUGIN_PROVIDE(DH, MODP_6144_BIT),
+                               PLUGIN_DEPENDS(RNG, RNG_STRONG),
+                       PLUGIN_PROVIDE(DH, MODP_8192_BIT),
+                               PLUGIN_DEPENDS(RNG, RNG_STRONG),
+                       PLUGIN_PROVIDE(DH, MODP_1024_BIT),
+                               PLUGIN_DEPENDS(RNG, RNG_STRONG),
+                       PLUGIN_PROVIDE(DH, MODP_1024_160),
+                               PLUGIN_DEPENDS(RNG, RNG_STRONG),
+                       PLUGIN_PROVIDE(DH, MODP_768_BIT),
+                               PLUGIN_DEPENDS(RNG, RNG_STRONG),
+               PLUGIN_REGISTER(DH, gmp_diffie_hellman_create_custom),
+                       PLUGIN_PROVIDE(DH, MODP_CUSTOM),
+                               PLUGIN_DEPENDS(RNG, RNG_STRONG),
+                       /* private/public keys */
+               PLUGIN_REGISTER(PRIVKEY, gmp_rsa_private_key_load, TRUE),
+                       PLUGIN_PROVIDE(PRIVKEY, KEY_RSA),
+               PLUGIN_REGISTER(PRIVKEY_GEN, gmp_rsa_private_key_gen, FALSE),
+                       PLUGIN_PROVIDE(PRIVKEY_GEN, KEY_RSA),
+                               PLUGIN_DEPENDS(RNG, RNG_TRUE),
+               PLUGIN_REGISTER(PUBKEY, gmp_rsa_public_key_load, TRUE),
+                       PLUGIN_PROVIDE(PUBKEY, KEY_RSA),
+               /* signature schemes, private */
+               PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_NULL),
+               PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_SHA1),
+                       PLUGIN_DEPENDS(HASHER, HASH_SHA1),
+               PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_SHA224),
+                       PLUGIN_DEPENDS(HASHER, HASH_SHA224),
+               PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_SHA256),
+                       PLUGIN_DEPENDS(HASHER, HASH_SHA256),
+               PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_SHA384),
+                       PLUGIN_DEPENDS(HASHER, HASH_SHA384),
+               PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_SHA512),
+                       PLUGIN_DEPENDS(HASHER, HASH_SHA512),
+               PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_MD5),
+                       PLUGIN_DEPENDS(HASHER, HASH_MD5),
+               /* signature verification schemes */
+               PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_NULL),
+               PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_SHA1),
+                       PLUGIN_DEPENDS(HASHER, HASH_SHA1),
+               PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_SHA224),
+                       PLUGIN_DEPENDS(HASHER, HASH_SHA224),
+               PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_SHA256),
+                       PLUGIN_DEPENDS(HASHER, HASH_SHA256),
+               PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_SHA384),
+                       PLUGIN_DEPENDS(HASHER, HASH_SHA384),
+               PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_SHA512),
+                       PLUGIN_DEPENDS(HASHER, HASH_SHA512),
+               PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_MD5),
+                       PLUGIN_DEPENDS(HASHER, HASH_MD5),
+               /* en-/decryption schemes */
+               PLUGIN_PROVIDE(PRIVKEY_DECRYPT, ENCRYPT_RSA_PKCS1),
+               PLUGIN_PROVIDE(PUBKEY_ENCRYPT, ENCRYPT_RSA_PKCS1),
+                       PLUGIN_DEPENDS(RNG, RNG_WEAK),
+       };
+       *features = f;
+       return countof(f);
+}
+
 METHOD(plugin_t, destroy, void,
        private_gmp_plugin_t *this)
 {
-       lib->crypto->remove_dh(lib->crypto,
-                                               (dh_constructor_t)gmp_diffie_hellman_create);
-       lib->crypto->remove_dh(lib->crypto,
-                                               (dh_constructor_t)gmp_diffie_hellman_create_custom);
-       lib->creds->remove_builder(lib->creds,
-                                               (builder_function_t)gmp_rsa_private_key_gen);
-       lib->creds->remove_builder(lib->creds,
-                                               (builder_function_t)gmp_rsa_private_key_load);
-       lib->creds->remove_builder(lib->creds,
-                                               (builder_function_t)gmp_rsa_public_key_load);
        free(this);
 }
 
@@ -66,45 +132,12 @@ plugin_t *gmp_plugin_create()
                .public = {
                        .plugin = {
                                .get_name = _get_name,
-                               .reload = (void*)return_false,
+                               .get_features = _get_features,
                                .destroy = _destroy,
                        },
                },
        );
 
-       lib->crypto->add_dh(lib->crypto, MODP_2048_BIT, get_name(this),
-                                               (dh_constructor_t)gmp_diffie_hellman_create);
-       lib->crypto->add_dh(lib->crypto, MODP_2048_224, get_name(this),
-                                               (dh_constructor_t)gmp_diffie_hellman_create);
-       lib->crypto->add_dh(lib->crypto, MODP_2048_256, get_name(this),
-                                               (dh_constructor_t)gmp_diffie_hellman_create);
-       lib->crypto->add_dh(lib->crypto, MODP_1536_BIT, get_name(this),
-                                               (dh_constructor_t)gmp_diffie_hellman_create);
-       lib->crypto->add_dh(lib->crypto, MODP_3072_BIT, get_name(this),
-                                               (dh_constructor_t)gmp_diffie_hellman_create);
-       lib->crypto->add_dh(lib->crypto, MODP_4096_BIT, get_name(this),
-                                               (dh_constructor_t)gmp_diffie_hellman_create);
-       lib->crypto->add_dh(lib->crypto, MODP_6144_BIT, get_name(this),
-                                               (dh_constructor_t)gmp_diffie_hellman_create);
-       lib->crypto->add_dh(lib->crypto, MODP_8192_BIT, get_name(this),
-                                               (dh_constructor_t)gmp_diffie_hellman_create);
-       lib->crypto->add_dh(lib->crypto, MODP_1024_BIT, get_name(this),
-                                               (dh_constructor_t)gmp_diffie_hellman_create);
-       lib->crypto->add_dh(lib->crypto, MODP_1024_160, get_name(this),
-                                               (dh_constructor_t)gmp_diffie_hellman_create);
-       lib->crypto->add_dh(lib->crypto, MODP_768_BIT, get_name(this),
-                                               (dh_constructor_t)gmp_diffie_hellman_create);
-
-       lib->crypto->add_dh(lib->crypto, MODP_CUSTOM, get_name(this),
-                                               (dh_constructor_t)gmp_diffie_hellman_create_custom);
-
-       lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA, FALSE,
-                                               (builder_function_t)gmp_rsa_private_key_gen);
-       lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA, TRUE,
-                                               (builder_function_t)gmp_rsa_private_key_load);
-       lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_RSA, TRUE,
-                                               (builder_function_t)gmp_rsa_public_key_load);
-
        return &this->public.plugin;
 }