summaryrefslogtreecommitdiff
path: root/src/libstrongswan/crypto/crypto_factory.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/crypto/crypto_factory.c')
-rw-r--r--src/libstrongswan/crypto/crypto_factory.c47
1 files changed, 42 insertions, 5 deletions
diff --git a/src/libstrongswan/crypto/crypto_factory.c b/src/libstrongswan/crypto/crypto_factory.c
index dba3f6f6d..6dea30ee3 100644
--- a/src/libstrongswan/crypto/crypto_factory.c
+++ b/src/libstrongswan/crypto/crypto_factory.c
@@ -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";
@@ -175,7 +176,7 @@ METHOD(crypto_factory_t, create_crypter, crypter_t*,
METHOD(crypto_factory_t, create_aead, aead_t*,
private_crypto_factory_t *this, encryption_algorithm_t algo,
- size_t key_size)
+ size_t key_size, size_t salt_size)
{
enumerator_t *enumerator;
entry_t *entry;
@@ -189,12 +190,12 @@ METHOD(crypto_factory_t, create_aead, aead_t*,
{
if (this->test_on_create &&
!this->tester->test_aead(this->tester, algo, key_size,
- entry->create_aead, NULL,
+ salt_size, entry->create_aead, NULL,
default_plugin_name))
{
continue;
}
- aead = entry->create_aead(algo, key_size);
+ aead = entry->create_aead(algo, key_size, salt_size);
if (aead)
{
break;
@@ -473,7 +474,7 @@ METHOD(crypto_factory_t, add_aead, bool,
u_int speed = 0;
if (!this->test_on_add ||
- this->tester->test_aead(this->tester, algo, 0, create,
+ this->tester->test_aead(this->tester, algo, 0, 0, create,
this->bench ? &speed : NULL, plugin_name))
{
add_entry(this, this->aeads, algo, plugin_name, speed, create);
@@ -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, 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);