crypto-tester: Use the plugin feature key size to benchmark crypters/aeads

We previously didn't pass the key size during algorithm registration, but this
resulted in benchmarking with the "default" key size the crypter uses when
passing 0 as key size.
This commit is contained in:
Martin Willi
2015-04-15 11:35:26 +02:00
parent 22d0c934cd
commit 3a5106caea
4 changed files with 29 additions and 21 deletions
+5 -5
View File
@@ -439,14 +439,14 @@ static void add_entry(private_crypto_factory_t *this, linked_list_t *list,
} }
METHOD(crypto_factory_t, add_crypter, bool, METHOD(crypto_factory_t, add_crypter, bool,
private_crypto_factory_t *this, encryption_algorithm_t algo, private_crypto_factory_t *this, encryption_algorithm_t algo, size_t key_size,
const char *plugin_name, crypter_constructor_t create) const char *plugin_name, crypter_constructor_t create)
{ {
u_int speed = 0; u_int speed = 0;
if (!this->test_on_add || if (!this->test_on_add ||
this->tester->test_crypter(this->tester, algo, 0, create, this->tester->test_crypter(this->tester, algo, key_size, create,
this->bench ? &speed : NULL, plugin_name)) this->bench ? &speed : NULL, plugin_name))
{ {
add_entry(this, this->crypters, algo, plugin_name, speed, create); add_entry(this, this->crypters, algo, plugin_name, speed, create);
return TRUE; return TRUE;
@@ -476,13 +476,13 @@ METHOD(crypto_factory_t, remove_crypter, void,
} }
METHOD(crypto_factory_t, add_aead, bool, METHOD(crypto_factory_t, add_aead, bool,
private_crypto_factory_t *this, encryption_algorithm_t algo, private_crypto_factory_t *this, encryption_algorithm_t algo, size_t key_size,
const char *plugin_name, aead_constructor_t create) const char *plugin_name, aead_constructor_t create)
{ {
u_int speed = 0; u_int speed = 0;
if (!this->test_on_add || if (!this->test_on_add ||
this->tester->test_aead(this->tester, algo, 0, 0, create, this->tester->test_aead(this->tester, algo, key_size, 0, create,
this->bench ? &speed : NULL, plugin_name)) this->bench ? &speed : NULL, plugin_name))
{ {
add_entry(this, this->aeads, algo, plugin_name, speed, create); add_entry(this, this->aeads, algo, plugin_name, speed, create);
+6 -2
View File
@@ -162,12 +162,14 @@ struct crypto_factory_t {
* Register a crypter constructor. * Register a crypter constructor.
* *
* @param algo algorithm to constructor * @param algo algorithm to constructor
* @param key size key size to peform benchmarking for
* @param plugin_name plugin that registered this algorithm * @param plugin_name plugin that registered this algorithm
* @param create constructor function for that algorithm * @param create constructor function for that algorithm
* @return TRUE if registered, FALSE if test vector failed * @return TRUE if registered, FALSE if test vector failed
*/ */
bool (*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); size_t key_size, const char *plugin_name,
crypter_constructor_t create);
/** /**
* Unregister a crypter constructor. * Unregister a crypter constructor.
@@ -187,12 +189,14 @@ struct crypto_factory_t {
* Register a aead constructor. * Register a aead constructor.
* *
* @param algo algorithm to constructor * @param algo algorithm to constructor
* @param key size key size to peform benchmarking for
* @param plugin_name plugin that registered this algorithm * @param plugin_name plugin that registered this algorithm
* @param create constructor function for that algorithm * @param create constructor function for that algorithm
* @return TRUE if registered, FALSE if test vector failed * @return TRUE if registered, FALSE if test vector failed
*/ */
bool (*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); size_t key_size, const char *plugin_name,
aead_constructor_t create);
/** /**
* Register a signer constructor. * Register a signer constructor.
+16 -14
View File
@@ -138,11 +138,11 @@ static u_int end_timing(struct timespec *start)
* Benchmark a crypter * Benchmark a crypter
*/ */
static u_int bench_crypter(private_crypto_tester_t *this, static u_int bench_crypter(private_crypto_tester_t *this,
encryption_algorithm_t alg, crypter_constructor_t create) encryption_algorithm_t alg, crypter_constructor_t create, size_t key_size)
{ {
crypter_t *crypter; crypter_t *crypter;
crypter = create(alg, 0); crypter = create(alg, key_size);
if (crypter) if (crypter)
{ {
char iv[crypter->get_iv_size(crypter)]; char iv[crypter->get_iv_size(crypter)];
@@ -280,8 +280,8 @@ failure:
{ {
if (failed) if (failed)
{ {
DBG1(DBG_LIB,"disable %N[%s]: no key size supported", DBG1(DBG_LIB,"disable %N[%s]: %zd byte key size not supported",
encryption_algorithm_names, alg, plugin_name); encryption_algorithm_names, alg, plugin_name, key_size);
return FALSE; return FALSE;
} }
else else
@@ -296,9 +296,10 @@ failure:
{ {
if (speed) if (speed)
{ {
*speed = bench_crypter(this, alg, create); *speed = bench_crypter(this, alg, create, key_size);
DBG1(DBG_LIB, "enabled %N[%s]: passed %u test vectors, %d points", DBG1(DBG_LIB, "enabled %N[%s]: passed %u test vectors, %d points "
encryption_algorithm_names, alg, plugin_name, tested, *speed); "(%zd bit key)", encryption_algorithm_names, alg,
plugin_name, tested, *speed, key_size * 8);
} }
else else
{ {
@@ -313,11 +314,11 @@ failure:
* Benchmark an aead transform * Benchmark an aead transform
*/ */
static u_int bench_aead(private_crypto_tester_t *this, static u_int bench_aead(private_crypto_tester_t *this,
encryption_algorithm_t alg, aead_constructor_t create) encryption_algorithm_t alg, aead_constructor_t create, size_t key_size)
{ {
aead_t *aead; aead_t *aead;
aead = create(alg, 0, 0); aead = create(alg, key_size, 0);
if (aead) if (aead)
{ {
char iv[aead->get_iv_size(aead)]; char iv[aead->get_iv_size(aead)];
@@ -474,8 +475,8 @@ failure:
{ {
if (failed) if (failed)
{ {
DBG1(DBG_LIB,"disable %N[%s]: no key size supported", DBG1(DBG_LIB,"disable %N[%s]: %zd byte key size not supported",
encryption_algorithm_names, alg, plugin_name); encryption_algorithm_names, alg, plugin_name, key_size);
return FALSE; return FALSE;
} }
else else
@@ -490,9 +491,10 @@ failure:
{ {
if (speed) if (speed)
{ {
*speed = bench_aead(this, alg, create); *speed = bench_aead(this, alg, create, key_size);
DBG1(DBG_LIB, "enabled %N[%s]: passed %u test vectors, %d points", DBG1(DBG_LIB, "enabled %N[%s]: passed %u test vectors, %d points "
encryption_algorithm_names, alg, plugin_name, tested, *speed); "(%zd bit key)", encryption_algorithm_names, alg,
plugin_name, tested, *speed, key_size * 8);
} }
else else
{ {
@@ -437,10 +437,12 @@ bool plugin_feature_load(plugin_t *plugin, plugin_feature_t *feature,
{ {
case FEATURE_CRYPTER: case FEATURE_CRYPTER:
lib->crypto->add_crypter(lib->crypto, feature->arg.crypter.alg, lib->crypto->add_crypter(lib->crypto, feature->arg.crypter.alg,
feature->arg.crypter.key_size,
name, reg->arg.reg.f); name, reg->arg.reg.f);
break; break;
case FEATURE_AEAD: case FEATURE_AEAD:
lib->crypto->add_aead(lib->crypto, feature->arg.aead.alg, lib->crypto->add_aead(lib->crypto, feature->arg.aead.alg,
feature->arg.aead.key_size,
name, reg->arg.reg.f); name, reg->arg.reg.f);
break; break;
case FEATURE_SIGNER: case FEATURE_SIGNER: