make bench use wolfCLU_checkForArg()
parent
e73aa160da
commit
86e2c9a7ba
|
@ -57,7 +57,7 @@ static struct option long_options[] = {
|
||||||
/* @temporary: implement modes as flags */
|
/* @temporary: implement modes as flags */
|
||||||
{"encrypt", required_argument, 0, ENCRYPT },
|
{"encrypt", required_argument, 0, ENCRYPT },
|
||||||
{"decrypt", required_argument, 0, DECRYPT },
|
{"decrypt", required_argument, 0, DECRYPT },
|
||||||
{"bench", required_argument, 0, BENCHMARK },
|
{"bench", no_argument, 0, BENCHMARK },
|
||||||
{"hash", required_argument, 0, HASH },
|
{"hash", required_argument, 0, HASH },
|
||||||
{"x509", no_argument, 0, X509 },
|
{"x509", no_argument, 0, X509 },
|
||||||
{"req", required_argument, 0, REQUEST },
|
{"req", required_argument, 0, REQUEST },
|
||||||
|
|
|
@ -26,74 +26,82 @@ int wolfCLU_benchSetup(int argc, char** argv)
|
||||||
int ret = 0; /* return variable */
|
int ret = 0; /* return variable */
|
||||||
int time = 3; /* timer variable */
|
int time = 3; /* timer variable */
|
||||||
int i, j = 0; /* second loop variable */
|
int i, j = 0; /* second loop variable */
|
||||||
const char* algs[] = { /* list of acceptable algorithms */
|
char* algs[] = { /* list of acceptable algorithms */
|
||||||
#ifndef NO_AES
|
#ifndef NO_AES
|
||||||
"aes-cbc"
|
"aes-cbc",
|
||||||
#endif
|
#endif
|
||||||
#ifdef WOLFSSL_AES_COUNTER
|
#ifdef WOLFSSL_AES_COUNTER
|
||||||
, "aes-ctr"
|
"aes-ctr",
|
||||||
#endif
|
#endif
|
||||||
#ifndef NO_DES3
|
#ifndef NO_DES3
|
||||||
, "3des"
|
"3des",
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_CAMELLIA
|
#ifdef HAVE_CAMELLIA
|
||||||
, "camellia"
|
"camellia",
|
||||||
#endif
|
#endif
|
||||||
#ifndef NO_MD5
|
#ifndef NO_MD5
|
||||||
, "md5"
|
"md5",
|
||||||
#endif
|
#endif
|
||||||
#ifndef NO_SHA
|
#ifndef NO_SHA
|
||||||
, "sha"
|
"sha",
|
||||||
#endif
|
#endif
|
||||||
#ifndef NO_SHA256
|
#ifndef NO_SHA256
|
||||||
, "sha256"
|
"sha256",
|
||||||
#endif
|
#endif
|
||||||
#ifdef WOLFSSL_SHA384
|
#ifdef WOLFSSL_SHA384
|
||||||
, "sha384"
|
"sha384",
|
||||||
#endif
|
#endif
|
||||||
#ifdef WOLFSSL_SHA512
|
#ifdef WOLFSSL_SHA512
|
||||||
, "sha512"
|
"sha512",
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_BLAKE2
|
#ifdef HAVE_BLAKE2
|
||||||
, "blake2b"
|
"blake2b",
|
||||||
#endif
|
#endif
|
||||||
|
NULL /* terminal argument (also stops us from having an empty list) */
|
||||||
};
|
};
|
||||||
|
size_t algsSz = sizeof(algs) / sizeof(algs[0]) - 1; /* -1 to ignore NULL */
|
||||||
|
|
||||||
int option[sizeof(algs)/sizeof(algs[0])] = {0};/* acceptable options */
|
/* acceptable options */
|
||||||
int optionCheck = 0; /* acceptable option check */
|
int option[sizeof(algs) / sizeof(algs[0])] = {0};
|
||||||
|
|
||||||
for (i = 2; i < argc; i++) {
|
/* acceptable option check */
|
||||||
if (XSTRNCMP(argv[i], "-help", 5) == 0 || XSTRNCMP(argv[i], "-h", 2)
|
int optionCheck = 0;
|
||||||
== 0) {
|
|
||||||
/* help checking */
|
ret = wolfCLU_checkForArg("-h", 2, argc, argv);
|
||||||
|
if (ret > 0) {
|
||||||
wolfCLU_benchHelp();
|
wolfCLU_benchHelp();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (j = 0; j < (int) sizeof(algs)/(int) sizeof(algs[0]); j++) {
|
|
||||||
/* checks for individual tests in the arguments */
|
ret = wolfCLU_checkForArg("-time", 5, argc, argv);
|
||||||
if (XSTRNCMP(argv[i], algs[j], XSTRLEN(argv[i])) == 0) {
|
if (ret > 0) {
|
||||||
option[j] = 1;
|
|
||||||
optionCheck = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (XSTRNCMP(argv[i], "-time", 5) == 0 && argv[i+1] != NULL) {
|
|
||||||
/* time for each test in seconds */
|
/* time for each test in seconds */
|
||||||
time = atoi(argv[i+1]);
|
time = atoi(argv[ret+1]);
|
||||||
if (time < 1 || time > 10) {
|
if (time < 1 || time > 10) {
|
||||||
printf("Invalid time, must be between 1-10. Using default"
|
printf("Invalid time, must be between 1-10. Using default"
|
||||||
" of three seconds.\n");
|
" of three seconds.\n");
|
||||||
time = 3;
|
time = 3;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
if (XSTRNCMP(argv[i], "-all", 4) == 0) {
|
|
||||||
|
ret = wolfCLU_checkForArg("-all", 4, argc, argv);
|
||||||
|
if (ret > 0) {
|
||||||
/* perform all available tests */
|
/* perform all available tests */
|
||||||
for (j = 0; j < (int) sizeof(algs)/(int) sizeof(algs[0]); j++) {
|
for (j = 0; j < (int)algsSz; j++) {
|
||||||
option[j] = 1;
|
option[j] = 1;
|
||||||
optionCheck = 1;
|
optionCheck = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* pull as many of the algorithms out of the argv as posible */
|
||||||
|
for (i = 0; i < (int)algsSz; ++i) {
|
||||||
|
ret = wolfCLU_checkForArg(algs[i], XSTRLEN(algs[i]), argc, argv);
|
||||||
|
if (ret > 0) {
|
||||||
|
option[i] = 1;
|
||||||
|
optionCheck = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (optionCheck != 1) {
|
if (optionCheck != 1) {
|
||||||
/* help checking */
|
/* help checking */
|
||||||
wolfCLU_help();
|
wolfCLU_help();
|
||||||
|
|
|
@ -63,6 +63,13 @@ int wolfCLU_benchmark(int timer, int* option)
|
||||||
wc_InitRng(&rng);
|
wc_InitRng(&rng);
|
||||||
|
|
||||||
signal(SIGALRM, wolfCLU_stop);
|
signal(SIGALRM, wolfCLU_stop);
|
||||||
|
|
||||||
|
/* @fragile:
|
||||||
|
* this function assumes that it perfectly knows the order and length of
|
||||||
|
* the option array in clu_src/benchmark/clu_bench_setup.c. Looping over a
|
||||||
|
* switch on an enum would be much more robust.
|
||||||
|
*/
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
#ifndef NO_AES
|
#ifndef NO_AES
|
||||||
/* aes test */
|
/* aes test */
|
||||||
|
|
Loading…
Reference in New Issue