]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
unit-tests: Actually verify registered algorithms against test vectors
authorTobias Brunner <tobias@strongswan.org>
Thu, 13 Mar 2014 15:03:05 +0000 (16:03 +0100)
committerTobias Brunner <tobias@strongswan.org>
Thu, 20 Mar 2014 14:49:05 +0000 (15:49 +0100)
Previously, the {ns}.crypto_test.on_add option had to be enabled to
actually test the algorithms, which we can't enforce for the tests in
the test_runner as the option is already read when the crypto factory
is initialized.  Even so, we wouldn't want to do this for every unit
test, which would be the result of enabling that option.

src/libstrongswan/crypto/crypto_factory.c
src/libstrongswan/tests/suites/test_vectors.c

index dba3f6f6dae4dbd00e0c7cfbc02af7c7f3fe338a..69225bd1ec52075303513d19dadbd9e94f3046ba 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Tobias Brunner
+ * Copyright (C) 2013-2014 Tobias Brunner
  * Copyright (C) 2008 Martin Willi
  * Hochschule fuer Technik Rapperswil
  *
@@ -20,6 +20,7 @@
 #include <threading/rwlock.h>
 #include <collections/linked_list.h>
 #include <crypto/crypto_tester.h>
+#include <utils/test.h>
 
 const char *default_plugin_name = "default";
 
@@ -976,3 +977,39 @@ crypto_factory_t *crypto_factory_create()
 
        return &this->public;
 }
+
+/**
+ * Manually verify all registered algorithms against test vectors
+ */
+static u_int verify_registered_algorithms(crypto_factory_t *factory)
+{
+       private_crypto_factory_t *this = (private_crypto_factory_t*)factory;
+       enumerator_t *enumerator;
+       entry_t *entry;
+       u_int failures = 0;
+
+#define TEST_ALGORITHMS(test, ...) do { \
+       enumerator = this->test##s->create_enumerator(this->test##s); \
+       while (enumerator->enumerate(enumerator, &entry)) \
+       { \
+               if (!this->tester->test_##test(this->tester, entry->algo, ##__VA_ARGS__, \
+                                                       entry->create_##test, NULL, entry->plugin_name)) \
+               { \
+                       failures++; \
+               } \
+       } \
+       enumerator->destroy(enumerator); \
+} while (0)
+
+       this->lock->read_lock(this->lock);
+       TEST_ALGORITHMS(crypter, 0);
+       TEST_ALGORITHMS(aead, 0);
+       TEST_ALGORITHMS(signer);
+       TEST_ALGORITHMS(hasher);
+       TEST_ALGORITHMS(prf);
+       TEST_ALGORITHMS(rng);
+       this->lock->unlock(this->lock);
+       return failures;
+}
+
+EXPORT_FUNCTION_FOR_TESTS(crypto, verify_registered_algorithms);
index 242ac9d09edbe390d4b5b290edf7a31d339bf046..a1205d0be9dc080cb1040eab19f073802287b37f 100644 (file)
@@ -1,4 +1,7 @@
 /*
+ * Copyright (C) 2014 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
  * Copyright (C) 2013 Martin Willi
  * Copyright (C) 2013 revosec AG
  *
 
 #include "test_suite.h"
 
-/*******************************************************************************
- * Check if test vectors have been successful during transform registration
- */
+#include <utils/test.h>
+
+IMPORT_FUNCTION_FOR_TESTS(crypto, verify_registered_algorithms, u_int,
+                                                 crypto_factory_t *factory);
 
 START_TEST(test_vectors)
 {
-       u_int failed = lib->crypto->get_test_vector_failures(lib->crypto);
+       u_int failed = TEST_FUNCTION(crypto, verify_registered_algorithms,
+                                                                lib->crypto);
        fail_if(failed > 0, "%u test vectors failed", failed);
 }
 END_TEST