trace back crypto algorithms to the plugins that registered them
This commit is contained in:
@@ -20,13 +20,29 @@
|
||||
#include <utils/linked_list.h>
|
||||
#include <crypto/crypto_tester.h>
|
||||
|
||||
const char *default_plugin_name = "default";
|
||||
|
||||
typedef struct entry_t entry_t;
|
||||
|
||||
struct entry_t {
|
||||
/* algorithm */
|
||||
/**
|
||||
* algorithm
|
||||
*/
|
||||
u_int algo;
|
||||
/* benchmarked speed */
|
||||
|
||||
/**
|
||||
* plugin that registered this algorithm
|
||||
*/
|
||||
const char *plugin_name;
|
||||
|
||||
/**
|
||||
* benchmarked speed
|
||||
*/
|
||||
u_int speed;
|
||||
/* constructor */
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
union {
|
||||
crypter_constructor_t create_crypter;
|
||||
aead_constructor_t create_aead;
|
||||
@@ -128,7 +144,8 @@ METHOD(crypto_factory_t, create_crypter, crypter_t*,
|
||||
{
|
||||
if (this->test_on_create &&
|
||||
!this->tester->test_crypter(this->tester, algo, key_size,
|
||||
entry->create_crypter, NULL))
|
||||
entry->create_crypter, NULL,
|
||||
default_plugin_name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -160,7 +177,8 @@ 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))
|
||||
entry->create_aead, NULL,
|
||||
default_plugin_name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -191,7 +209,8 @@ METHOD(crypto_factory_t, create_signer, signer_t*,
|
||||
{
|
||||
if (this->test_on_create &&
|
||||
!this->tester->test_signer(this->tester, algo,
|
||||
entry->create_signer, NULL))
|
||||
entry->create_signer, NULL,
|
||||
default_plugin_name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -223,7 +242,8 @@ METHOD(crypto_factory_t, create_hasher, hasher_t*,
|
||||
{
|
||||
if (this->test_on_create && algo != HASH_PREFERRED &&
|
||||
!this->tester->test_hasher(this->tester, algo,
|
||||
entry->create_hasher, NULL))
|
||||
entry->create_hasher, NULL,
|
||||
default_plugin_name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -254,7 +274,8 @@ METHOD(crypto_factory_t, create_prf, prf_t*,
|
||||
{
|
||||
if (this->test_on_create &&
|
||||
!this->tester->test_prf(this->tester, algo,
|
||||
entry->create_prf, NULL))
|
||||
entry->create_prf, NULL,
|
||||
default_plugin_name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -286,7 +307,8 @@ METHOD(crypto_factory_t, create_rng, rng_t*,
|
||||
{
|
||||
if (this->test_on_create &&
|
||||
!this->tester->test_rng(this->tester, quality,
|
||||
entry->create_rng, NULL))
|
||||
entry->create_rng, NULL,
|
||||
default_plugin_name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -350,7 +372,8 @@ METHOD(crypto_factory_t, create_dh, diffie_hellman_t*,
|
||||
* Insert an algorithm entry to a list
|
||||
*/
|
||||
static void add_entry(private_crypto_factory_t *this, linked_list_t *list,
|
||||
int algo, u_int speed, void *create)
|
||||
int algo, const char *plugin_name,
|
||||
u_int speed, void *create)
|
||||
{
|
||||
entry_t *entry, *current;
|
||||
linked_list_t *tmp;
|
||||
@@ -358,6 +381,7 @@ static void add_entry(private_crypto_factory_t *this, linked_list_t *list,
|
||||
|
||||
INIT(entry,
|
||||
.algo = algo,
|
||||
.plugin_name = plugin_name,
|
||||
.speed = speed,
|
||||
);
|
||||
entry->create = create;
|
||||
@@ -391,16 +415,16 @@ static void add_entry(private_crypto_factory_t *this, linked_list_t *list,
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, add_crypter, void,
|
||||
private_crypto_factory_t *this, encryption_algorithm_t algo,
|
||||
crypter_constructor_t create)
|
||||
private_crypto_factory_t *this, encryption_algorithm_t algo,
|
||||
const char *plugin_name, crypter_constructor_t create)
|
||||
{
|
||||
u_int speed = 0;
|
||||
|
||||
if (!this->test_on_add ||
|
||||
this->tester->test_crypter(this->tester, algo, 0, create,
|
||||
this->bench ? &speed : NULL))
|
||||
this->bench ? &speed : NULL, plugin_name))
|
||||
{
|
||||
add_entry(this, this->crypters, algo, speed, create);
|
||||
add_entry(this, this->crypters, algo, plugin_name, speed, create);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,16 +449,16 @@ METHOD(crypto_factory_t, remove_crypter, void,
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, add_aead, void,
|
||||
private_crypto_factory_t *this, encryption_algorithm_t algo,
|
||||
aead_constructor_t create)
|
||||
private_crypto_factory_t *this, encryption_algorithm_t algo,
|
||||
const char *plugin_name, aead_constructor_t create)
|
||||
{
|
||||
u_int speed = 0;
|
||||
|
||||
if (!this->test_on_add ||
|
||||
this->tester->test_aead(this->tester, algo, 0, create,
|
||||
this->bench ? &speed : NULL))
|
||||
this->bench ? &speed : NULL, plugin_name))
|
||||
{
|
||||
add_entry(this, this->aeads, algo, speed, create);
|
||||
add_entry(this, this->aeads, algo, plugin_name, speed, create);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,16 +483,16 @@ METHOD(crypto_factory_t, remove_aead, void,
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, add_signer, void,
|
||||
private_crypto_factory_t *this, integrity_algorithm_t algo,
|
||||
signer_constructor_t create)
|
||||
private_crypto_factory_t *this, integrity_algorithm_t algo,
|
||||
const char *plugin_name, signer_constructor_t create)
|
||||
{
|
||||
u_int speed = 0;
|
||||
|
||||
if (!this->test_on_add ||
|
||||
this->tester->test_signer(this->tester, algo, create,
|
||||
this->bench ? &speed : NULL))
|
||||
this->bench ? &speed : NULL, plugin_name))
|
||||
{
|
||||
add_entry(this, this->signers, algo, speed, create);
|
||||
add_entry(this, this->signers, algo, plugin_name, speed, create);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -493,16 +517,16 @@ METHOD(crypto_factory_t, remove_signer, void,
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, add_hasher, void,
|
||||
private_crypto_factory_t *this, hash_algorithm_t algo,
|
||||
hasher_constructor_t create)
|
||||
private_crypto_factory_t *this, hash_algorithm_t algo,
|
||||
const char *plugin_name, hasher_constructor_t create)
|
||||
{
|
||||
u_int speed = 0;
|
||||
|
||||
if (!this->test_on_add ||
|
||||
this->tester->test_hasher(this->tester, algo, create,
|
||||
this->bench ? &speed : NULL))
|
||||
this->bench ? &speed : NULL, plugin_name))
|
||||
{
|
||||
add_entry(this, this->hashers, algo, speed, create);
|
||||
add_entry(this, this->hashers, algo, plugin_name, speed, create);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -527,16 +551,16 @@ METHOD(crypto_factory_t, remove_hasher, void,
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, add_prf, void,
|
||||
private_crypto_factory_t *this, pseudo_random_function_t algo,
|
||||
prf_constructor_t create)
|
||||
private_crypto_factory_t *this, pseudo_random_function_t algo,
|
||||
const char *plugin_name, prf_constructor_t create)
|
||||
{
|
||||
u_int speed = 0;
|
||||
|
||||
if (!this->test_on_add ||
|
||||
this->tester->test_prf(this->tester, algo, create,
|
||||
this->bench ? &speed : NULL))
|
||||
this->bench ? &speed : NULL, plugin_name))
|
||||
{
|
||||
add_entry(this, this->prfs, algo, speed, create);
|
||||
add_entry(this, this->prfs, algo, plugin_name, speed, create);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,15 +586,15 @@ METHOD(crypto_factory_t, remove_prf, void,
|
||||
|
||||
METHOD(crypto_factory_t, add_rng, void,
|
||||
private_crypto_factory_t *this, rng_quality_t quality,
|
||||
rng_constructor_t create)
|
||||
const char *plugin_name, rng_constructor_t create)
|
||||
{
|
||||
u_int speed = 0;
|
||||
|
||||
if (!this->test_on_add ||
|
||||
this->tester->test_rng(this->tester, quality, create,
|
||||
this->bench ? &speed : NULL))
|
||||
this->bench ? &speed : NULL, plugin_name))
|
||||
{
|
||||
add_entry(this, this->rngs, quality, speed, create);
|
||||
add_entry(this, this->rngs, quality, plugin_name, speed, create);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -595,10 +619,10 @@ METHOD(crypto_factory_t, remove_rng, void,
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, add_dh, void,
|
||||
private_crypto_factory_t *this, diffie_hellman_group_t group,
|
||||
dh_constructor_t create)
|
||||
private_crypto_factory_t *this, diffie_hellman_group_t group,
|
||||
const char *plugin_name, dh_constructor_t create)
|
||||
{
|
||||
add_entry(this, this->dhs, group, 0, create);
|
||||
add_entry(this, this->dhs, group, plugin_name, 0, create);
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, remove_dh, void,
|
||||
@@ -660,9 +684,11 @@ static enumerator_t *create_enumerator(private_crypto_factory_t *this,
|
||||
/**
|
||||
* Filter function to enumerate algorithm, not entry
|
||||
*/
|
||||
static bool crypter_filter(void *n, entry_t **entry, encryption_algorithm_t *algo)
|
||||
static bool crypter_filter(void *n, entry_t **entry, encryption_algorithm_t *algo,
|
||||
void *i2, const char **plugin_name)
|
||||
{
|
||||
*algo = (*entry)->algo;
|
||||
*plugin_name = (*entry)->plugin_name;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -681,9 +707,11 @@ METHOD(crypto_factory_t, create_aead_enumerator, enumerator_t*,
|
||||
/**
|
||||
* Filter function to enumerate algorithm, not entry
|
||||
*/
|
||||
static bool signer_filter(void *n, entry_t **entry, integrity_algorithm_t *algo)
|
||||
static bool signer_filter(void *n, entry_t **entry, integrity_algorithm_t *algo,
|
||||
void *i2, const char **plugin_name)
|
||||
{
|
||||
*algo = (*entry)->algo;
|
||||
*plugin_name = (*entry)->plugin_name;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -696,9 +724,11 @@ METHOD(crypto_factory_t, create_signer_enumerator, enumerator_t*,
|
||||
/**
|
||||
* Filter function to enumerate algorithm, not entry
|
||||
*/
|
||||
static bool hasher_filter(void *n, entry_t **entry, hash_algorithm_t *algo)
|
||||
static bool hasher_filter(void *n, entry_t **entry, hash_algorithm_t *algo,
|
||||
void *i2, const char **plugin_name)
|
||||
{
|
||||
*algo = (*entry)->algo;
|
||||
*plugin_name = (*entry)->plugin_name;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -711,9 +741,11 @@ METHOD(crypto_factory_t, create_hasher_enumerator, enumerator_t*,
|
||||
/**
|
||||
* Filter function to enumerate algorithm, not entry
|
||||
*/
|
||||
static bool prf_filter(void *n, entry_t **entry, pseudo_random_function_t *algo)
|
||||
static bool prf_filter(void *n, entry_t **entry, pseudo_random_function_t *algo,
|
||||
void *i2, const char **plugin_name)
|
||||
{
|
||||
*algo = (*entry)->algo;
|
||||
*plugin_name = (*entry)->plugin_name;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -726,9 +758,11 @@ METHOD(crypto_factory_t, create_prf_enumerator, enumerator_t*,
|
||||
/**
|
||||
* Filter function to enumerate algorithm, not entry
|
||||
*/
|
||||
static bool dh_filter(void *n, entry_t **entry, diffie_hellman_group_t *group)
|
||||
static bool dh_filter(void *n, entry_t **entry, diffie_hellman_group_t *group,
|
||||
void *i2, const char **plugin_name)
|
||||
{
|
||||
*group = (*entry)->algo;
|
||||
*plugin_name = (*entry)->plugin_name;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -738,6 +772,22 @@ METHOD(crypto_factory_t, create_dh_enumerator, enumerator_t*,
|
||||
return create_enumerator(this, this->dhs, dh_filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter function to enumerate algorithm, not entry
|
||||
*/
|
||||
static bool rng_filter(void *n, entry_t **entry, rng_quality_t *quality,
|
||||
void *i2, const char **plugin_name)
|
||||
{
|
||||
*quality = (*entry)->algo;
|
||||
*plugin_name = (*entry)->plugin_name;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, create_rng_enumerator, enumerator_t*,
|
||||
private_crypto_factory_t *this)
|
||||
{
|
||||
return create_enumerator(this, this->rngs, rng_filter);
|
||||
}
|
||||
METHOD(crypto_factory_t, add_test_vector, void,
|
||||
private_crypto_factory_t *this, transform_type_t type, void *vector)
|
||||
{
|
||||
@@ -812,6 +862,7 @@ crypto_factory_t *crypto_factory_create()
|
||||
.create_hasher_enumerator = _create_hasher_enumerator,
|
||||
.create_prf_enumerator = _create_prf_enumerator,
|
||||
.create_dh_enumerator = _create_dh_enumerator,
|
||||
.create_rng_enumerator = _create_rng_enumerator,
|
||||
.add_test_vector = _add_test_vector,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user