aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2011-06-28 16:49:25 +0200
committerMartin Willi <martin@revosec.ch>2011-10-14 10:05:45 +0200
commitd6c7b30cad4a9b25a29eac3e712ed0df031b9e28 (patch)
treed596c2ef0b17ad30b721e3e779e8c55b28c4ee32 /src/libstrongswan
parent3bc79461cdc3e1a67fdf20dcfd272ec4974f6e14 (diff)
downloadstrongswan-d6c7b30cad4a9b25a29eac3e712ed0df031b9e28.tar.bz2
strongswan-d6c7b30cad4a9b25a29eac3e712ed0df031b9e28.tar.xz
Add features support to af_alg plugin
Diffstat (limited to 'src/libstrongswan')
-rw-r--r--src/libstrongswan/plugins/af_alg/af_alg_crypter.c19
-rw-r--r--src/libstrongswan/plugins/af_alg/af_alg_crypter.h11
-rw-r--r--src/libstrongswan/plugins/af_alg/af_alg_hasher.c7
-rw-r--r--src/libstrongswan/plugins/af_alg/af_alg_hasher.h11
-rw-r--r--src/libstrongswan/plugins/af_alg/af_alg_plugin.c38
-rw-r--r--src/libstrongswan/plugins/af_alg/af_alg_prf.c7
-rw-r--r--src/libstrongswan/plugins/af_alg/af_alg_prf.h11
-rw-r--r--src/libstrongswan/plugins/af_alg/af_alg_signer.c7
-rw-r--r--src/libstrongswan/plugins/af_alg/af_alg_signer.h11
9 files changed, 71 insertions, 51 deletions
diff --git a/src/libstrongswan/plugins/af_alg/af_alg_crypter.c b/src/libstrongswan/plugins/af_alg/af_alg_crypter.c
index 7b3c062aa..9c547140d 100644
--- a/src/libstrongswan/plugins/af_alg/af_alg_crypter.c
+++ b/src/libstrongswan/plugins/af_alg/af_alg_crypter.c
@@ -61,7 +61,7 @@ static struct {
/* size of the keying material (key + nonce for ctr mode) */
size_t keymat_size;
size_t iv_size;
-} algs[] = {
+} algs[AF_ALG_CRYPTER] = {
{ENCR_DES, "cbc(des)", 8, 8, 8, 8, },
{ENCR_DES_ECB, "ecb(des)", 8, 8, 8, 0, },
{ENCR_3DES, "cbc(des3_ede)", 8, 24, 24, 8, },
@@ -92,25 +92,20 @@ static struct {
/**
* See header.
*/
-void af_alg_crypter_probe(char *plugin)
+void af_alg_crypter_probe(plugin_feature_t *features, int *pos)
{
- encryption_algorithm_t prev = -1;
af_alg_ops_t *ops;
int i;
for (i = 0; i < countof(algs); i++)
{
- if (prev != algs[i].id)
+ ops = af_alg_ops_create("skcipher", algs[i].name);
+ if (ops)
{
- ops = af_alg_ops_create("skcipher", algs[i].name);
- if (ops)
- {
- ops->destroy(ops);
- lib->crypto->add_crypter(lib->crypto, algs[i].id, plugin,
- (crypter_constructor_t)af_alg_crypter_create);
- }
+ ops->destroy(ops);
+ features[(*pos)++] = PLUGIN_PROVIDE(CRYPTER,
+ algs[i].id, algs[i].key_size);
}
- prev = algs[i].id;
}
}
diff --git a/src/libstrongswan/plugins/af_alg/af_alg_crypter.h b/src/libstrongswan/plugins/af_alg/af_alg_crypter.h
index ed7799cc8..ad2d42a97 100644
--- a/src/libstrongswan/plugins/af_alg/af_alg_crypter.h
+++ b/src/libstrongswan/plugins/af_alg/af_alg_crypter.h
@@ -23,8 +23,12 @@
typedef struct af_alg_crypter_t af_alg_crypter_t;
+#include <plugins/plugin.h>
#include <crypto/crypters/crypter.h>
+/** Number of crypters */
+#define AF_ALG_CRYPTER 25
+
/**
* Implementation of signers using AF_ALG.
*/
@@ -47,10 +51,11 @@ af_alg_crypter_t *af_alg_crypter_create(encryption_algorithm_t algo,
size_t key_size);
/**
- * Probe algorithms and register af_alg_crypter_create().
+ * Probe algorithms and return plugin features.
*
- * @param plugin plugin name to register algorithms for
+ * @param features plugin features to create
+ * @param pos current position in features
*/
-void af_alg_crypter_probe(char *plugin);
+void af_alg_crypter_probe(plugin_feature_t *features, int *pos);
#endif /** AF_ALG_CRYPTER_H_ @}*/
diff --git a/src/libstrongswan/plugins/af_alg/af_alg_hasher.c b/src/libstrongswan/plugins/af_alg/af_alg_hasher.c
index 11074c4bd..ef2350497 100644
--- a/src/libstrongswan/plugins/af_alg/af_alg_hasher.c
+++ b/src/libstrongswan/plugins/af_alg/af_alg_hasher.c
@@ -46,7 +46,7 @@ static struct {
hash_algorithm_t id;
char *name;
size_t size;
-} algs[] = {
+} algs[AF_ALG_HASHER] = {
{HASH_SHA1, "sha1", HASH_SIZE_SHA1 },
{HASH_MD5, "md5", HASH_SIZE_MD5 },
{HASH_SHA224, "sha224", HASH_SIZE_SHA224 },
@@ -59,7 +59,7 @@ static struct {
/**
* See header.
*/
-void af_alg_hasher_probe(char *plugin)
+void af_alg_hasher_probe(plugin_feature_t *features, int *pos)
{
af_alg_ops_t *ops;
int i;
@@ -70,8 +70,7 @@ void af_alg_hasher_probe(char *plugin)
if (ops)
{
ops->destroy(ops);
- lib->crypto->add_hasher(lib->crypto, algs[i].id, plugin,
- (hasher_constructor_t)af_alg_hasher_create);
+ features[(*pos)++] = PLUGIN_PROVIDE(HASHER, algs[i].id);
}
}
}
diff --git a/src/libstrongswan/plugins/af_alg/af_alg_hasher.h b/src/libstrongswan/plugins/af_alg/af_alg_hasher.h
index f44ba2938..5b540875a 100644
--- a/src/libstrongswan/plugins/af_alg/af_alg_hasher.h
+++ b/src/libstrongswan/plugins/af_alg/af_alg_hasher.h
@@ -23,8 +23,12 @@
typedef struct af_alg_hasher_t af_alg_hasher_t;
+#include <plugins/plugin.h>
#include <crypto/hashers/hasher.h>
+/** Number of hashers */
+#define AF_ALG_HASHER 7
+
/**
* Implementation of hashers using AF_ALG.
*/
@@ -45,10 +49,11 @@ struct af_alg_hasher_t {
af_alg_hasher_t *af_alg_hasher_create(hash_algorithm_t algo);
/**
- * Probe algorithms and register af_alg_hasher_create().
+ * Probe algorithms and return plugin features.
*
- * @param plugin plugin name to register algorithms for
+ * @param features plugin features to create
+ * @param pos current position in deps
*/
-void af_alg_hasher_probe(char *plugin);
+void af_alg_hasher_probe(plugin_feature_t *features, int *pos);
#endif /** af_alg_HASHER_H_ @}*/
diff --git a/src/libstrongswan/plugins/af_alg/af_alg_plugin.c b/src/libstrongswan/plugins/af_alg/af_alg_plugin.c
index 280ea4e98..445667507 100644
--- a/src/libstrongswan/plugins/af_alg/af_alg_plugin.c
+++ b/src/libstrongswan/plugins/af_alg/af_alg_plugin.c
@@ -41,18 +41,31 @@ METHOD(plugin_t, get_name, char*,
return "af-alg";
}
+METHOD(plugin_t, get_features, int,
+ private_af_alg_plugin_t *this, plugin_feature_t *features[])
+{
+ static plugin_feature_t f[AF_ALG_HASHER + AF_ALG_SIGNER +
+ AF_ALG_PRF + AF_ALG_CRYPTER + 4] = {};
+ static int count = 0;
+
+ if (!count)
+ { /* initialize only once */
+ f[count++] = PLUGIN_REGISTER(HASHER, af_alg_hasher_create);
+ af_alg_hasher_probe(f, &count);
+ f[count++] = PLUGIN_REGISTER(SIGNER, af_alg_signer_create);
+ af_alg_signer_probe(f, &count);
+ f[count++] = PLUGIN_REGISTER(PRF, af_alg_prf_create);
+ af_alg_prf_probe(f, &count);
+ f[count++] = PLUGIN_REGISTER(CRYPTER, af_alg_crypter_create);
+ af_alg_crypter_probe(f, &count);
+ }
+ *features = f;
+ return count;
+}
+
METHOD(plugin_t, destroy, void,
private_af_alg_plugin_t *this)
{
- lib->crypto->remove_hasher(lib->crypto,
- (hasher_constructor_t)af_alg_hasher_create);
- lib->crypto->remove_signer(lib->crypto,
- (signer_constructor_t)af_alg_signer_create);
- lib->crypto->remove_prf(lib->crypto,
- (prf_constructor_t)af_alg_prf_create);
- lib->crypto->remove_crypter(lib->crypto,
- (crypter_constructor_t)af_alg_crypter_create);
-
free(this);
}
@@ -67,16 +80,11 @@ plugin_t *af_alg_plugin_create()
.public = {
.plugin = {
.get_name = _get_name,
- .reload = (void*)return_false,
+ .get_features = _get_features,
.destroy = _destroy,
},
},
);
- af_alg_hasher_probe(get_name(this));
- af_alg_signer_probe(get_name(this));
- af_alg_prf_probe(get_name(this));
- af_alg_crypter_probe(get_name(this));
-
return &this->public.plugin;
}
diff --git a/src/libstrongswan/plugins/af_alg/af_alg_prf.c b/src/libstrongswan/plugins/af_alg/af_alg_prf.c
index 673ca5e7a..a7912291f 100644
--- a/src/libstrongswan/plugins/af_alg/af_alg_prf.c
+++ b/src/libstrongswan/plugins/af_alg/af_alg_prf.c
@@ -57,7 +57,7 @@ static struct {
char *name;
size_t block_size;
bool xcbc;
-} algs[] = {
+} algs[AF_ALG_PRF] = {
{PRF_HMAC_SHA1, "hmac(sha1)", 20, FALSE, },
{PRF_HMAC_SHA2_256, "hmac(sha256)", 32, FALSE, },
{PRF_HMAC_MD5, "hmac(md5)", 16, FALSE, },
@@ -70,7 +70,7 @@ static struct {
/**
* See header.
*/
-void af_alg_prf_probe(char *plugin)
+void af_alg_prf_probe(plugin_feature_t *features, int *pos)
{
af_alg_ops_t *ops;
int i;
@@ -81,8 +81,7 @@ void af_alg_prf_probe(char *plugin)
if (ops)
{
ops->destroy(ops);
- lib->crypto->add_prf(lib->crypto, algs[i].id, plugin,
- (prf_constructor_t)af_alg_prf_create);
+ features[(*pos)++] = PLUGIN_PROVIDE(PRF, algs[i].id);
}
}
}
diff --git a/src/libstrongswan/plugins/af_alg/af_alg_prf.h b/src/libstrongswan/plugins/af_alg/af_alg_prf.h
index d3275e7be..2f6cf0cf1 100644
--- a/src/libstrongswan/plugins/af_alg/af_alg_prf.h
+++ b/src/libstrongswan/plugins/af_alg/af_alg_prf.h
@@ -23,8 +23,12 @@
typedef struct af_alg_prf_t af_alg_prf_t;
+#include <plugins/plugin.h>
#include <crypto/prfs/prf.h>
+/** Number of PRFs */
+#define AF_ALG_PRF 7
+
/**
* Implementation of PRFs using AF_ALG.
*/
@@ -45,10 +49,11 @@ struct af_alg_prf_t {
af_alg_prf_t *af_alg_prf_create(pseudo_random_function_t algo);
/**
- * Probe algorithms and register af_alg_prf_create().
+ * Probe algorithms and return plugin features.
*
- * @param plugin plugin name to register algorithms for
+ * @param features plugin features to create
+ * @param pos current position in features
*/
-void af_alg_prf_probe(char *plugin);
+void af_alg_prf_probe(plugin_feature_t *features, int *pos);
#endif /** AF_ALG_PRF_H_ @}*/
diff --git a/src/libstrongswan/plugins/af_alg/af_alg_signer.c b/src/libstrongswan/plugins/af_alg/af_alg_signer.c
index 34534a06b..6cd79f8f2 100644
--- a/src/libstrongswan/plugins/af_alg/af_alg_signer.c
+++ b/src/libstrongswan/plugins/af_alg/af_alg_signer.c
@@ -52,7 +52,7 @@ static struct {
char *name;
size_t block_size;
size_t key_size;
-} algs[] = {
+} algs[AF_ALG_SIGNER] = {
{AUTH_HMAC_SHA1_96, "hmac(sha1)", 12, 20, },
{AUTH_HMAC_SHA1_128, "hmac(sha1)", 16, 20, },
{AUTH_HMAC_SHA1_160, "hmac(sha1)", 20, 20, },
@@ -71,7 +71,7 @@ static struct {
/**
* See header.
*/
-void af_alg_signer_probe(char *plugin)
+void af_alg_signer_probe(plugin_feature_t *features, int *pos)
{
af_alg_ops_t *ops;
int i;
@@ -82,8 +82,7 @@ void af_alg_signer_probe(char *plugin)
if (ops)
{
ops->destroy(ops);
- lib->crypto->add_signer(lib->crypto, algs[i].id, plugin,
- (signer_constructor_t)af_alg_signer_create);
+ features[(*pos)++] = PLUGIN_PROVIDE(SIGNER, algs[i].id);
}
}
}
diff --git a/src/libstrongswan/plugins/af_alg/af_alg_signer.h b/src/libstrongswan/plugins/af_alg/af_alg_signer.h
index 21487a118..deced7110 100644
--- a/src/libstrongswan/plugins/af_alg/af_alg_signer.h
+++ b/src/libstrongswan/plugins/af_alg/af_alg_signer.h
@@ -23,8 +23,12 @@
typedef struct af_alg_signer_t af_alg_signer_t;
+#include <plugins/plugin.h>
#include <crypto/signers/signer.h>
+/** Number of signers */
+#define AF_ALG_SIGNER 13
+
/**
* Implementation of signers using AF_ALG.
*/
@@ -45,10 +49,11 @@ struct af_alg_signer_t {
af_alg_signer_t *af_alg_signer_create(integrity_algorithm_t algo);
/**
- * Probe algorithms and register af_alg_signer_create().
+ * Probe algorithms and return plugin features.
*
- * @param plugin plugin name to register algorithms for
+ * @param features plugin features to create
+ * @param pos current position in features
*/
-void af_alg_signer_probe(char *plugin);
+void af_alg_signer_probe(plugin_feature_t *features, int *pos);
#endif /** AF_ALG_SIGNER_H_ @}*/