]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Register algorithms with dependencies only if dependency available
authorMartin Willi <martin@revosec.ch>
Mon, 8 Nov 2010 13:20:15 +0000 (14:20 +0100)
committerMartin Willi <martin@revosec.ch>
Mon, 20 Dec 2010 09:00:39 +0000 (10:00 +0100)
src/libstrongswan/plugins/ccm/ccm_plugin.c
src/libstrongswan/plugins/ctr/ctr_plugin.c
src/libstrongswan/plugins/fips_prf/fips_prf_plugin.c
src/libstrongswan/plugins/gcm/gcm_plugin.c
src/libstrongswan/plugins/hmac/hmac_plugin.c
src/libstrongswan/plugins/xcbc/xcbc_plugin.c

index 0b628ceaea3f753e6c84ea549db3d61bc455f718..a4c89b5484c53b17f9907509bdb1f7751e5d5920 100644 (file)
@@ -49,23 +49,34 @@ METHOD(plugin_t, destroy, void,
 plugin_t *ccm_plugin_create()
 {
        private_ccm_plugin_t *this;
+       crypter_t *crypter;
 
        INIT(this,
                .public.plugin.destroy = _destroy,
        );
 
-       lib->crypto->add_aead(lib->crypto, ENCR_AES_CCM_ICV8, plugin_name,
-                                       (aead_constructor_t)ccm_aead_create);
-       lib->crypto->add_aead(lib->crypto, ENCR_AES_CCM_ICV12, plugin_name,
-                                       (aead_constructor_t)ccm_aead_create);
-       lib->crypto->add_aead(lib->crypto, ENCR_AES_CCM_ICV16, plugin_name,
-                                       (aead_constructor_t)ccm_aead_create);
-       lib->crypto->add_aead(lib->crypto, ENCR_CAMELLIA_CCM_ICV8, plugin_name,
-                                       (aead_constructor_t)ccm_aead_create);
-       lib->crypto->add_aead(lib->crypto, ENCR_CAMELLIA_CCM_ICV12, plugin_name,
-                                       (aead_constructor_t)ccm_aead_create);
-       lib->crypto->add_aead(lib->crypto, ENCR_CAMELLIA_CCM_ICV16, plugin_name,
-                                       (aead_constructor_t)ccm_aead_create);
+       crypter = lib->crypto->create_crypter(lib->crypto, ENCR_AES_CBC, 0);
+       if (crypter)
+       {
+               crypter->destroy(crypter);
+               lib->crypto->add_aead(lib->crypto, ENCR_AES_CCM_ICV8, plugin_name,
+                                               (aead_constructor_t)ccm_aead_create);
+               lib->crypto->add_aead(lib->crypto, ENCR_AES_CCM_ICV12, plugin_name,
+                                               (aead_constructor_t)ccm_aead_create);
+               lib->crypto->add_aead(lib->crypto, ENCR_AES_CCM_ICV16, plugin_name,
+                                               (aead_constructor_t)ccm_aead_create);
+       }
+       crypter = lib->crypto->create_crypter(lib->crypto, ENCR_CAMELLIA_CBC, 0);
+       if (crypter)
+       {
+               crypter->destroy(crypter);
+               lib->crypto->add_aead(lib->crypto, ENCR_CAMELLIA_CCM_ICV8, plugin_name,
+                                               (aead_constructor_t)ccm_aead_create);
+               lib->crypto->add_aead(lib->crypto, ENCR_CAMELLIA_CCM_ICV12, plugin_name,
+                                               (aead_constructor_t)ccm_aead_create);
+               lib->crypto->add_aead(lib->crypto, ENCR_CAMELLIA_CCM_ICV16, plugin_name,
+                                               (aead_constructor_t)ccm_aead_create);
+       }
 
        return &this->public.plugin;
 }
index e8dadaffe1817c4859468483704049cb85530340..9f1bf957f0bb827b9079e87e3a4873503c2b138c 100644 (file)
@@ -49,6 +49,7 @@ METHOD(plugin_t, destroy, void,
 plugin_t *ctr_plugin_create()
 {
        private_ctr_plugin_t *this;
+       crypter_t *crypter;
 
        INIT(this,
                .public = {
@@ -58,10 +59,19 @@ plugin_t *ctr_plugin_create()
                },
        );
 
-       lib->crypto->add_crypter(lib->crypto, ENCR_AES_CTR, plugin_name,
-                                       (crypter_constructor_t)ctr_ipsec_crypter_create);
-       lib->crypto->add_crypter(lib->crypto, ENCR_CAMELLIA_CTR, plugin_name,
-                                       (crypter_constructor_t)ctr_ipsec_crypter_create);
-
+       crypter = lib->crypto->create_crypter(lib->crypto, ENCR_AES_CBC, 16);
+       if (crypter)
+       {
+               crypter->destroy(crypter);
+               lib->crypto->add_crypter(lib->crypto, ENCR_AES_CTR, plugin_name,
+                                               (crypter_constructor_t)ctr_ipsec_crypter_create);
+       }
+       crypter = lib->crypto->create_crypter(lib->crypto, ENCR_CAMELLIA_CBC, 16);
+       if (crypter)
+       {
+               crypter->destroy(crypter);
+               lib->crypto->add_crypter(lib->crypto, ENCR_CAMELLIA_CTR, plugin_name,
+                                               (crypter_constructor_t)ctr_ipsec_crypter_create);
+       }
        return &this->public.plugin;
 }
index 7f9e135f436fc8a7f11e310d44d407b898305d8a..c67f81089be9e789a520129d3b86d4da75222c26 100644 (file)
@@ -47,6 +47,7 @@ METHOD(plugin_t, destroy, void,
 plugin_t *fips_prf_plugin_create()
 {
        private_fips_prf_plugin_t *this;
+       prf_t *prf;
 
        INIT(this,
                .public = {
@@ -56,8 +57,13 @@ plugin_t *fips_prf_plugin_create()
                },
        );
 
-       lib->crypto->add_prf(lib->crypto, PRF_FIPS_SHA1_160, plugin_name,
-                                                (prf_constructor_t)fips_prf_create);
+       prf = lib->crypto->create_prf(lib->crypto, PRF_KEYED_SHA1);
+       if (prf)
+       {
+               prf->destroy(prf);
+               lib->crypto->add_prf(lib->crypto, PRF_FIPS_SHA1_160, plugin_name,
+                                                        (prf_constructor_t)fips_prf_create);
+       }
 
        return &this->public.plugin;
 }
index 43ff3e7cc23aadad1554f9f455e73b0e19dcafd0..a438fb0730f6d84d3edcf80dce0ca9f117791f71 100644 (file)
@@ -49,17 +49,23 @@ METHOD(plugin_t, destroy, void,
 plugin_t *gcm_plugin_create()
 {
        private_gcm_plugin_t *this;
+       crypter_t *crypter;
 
        INIT(this,
                .public.plugin.destroy = _destroy,
        );
 
-       lib->crypto->add_aead(lib->crypto, ENCR_AES_GCM_ICV8, plugin_name,
-                                       (aead_constructor_t)gcm_aead_create);
-       lib->crypto->add_aead(lib->crypto, ENCR_AES_GCM_ICV12, plugin_name,
-                                       (aead_constructor_t)gcm_aead_create);
-       lib->crypto->add_aead(lib->crypto, ENCR_AES_GCM_ICV16, plugin_name,
-                                       (aead_constructor_t)gcm_aead_create);
+       crypter = lib->crypto->create_crypter(lib->crypto, ENCR_AES_CBC, 0);
+       if (crypter)
+       {
+               crypter->destroy(crypter);
+               lib->crypto->add_aead(lib->crypto, ENCR_AES_GCM_ICV8, plugin_name,
+                                               (aead_constructor_t)gcm_aead_create);
+               lib->crypto->add_aead(lib->crypto, ENCR_AES_GCM_ICV12, plugin_name,
+                                               (aead_constructor_t)gcm_aead_create);
+               lib->crypto->add_aead(lib->crypto, ENCR_AES_GCM_ICV16, plugin_name,
+                                               (aead_constructor_t)gcm_aead_create);
+       }
 
        return &this->public.plugin;
 }
index 82451d1d3a2d7896445c17ffe4e41e65ed6b3570..76d6157ae160f93ce1ae3ea5e1228dc6d29b4abb 100644 (file)
@@ -50,6 +50,7 @@ METHOD(plugin_t, destroy, void,
 plugin_t *hmac_plugin_create()
 {
        private_hmac_plugin_t *this;
+       hasher_t *hasher;
 
        INIT(this,
                .public = {
@@ -59,37 +60,62 @@ plugin_t *hmac_plugin_create()
                },
        );
 
-       lib->crypto->add_prf(lib->crypto, PRF_HMAC_SHA2_256, plugin_name,
-                                                (prf_constructor_t)hmac_prf_create);
-       lib->crypto->add_prf(lib->crypto, PRF_HMAC_SHA1, plugin_name,
-                                                (prf_constructor_t)hmac_prf_create);
-       lib->crypto->add_prf(lib->crypto, PRF_HMAC_MD5, plugin_name,
-                                                (prf_constructor_t)hmac_prf_create);
-       lib->crypto->add_prf(lib->crypto, PRF_HMAC_SHA2_384, plugin_name,
-                                                (prf_constructor_t)hmac_prf_create);
-       lib->crypto->add_prf(lib->crypto, PRF_HMAC_SHA2_512, plugin_name,
-                                                (prf_constructor_t)hmac_prf_create);
+       hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1);
+       if (hasher)
+       {
+               hasher->destroy(hasher);
+               lib->crypto->add_prf(lib->crypto, PRF_HMAC_SHA1, plugin_name,
+                                               (prf_constructor_t)hmac_prf_create);
+               lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA1_96, plugin_name,
+                                               (signer_constructor_t)hmac_signer_create);
+               lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA1_128, plugin_name,
+                                               (signer_constructor_t)hmac_signer_create);
+               lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA1_160, plugin_name,
+                                               (signer_constructor_t)hmac_signer_create);
+       }
+       hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA256);
+       if (hasher)
+       {
+               hasher->destroy(hasher);
+               lib->crypto->add_prf(lib->crypto, PRF_HMAC_SHA2_256, plugin_name,
+                                               (prf_constructor_t)hmac_prf_create);
+               lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA2_256_128, plugin_name,
+                                               (signer_constructor_t)hmac_signer_create);
+               lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA2_256_256, plugin_name,
+                                               (signer_constructor_t)hmac_signer_create);
 
