app/crypto-perf: add extra option checks

When using the verify test, test name is necessary
to be passed when digest is needed.

Also, when using an block cipher algorithm (CBC, ECB),
the buffer size has to be aligned to the block size.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Acked-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>
This commit is contained in:
Pablo de Lara 2017-03-27 12:26:05 +01:00
parent f6cefe253c
commit fc4600fb25

View File

@ -38,6 +38,9 @@
#include "cperf_options.h"
#define AES_BLOCK_SIZE 16
#define DES_BLOCK_SIZE 8
struct name_id_map {
const char *name;
uint32_t id;
@ -717,6 +720,8 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
int
cperf_options_check(struct cperf_options *options)
{
uint32_t buffer_size, buffer_size_idx = 0;
if (options->segments_nb > options->min_buffer_size) {
RTE_LOG(ERR, USER1,
"Segments number greater than buffer size.\n");
@ -730,6 +735,14 @@ cperf_options_check(struct cperf_options *options)
return -EINVAL;
}
if (options->test == CPERF_TEST_TYPE_VERIFY &&
options->op_type != CPERF_CIPHER_ONLY &&
options->test_name == NULL) {
RTE_LOG(ERR, USER1, "Define test name to get the correct digest"
" from the test vectors.\n");
return -EINVAL;
}
if (options->test_name != NULL && options->test_file == NULL) {
RTE_LOG(ERR, USER1, "Define path to the file with test"
" vectors.\n");
@ -807,6 +820,45 @@ cperf_options_check(struct cperf_options *options)
}
}
if (options->cipher_algo == RTE_CRYPTO_CIPHER_AES_CBC ||
options->cipher_algo == RTE_CRYPTO_CIPHER_AES_ECB) {
if (options->inc_buffer_size != 0)
buffer_size = options->min_buffer_size;
else
buffer_size = options->buffer_size_list[0];
while (buffer_size <= options->max_buffer_size) {
if ((buffer_size % AES_BLOCK_SIZE) != 0) {
RTE_LOG(ERR, USER1, "Some of the buffer sizes are "
"not suitable for the algorithm selected\n");
return -EINVAL;
}
if (options->inc_buffer_size != 0)
buffer_size += options->inc_buffer_size;
else {
if (++buffer_size_idx == options->buffer_size_count)
break;
buffer_size = options->buffer_size_list[buffer_size_idx];
}
}
}
if (options->cipher_algo == RTE_CRYPTO_CIPHER_DES_CBC ||
options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_CBC ||
options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_ECB) {
for (buffer_size = options->min_buffer_size;
buffer_size < options->max_buffer_size;
buffer_size += options->inc_buffer_size) {
if ((buffer_size % DES_BLOCK_SIZE) != 0) {
RTE_LOG(ERR, USER1, "Some of the buffer sizes are "
"not suitable for the algorithm selected\n");
return -EINVAL;
}
}
}
return 0;
}