Add aead plugin features
authorMartin Willi <martin@revosec.ch>
Wed, 21 Sep 2011 09:17:56 +0000 (11:17 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 14 Oct 2011 08:05:46 +0000 (10:05 +0200)
src/libstrongswan/plugins/plugin_feature.c
src/libstrongswan/plugins/plugin_feature.h
src/libstrongswan/plugins/plugin_loader.c

index 682963b..29ca101 100644 (file)
@@ -21,6 +21,7 @@
 ENUM(plugin_feature_names, FEATURE_NONE, FEATURE_CUSTOM,
        "NONE",
        "CRYPTER",
+       "AEAD",
        "SIGNER",
        "HASHER",
        "PRF",
@@ -56,6 +57,9 @@ bool plugin_feature_matches(plugin_feature_t *a, plugin_feature_t *b)
                        case FEATURE_CRYPTER:
                                return a->crypter.alg == b->crypter.alg &&
                                           a->crypter.key_size == b->crypter.key_size;
+                       case FEATURE_AEAD:
+                               return a->aead.alg == b->aead.alg &&
+                                          a->aead.key_size == b->aead.key_size;
                        case FEATURE_SIGNER:
                                return a->signer == b->signer;
                        case FEATURE_HASHER:
@@ -116,6 +120,14 @@ char* plugin_feature_get_string(plugin_feature_t *feature)
                                return str;
                        }
                        break;
+               case FEATURE_AEAD:
+                       if (asprintf(&str, "%N:%N-%d", plugin_feature_names, feature->type,
+                                       encryption_algorithm_names, feature->aead.alg,
+                                       feature->aead.key_size) > 0)
+                       {
+                               return str;
+                       }
+                       break;
                case FEATURE_SIGNER:
                        if (asprintf(&str, "%N:%N", plugin_feature_names, feature->type,
                                        integrity_algorithm_names, feature->signer) > 0)
index c10c3c4..1f77629 100644 (file)
@@ -95,6 +95,8 @@ struct plugin_feature_t {
                FEATURE_NONE,
                /** crypter_t */
                FEATURE_CRYPTER,
+               /** aead_t */
+               FEATURE_AEAD,
                /** signer_t */
                FEATURE_SIGNER,
                /** hasher_t */
@@ -141,6 +143,11 @@ struct plugin_feature_t {
                        encryption_algorithm_t alg;
                        size_t key_size;
                } crypter;
+               /** FEATURE_AEAD */
+               struct {
+                       encryption_algorithm_t alg;
+                       size_t key_size;
+               } aead;
                /** FEATURE_SIGNER */
                integrity_algorithm_t signer;
                /** FEATURE_PRF */
@@ -240,6 +247,7 @@ struct plugin_feature_t {
 
 #define __PLUGIN_FEATURE(kind, type, ...)                                      (plugin_feature_t){ FEATURE_##kind, FEATURE_##type, { __VA_ARGS__ }}
 #define _PLUGIN_FEATURE_CRYPTER(kind, alg, size)                       __PLUGIN_FEATURE(kind, CRYPTER, .crypter = { alg, size })
+#define _PLUGIN_FEATURE_AEAD(kind, alg, size)                          __PLUGIN_FEATURE(kind, AEAD, .aead = { alg, size })
 #define _PLUGIN_FEATURE_SIGNER(kind, alg)                                      __PLUGIN_FEATURE(kind, SIGNER, .signer = alg)
 #define _PLUGIN_FEATURE_HASHER(kind, alg)                                      __PLUGIN_FEATURE(kind, HASHER, .hasher = alg)
 #define _PLUGIN_FEATURE_PRF(kind, alg)                                         __PLUGIN_FEATURE(kind, PRF, .prf = alg)
@@ -262,6 +270,7 @@ struct plugin_feature_t {
 #define __PLUGIN_FEATURE_REGISTER(type, _f)                                    (plugin_feature_t){ FEATURE_REGISTER, FEATURE_##type, .reg.f = _f }
 #define __PLUGIN_FEATURE_REGISTER_BUILDER(type, _f, _final)    (plugin_feature_t){ FEATURE_REGISTER, FEATURE_##type, .reg = {.f = _f, .final = _final, }}
 #define _PLUGIN_FEATURE_REGISTER_CRYPTER(type, f)                      __PLUGIN_FEATURE_REGISTER(type, f)
+#define _PLUGIN_FEATURE_REGISTER_AEAD(type, f)                                 __PLUGIN_FEATURE_REGISTER(type, f)
 #define _PLUGIN_FEATURE_REGISTER_SIGNER(type, f)                       __PLUGIN_FEATURE_REGISTER(type, f)
 #define _PLUGIN_FEATURE_REGISTER_HASHER(type, f)                       __PLUGIN_FEATURE_REGISTER(type, f)
 #define _PLUGIN_FEATURE_REGISTER_PRF(type, f)                          __PLUGIN_FEATURE_REGISTER(type, f)
index 831a106..ecd1d71 100644 (file)
@@ -297,6 +297,7 @@ static bool load_feature(private_plugin_loader_t *this, plugin_entry_t *entry,
        switch (feature->type)
        {
                case FEATURE_CRYPTER:
+               case FEATURE_AEAD:
                case FEATURE_SIGNER:
                case FEATURE_HASHER:
                case FEATURE_PRF:
@@ -340,6 +341,10 @@ static bool load_feature(private_plugin_loader_t *this, plugin_entry_t *entry,
                                lib->crypto->add_crypter(lib->crypto, feature->crypter.alg,
                                                                        name, reg->reg.f);
                                break;
+                       case FEATURE_AEAD:
+                               lib->crypto->add_aead(lib->crypto, feature->aead.alg,
+                                                                       name, reg->reg.f);
+                               break;
                        case FEATURE_SIGNER:
                                lib->crypto->add_signer(lib->crypto, feature->signer,
                                                                        name, reg->reg.f);