-       lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA1_96, plugin_name,
-                                                       (signer_constructor_t)hmac_signer_create);
-       lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA1_128, plugin_name,
-                                                       (signer_constructor_t)hmac_signer_create);
-       lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA1_160, plugin_name,
-                                                       (signer_constructor_t)hmac_signer_create);
-       lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA2_256_128, plugin_name,
-                                                       (signer_constructor_t)hmac_signer_create);
-       lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA2_256_256, plugin_name,
-                                                       (signer_constructor_t)hmac_signer_create);
-       lib->crypto->add_signer(lib->crypto, AUTH_HMAC_MD5_96, plugin_name,
-                                                       (signer_constructor_t)hmac_signer_create);
-       lib->crypto->add_signer(lib->crypto, AUTH_HMAC_MD5_128, plugin_name,
-                                                       (signer_constructor_t)hmac_signer_create);
-       lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA2_384_192, plugin_name,
-                                                       (signer_constructor_t)hmac_signer_create);
-       lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA2_384_384, plugin_name,
-                                                       (signer_constructor_t)hmac_signer_create);
-       lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA2_512_256, plugin_name,
-                                                       (signer_constructor_t)hmac_signer_create);
+       }
+       hasher = lib->crypto->create_hasher(lib->crypto, HASH_MD5);
+       if (hasher)
+       {
+               hasher->destroy(hasher);
+               lib->crypto->add_prf(lib->crypto, PRF_HMAC_MD5, plugin_name,
+                                               (prf_constructor_t)hmac_prf_create);
+               lib->crypto->add_signer(lib->crypto, AUTH_HMAC_MD5_96, plugin_name,
+                                               (signer_constructor_t)hmac_signer_create);
+               lib->crypto->add_signer(lib->crypto, AUTH_HMAC_MD5_128, plugin_name,
+                                               (signer_constructor_t)hmac_signer_create);
+       }
+       hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA384);
+       if (hasher)
+       {
+               hasher->destroy(hasher);
+               lib->crypto->add_prf(lib->crypto, PRF_HMAC_SHA2_384, plugin_name,
+                                               (prf_constructor_t)hmac_prf_create);
+               lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA2_384_192, plugin_name,
+                                               (signer_constructor_t)hmac_signer_create);
+               lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA2_384_384, plugin_name,
+                                               (signer_constructor_t)hmac_signer_create);
+       }
+       hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA512);
+       if (hasher)
+       {
+               hasher->destroy(hasher);
+               lib->crypto->add_prf(lib->crypto, PRF_HMAC_SHA2_512, plugin_name,
+                                               (prf_constructor_t)hmac_prf_create);
+               lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA2_512_256, plugin_name,
+                                               (signer_constructor_t)hmac_signer_create);
+       }
 
        return &this->public.plugin;
 }
