]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Hash function for plugin features added.
authorTobias Brunner <tobias@strongswan.org>
Wed, 23 May 2012 15:37:53 +0000 (17:37 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 23 May 2012 15:50:05 +0000 (17:50 +0200)
src/libstrongswan/plugins/plugin_feature.c
src/libstrongswan/plugins/plugin_feature.h

index 7239e512b0ec50af71edd44ac99a63675b128633..eed3a31b8f925af8209ac747038a9f9fa9f8bd07 100644 (file)
@@ -1,4 +1,7 @@
 /*
+ * Copyright (C) 2012 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
  * Copyright (C) 2011 Martin Willi
  * Copyright (C) 2011 revosec AG
  *
@@ -48,6 +51,56 @@ ENUM(plugin_feature_names, FEATURE_NONE, FEATURE_CUSTOM,
        "CUSTOM",
 );
 
+/**
+ * See header.
+ */
+u_int32_t plugin_feature_hash(plugin_feature_t *feature)
+{
+       chunk_t data;
+
+       switch (feature->type)
+       {
+               case FEATURE_NONE:
+               case FEATURE_RNG:
+               case FEATURE_NONCE_GEN:
+               case FEATURE_DATABASE:
+               case FEATURE_FETCHER:
+                       /* put these special cases in their (type-specific) buckets */
+                       data = chunk_empty;
+                       break;
+               case FEATURE_CRYPTER:
+               case FEATURE_AEAD:
+               case FEATURE_SIGNER:
+               case FEATURE_HASHER:
+               case FEATURE_PRF:
+               case FEATURE_DH:
+               case FEATURE_PRIVKEY:
+               case FEATURE_PRIVKEY_GEN:
+               case FEATURE_PUBKEY:
+               case FEATURE_PRIVKEY_SIGN:
+               case FEATURE_PUBKEY_VERIFY:
+               case FEATURE_PRIVKEY_DECRYPT:
+               case FEATURE_PUBKEY_ENCRYPT:
+               case FEATURE_CERT_DECODE:
+               case FEATURE_CERT_ENCODE:
+               case FEATURE_EAP_SERVER:
+               case FEATURE_EAP_PEER:
+                       data = chunk_from_thing(feature->arg);
+                       break;
+               case FEATURE_CUSTOM:
+                       data = chunk_create(feature->arg.custom,
+                                                               strlen(feature->arg.custom));
+                       break;
+               case FEATURE_XAUTH_SERVER:
+               case FEATURE_XAUTH_PEER:
+                       data = chunk_create(feature->arg.xauth,
+                                                               strlen(feature->arg.xauth));
+                       break;
+       }
+       return chunk_hash_inc(chunk_from_thing(feature->type),
+                                                 chunk_hash(data));
+}
+
 /**
  * See header.
  */
index 25a58a4b55059c411df273c00285f772abb103fe..10a316e4aaf1115aacedf68db75b4b8a24c6fac1 100644 (file)
@@ -1,4 +1,7 @@
 /*
+ * Copyright (C) 2012 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
  * Copyright (C) 2011 Martin Willi
  * Copyright (C) 2011 revosec AG
  *
@@ -303,6 +306,18 @@ struct plugin_feature_t {
  */
 extern enum_name_t *plugin_feature_names;
 
+/**
+ * Calculates a hash value for the given feature.
+ *
+ * Since this is intended to be used with the plugin_features_matches function
+ * the hash is not really unique for all types of features (e.g. RNGs are all
+ * mapped to the same value because they are loosely matched by said function).
+ *
+ * @param feature      feature to hash
+ * @return                     hash value of the feature
+ */
+u_int32_t plugin_feature_hash(plugin_feature_t *feature);
+
 /**
  * Check if feature a matches to feature b.
  *