]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
crypto-factory: count the number of test vector failures during registration
authorMartin Willi <martin@revosec.ch>
Tue, 9 Apr 2013 12:30:13 +0000 (14:30 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 21 Jun 2013 08:53:20 +0000 (10:53 +0200)
src/libstrongswan/crypto/crypto_factory.c
src/libstrongswan/crypto/crypto_factory.h

index 5a363e9f07d539dfb582843302ce0b6db64469cc..b891980037ac3f1c1890723cb13d81e1a254697c 100644 (file)
@@ -128,6 +128,11 @@ struct private_crypto_factory_t {
         */
        bool bench;
 
+       /**
+        * Number of failed test vectors during "add".
+        */
+       u_int test_failures;
+
        /**
         * rwlock to lock access to modules
         */
@@ -435,8 +440,8 @@ static void add_entry(private_crypto_factory_t *this, linked_list_t *list,
        this->lock->unlock(this->lock);
 }
 
-METHOD(crypto_factory_t, add_crypter, void,
-       private_crypto_factory_t *this, encryption_algorithm_t algo,
+METHOD(crypto_factory_t, add_crypter, bool,
+       private_crypto_factory_t *this, encryption_algorithm_t algo,
        const char *plugin_name, crypter_constructor_t create)
 {
        u_int speed = 0;
@@ -446,7 +451,10 @@ METHOD(crypto_factory_t, add_crypter, void,
                                                                   this->bench ? &speed : NULL, plugin_name))
        {
                add_entry(this, this->crypters, algo, plugin_name, speed, create);
+               return TRUE;
        }
+       this->test_failures++;
+       return FALSE;
 }
 
 METHOD(crypto_factory_t, remove_crypter, void,
@@ -469,8 +477,8 @@ METHOD(crypto_factory_t, remove_crypter, void,
        this->lock->unlock(this->lock);
 }
 
-METHOD(crypto_factory_t, add_aead, void,
-       private_crypto_factory_t *this, encryption_algorithm_t algo,
+METHOD(crypto_factory_t, add_aead, bool,
+       private_crypto_factory_t *this, encryption_algorithm_t algo,
        const char *plugin_name, aead_constructor_t create)
 {
        u_int speed = 0;
@@ -480,7 +488,10 @@ METHOD(crypto_factory_t, add_aead, void,
                                                                this->bench ? &speed : NULL, plugin_name))
        {
                add_entry(this, this->aeads, algo, plugin_name, speed, create);
+               return TRUE;
        }
+       this->test_failures++;
+       return FALSE;
 }
 
 METHOD(crypto_factory_t, remove_aead, void,
@@ -503,8 +514,8 @@ METHOD(crypto_factory_t, remove_aead, void,
        this->lock->unlock(this->lock);
 }
 
-METHOD(crypto_factory_t, add_signer, void,
-       private_crypto_factory_t *this, integrity_algorithm_t algo,
+METHOD(crypto_factory_t, add_signer, bool,
+       private_crypto_factory_t *this, integrity_algorithm_t algo,
        const char *plugin_name, signer_constructor_t create)
 {
        u_int speed = 0;
@@ -514,7 +525,10 @@ METHOD(crypto_factory_t, add_signer, void,
                                                                  this->bench ? &speed : NULL, plugin_name))
        {
                add_entry(this, this->signers, algo, plugin_name, speed, create);
+               return TRUE;
        }
+       this->test_failures++;
+       return FALSE;
 }
 
 METHOD(crypto_factory_t, remove_signer, void,
@@ -537,8 +551,8 @@ METHOD(crypto_factory_t, remove_signer, void,
        this->lock->unlock(this->lock);
 }
 
-METHOD(crypto_factory_t, add_hasher, void,
-       private_crypto_factory_t *this, hash_algorithm_t algo,
+METHOD(crypto_factory_t, add_hasher, bool,
+       private_crypto_factory_t *this, hash_algorithm_t algo,
        const char *plugin_name, hasher_constructor_t create)
 {
        u_int speed = 0;
@@ -548,7 +562,10 @@ METHOD(crypto_factory_t, add_hasher, void,
                                                                  this->bench ? &speed : NULL, plugin_name))
        {
                add_entry(this, this->hashers, algo, plugin_name, speed, create);
+               return TRUE;
        }
+       this->test_failures++;
+       return FALSE;
 }
 
 METHOD(crypto_factory_t, remove_hasher, void,
@@ -571,8 +588,8 @@ METHOD(crypto_factory_t, remove_hasher, void,
        this->lock->unlock(this->lock);
 }
 
-METHOD(crypto_factory_t, add_prf, void,
-       private_crypto_factory_t *this, pseudo_random_function_t algo,
+METHOD(crypto_factory_t, add_prf, bool,
+       private_crypto_factory_t *this, pseudo_random_function_t algo,
        const char *plugin_name, prf_constructor_t create)
 {
        u_int speed = 0;
@@ -582,7 +599,10 @@ METHOD(crypto_factory_t, add_prf, void,
                                                           this->bench ? &speed : NULL, plugin_name))
        {
                add_entry(this, this->prfs, algo, plugin_name, speed, create);
+               return TRUE;
        }
+       this->test_failures++;
+       return FALSE;
 }
 
 METHOD(crypto_factory_t, remove_prf, void,
@@ -605,7 +625,7 @@ METHOD(crypto_factory_t, remove_prf, void,
        this->lock->unlock(this->lock);
 }
 
-METHOD(crypto_factory_t, add_rng, void,
+METHOD(crypto_factory_t, add_rng, bool,
        private_crypto_factory_t *this, rng_quality_t quality,
        const char *plugin_name, rng_constructor_t create)
 {
@@ -616,7 +636,10 @@ METHOD(crypto_factory_t, add_rng, void,
                                                           this->bench ? &speed : NULL, plugin_name))
        {
                add_entry(this, this->rngs, quality, plugin_name, speed, create);
+               return TRUE;
        }
+       this->test_failures++;
+       return FALSE;
 }
 
 METHOD(crypto_factory_t, remove_rng, void,
@@ -639,11 +662,12 @@ METHOD(crypto_factory_t, remove_rng, void,
        this->lock->unlock(this->lock);
 }
 
-METHOD(crypto_factory_t, add_nonce_gen, void,
+METHOD(crypto_factory_t, add_nonce_gen, bool,
        private_crypto_factory_t *this, const char *plugin_name,
        nonce_gen_constructor_t create)
 {
        add_entry(this, this->nonce_gens, 0, plugin_name, 0, create);
+       return TRUE;
 }
 
 METHOD(crypto_factory_t, remove_nonce_gen, void,
@@ -666,11 +690,12 @@ METHOD(crypto_factory_t, remove_nonce_gen, void,
        this->lock->unlock(this->lock);
 }
 
-METHOD(crypto_factory_t, add_dh, void,
-       private_crypto_factory_t *this, diffie_hellman_group_t group,
-        const char *plugin_name, dh_constructor_t create)
+METHOD(crypto_factory_t, add_dh, bool,
+       private_crypto_factory_t *this, diffie_hellman_group_t group,
+       const char *plugin_name, dh_constructor_t create)
 {
        add_entry(this, this->dhs, group, plugin_name, 0, create);
+       return TRUE;
 }
 
 METHOD(crypto_factory_t, remove_dh, void,
@@ -875,6 +900,12 @@ METHOD(crypto_factory_t, add_test_vector, void,
        }
 }
 
+METHOD(crypto_factory_t, get_test_vector_failures, u_int,
+       private_crypto_factory_t *this)
+{
+       return this->test_failures;
+}
+
 METHOD(crypto_factory_t, destroy, void,
        private_crypto_factory_t *this)
 {
@@ -933,6 +964,7 @@ crypto_factory_t *crypto_factory_create()
                        .create_rng_enumerator = _create_rng_enumerator,
                        .create_nonce_gen_enumerator = _create_nonce_gen_enumerator,
                        .add_test_vector = _add_test_vector,
+                       .get_test_vector_failures = _get_test_vector_failures,
                        .destroy = _destroy,
                },
                .crypters = linked_list_create(),
@@ -955,4 +987,3 @@ crypto_factory_t *crypto_factory_create()
 
        return &this->public;
 }
-
index 5d23c897769a5fac0d2c3c43c998d4a7c21c2e94..256ecec63128c369705079872aac35aea3801a94 100644 (file)
@@ -162,9 +162,9 @@ struct crypto_factory_t {
         * @param algo                  algorithm to constructor
         * @param plugin_name   plugin that registered this algorithm
         * @param create                constructor function for that algorithm
-        * @return
+        * @return                              TRUE if registered, FALSE if test vector failed
         */
-       void (*add_crypter)(crypto_factory_t *this, encryption_algorithm_t algo,
+       bool (*add_crypter)(crypto_factory_t *this, encryption_algorithm_t algo,
                                                const char *plugin_name, crypter_constructor_t create);
 
        /**
@@ -187,9 +187,9 @@ struct crypto_factory_t {
         * @param algo                  algorithm to constructor
         * @param plugin_name   plugin that registered this algorithm
         * @param create                constructor function for that algorithm
-        * @return
+        * @return                              TRUE if registered, FALSE if test vector failed
         */
-       void (*add_aead)(crypto_factory_t *this, encryption_algorithm_t algo,
+       bool (*add_aead)(crypto_factory_t *this, encryption_algorithm_t algo,
                                         const char *plugin_name, aead_constructor_t create);
 
        /**
@@ -198,9 +198,9 @@ struct crypto_factory_t {
         * @param algo                  algorithm to constructor
         * @param plugin_name   plugin that registered this algorithm
         * @param create                constructor function for that algorithm
-        * @return
+        * @return                              TRUE if registered, FALSE if test vector failed
         */
-       void (*add_signer)(crypto_factory_t *this, integrity_algorithm_t algo,
+       bool (*add_signer)(crypto_factory_t *this, integrity_algorithm_t algo,
                                            const char *plugin_name, signer_constructor_t create);
 
        /**
@@ -219,9 +219,9 @@ struct crypto_factory_t {
         * @param algo                  algorithm to constructor
         * @param plugin_name   plugin that registered this algorithm
         * @param create                constructor function for that algorithm
-        * @return
+        * @return                              TRUE if registered, FALSE if test vector failed
         */
-       void (*add_hasher)(crypto_factory_t *this, hash_algorithm_t algo,
+       bool (*add_hasher)(crypto_factory_t *this, hash_algorithm_t algo,
                                           const char *plugin_name, hasher_constructor_t create);
 
        /**
@@ -237,9 +237,9 @@ struct crypto_factory_t {
         * @param algo                  algorithm to constructor
         * @param plugin_name   plugin that registered this algorithm
         * @param create                constructor function for that algorithm
-        * @return
+        * @return                              TRUE if registered, FALSE if test vector failed
         */
-       void (*add_prf)(crypto_factory_t *this, pseudo_random_function_t algo,
+       bool (*add_prf)(crypto_factory_t *this, pseudo_random_function_t algo,
                                        const char *plugin_name, prf_constructor_t create);
 
        /**
@@ -255,8 +255,9 @@ struct crypto_factory_t {
         * @param quality               quality of randomness this RNG serves
         * @param plugin_name   plugin that registered this algorithm
         * @param create                constructor function for such a quality
+        * @return                              TRUE if registered, FALSE if test vector failed
         */
-       void (*add_rng)(crypto_factory_t *this, rng_quality_t quality,
+       bool (*add_rng)(crypto_factory_t *this, rng_quality_t quality,
                                        const char *plugin_name, rng_constructor_t create);
 
        /**
@@ -271,8 +272,9 @@ struct crypto_factory_t {
         *
         * @param plugin_name   plugin that registered this algorithm
         * @param create                constructor function for that nonce generator
+        * @return                              TRUE if registered, FALSE if test vector failed
         */
-       void (*add_nonce_gen)(crypto_factory_t *this, const char *plugin_name,
+       bool (*add_nonce_gen)(crypto_factory_t *this, const char *plugin_name,
                                                  nonce_gen_constructor_t create);
 
        /**
@@ -289,9 +291,9 @@ struct crypto_factory_t {
         * @param group                 dh group to constructor
         * @param plugin_name   plugin that registered this algorithm
         * @param create                constructor function for that algorithm
-        * @return
+        * @return                              TRUE if registered, FALSE if test vector failed
         */
-       void (*add_dh)(crypto_factory_t *this, diffie_hellman_group_t group,
+       bool (*add_dh)(crypto_factory_t *this, diffie_hellman_group_t group,
                                   const char *plugin_name, dh_constructor_t create);
 
        /**
@@ -366,6 +368,16 @@ struct crypto_factory_t {
        void (*add_test_vector)(crypto_factory_t *this, transform_type_t type,
                                                        void *vector);
 
+       /**
+        * Get the number of test vector failures encountered during add.
+        *
+        * This counter gets incremented only if transforms get tested during
+        * registration.
+        *
+        * @return                              number of failed test vectors
+        */
+       u_int (*get_test_vector_failures)(crypto_factory_t *this);
+
        /**
         * Destroy a crypto_factory instance.
         */