index 7f649cada6bbd794c015972ebe13dc084583d167..65e88335c31e3c6f18ba93180b316b267e353da7 100644 (file)
@@ -50,6 +50,7 @@ METHOD(plugin_t, destroy, void,
 plugin_t *xcbc_plugin_create()
 {
        private_xcbc_plugin_t *this;
+       crypter_t *crypter;
 
        INIT(this,
                .public = {
@@ -59,15 +60,24 @@ plugin_t *xcbc_plugin_create()
                },
        );
 
-       lib->crypto->add_prf(lib->crypto, PRF_AES128_XCBC, plugin_name,
-                                       (prf_constructor_t)xcbc_prf_create);
-       lib->crypto->add_prf(lib->crypto, PRF_CAMELLIA128_XCBC, plugin_name,
-                                       (prf_constructor_t)xcbc_prf_create);
-       lib->crypto->add_signer(lib->crypto, AUTH_AES_XCBC_96, plugin_name,
-                                       (signer_constructor_t)xcbc_signer_create);
-       lib->crypto->add_signer(lib->crypto, AUTH_CAMELLIA_XCBC_96, plugin_name,
-                                       (signer_constructor_t)xcbc_signer_create);
-
+       crypter = lib->crypto->create_crypter(lib->crypto, ENCR_AES_CBC, 16);
+       if (crypter)
+       {
+               crypter->destroy(crypter);
+               lib->crypto->add_prf(lib->crypto, PRF_AES128_XCBC, plugin_name,
+                                               (prf_constructor_t)xcbc_prf_create);
+               lib->crypto->add_signer(lib->crypto, AUTH_AES_XCBC_96, plugin_name,
+                                               (signer_constructor_t)xcbc_signer_create);
+       }
+       crypter = lib->crypto->create_crypter(lib->crypto, ENCR_CAMELLIA_CBC, 16);
+       if (crypter)
+       {
+               crypter->destroy(crypter);
+               lib->crypto->add_prf(lib->crypto, PRF_CAMELLIA128_XCBC, plugin_name,
+                                               (prf_constructor_t)xcbc_prf_create);
+               lib->crypto->add_signer(lib->crypto, AUTH_CAMELLIA_XCBC_96, plugin_name,
+                                               (signer_constructor_t)xcbc_signer_create);
+       }
        return &this->public.plugin;
 }