| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <getopt.h> |
| 21 |
#include <string.h> |
| 22 |
#include "cryptoperf.h" |
| 23 |
|
| 24 |
#define MAXNAMELEN 30 |
| 25 |
struct test_array { |
| 26 |
struct cp_test *array; |
| 27 |
size_t entries; |
| 28 |
}; |
| 29 |
|
| 30 |
static struct test_array tests[4]; |
| 31 |
|
| 32 |
static void print_tests(struct test_array *tests, int print) |
| 33 |
{ |
| 34 |
size_t i = 0; |
| 35 |
|
| 36 |
if (!print) |
| 37 |
return; |
| 38 |
|
| 39 |
for (i = 0; i < tests->entries; i++) { |
| 40 |
printf("%-9s | %-35s | %s | %s\n", tests->array[i].type, |
| 41 |
tests->array[i].testname, |
| 42 |
tests->array[i].driver_name, |
| 43 |
tests->array[i].enc ? "e" : "d"); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
static void register_tests(int print) |
| 48 |
{ |
| 49 |
cp_hash_register(&tests[0].array, &tests[0].entries); |
| 50 |
print_tests(&tests[0], print); |
| 51 |
|
| 52 |
cp_skcipher_register(&tests[1].array, &tests[1].entries); |
| 53 |
print_tests(&tests[1], print); |
| 54 |
|
| 55 |
cp_rng_register(&tests[2].array, &tests[2].entries); |
| 56 |
print_tests(&tests[2], print); |
| 57 |
|
| 58 |
cp_aead_register(&tests[3].array, &tests[3].entries); |
| 59 |
print_tests(&tests[3], print); |
| 60 |
} |
| 61 |
|
| 62 |
static int exec_all_tests(struct test_array *tests, |
| 63 |
struct cp_test_param *test_params, int raw) |
| 64 |
{ |
| 65 |
size_t i; |
| 66 |
|
| 67 |
for (i = 0; i < tests->entries; i++) { |
| 68 |
struct cp_test *test = &tests->array[i]; |
| 69 |
char *out = NULL; |
| 70 |
|
| 71 |
test->test_params = test_params; |
| 72 |
|
| 73 |
|
| 74 |
if (cp_exec_test(test)) |
| 75 |
continue; |
| 76 |
out = cp_print_status(test, raw); |
| 77 |
if (!out) |
| 78 |
return -ENOMEM; |
| 79 |
printf("%s\n", out); |
| 80 |
free(out); |
| 81 |
} |
| 82 |
|
| 83 |
return 0; |
| 84 |
} |
| 85 |
|
| 86 |
static int find_test(const char *name, struct test_array *tests, int start, |
| 87 |
struct cp_test **test) |
| 88 |
{ |
| 89 |
int i = start; |
| 90 |
|
| 91 |
if (i < 0) |
| 92 |
i = 0; |
| 93 |
|
| 94 |
for (; (unsigned int)i < tests->entries; i++) { |
| 95 |
if (!strncmp(tests->array[i].driver_name, name, strlen(name)) || |
| 96 |
!strncmp(tests->array[i].testname, name, strlen(name)) || |
| 97 |
!strncmp(tests->array[i].type, name, strlen(name))) { |
| 98 |
*test = &tests->array[i]; |
| 99 |
return i; |
| 100 |
} |
| 101 |
} |
| 102 |
return -EFAULT; |
| 103 |
} |
| 104 |
|
| 105 |
static int exec_subset_test(const char *name, int raw, |
| 106 |
struct cp_test_param *test_params) |
| 107 |
{ |
| 108 |
struct cp_test *test = NULL; |
| 109 |
int i = 0; |
| 110 |
|
| 111 |
for (i = 0; i < 4; i++) { |
| 112 |
int ret = 0; |
| 113 |
|
| 114 |
while (1) { |
| 115 |
char *out = NULL; |
| 116 |
|
| 117 |
ret = find_test(name, &tests[i], ret, &test); |
| 118 |
if (ret < 0) |
| 119 |
break; |
| 120 |
ret++; |
| 121 |
|
| 122 |
test->test_params = test_params; |
| 123 |
|
| 124 |
if (cp_exec_test(test)) |
| 125 |
return -EFAULT; |
| 126 |
out = cp_print_status(test, raw); |
| 127 |
if (!out) |
| 128 |
return -ENOMEM; |
| 129 |
printf("%s\n", out); |
| 130 |
free(out); |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
return 0; |
| 135 |
} |
| 136 |
|
| 137 |
static void usage(void) |
| 138 |
{ |
| 139 |
char version[20]; |
| 140 |
unsigned int ver = kcapi_version(); |
| 141 |
|
| 142 |
memset(version, 0, 20); |
| 143 |
kcapi_versionstring(version, 20); |
| 144 |
|
| 145 |
fprintf(stderr, "\nAF_ALG Kernel Crypto API Speed Test\n"); |
| 146 |
fprintf(stderr, "\nKernel Crypto API interface library version: %s\n", version); |
| 147 |
fprintf(stderr, "Reported numeric version number %u\n\n", ver); |
| 148 |
fprintf(stderr, "Usage:\n"); |
| 149 |
fprintf(stderr, "\t-a --all\tExecute all ciphers\n"); |
| 150 |
fprintf(stderr, "\t-l --list\tList available ciphers\n"); |
| 151 |
fprintf(stderr, "\t-c --cipher\tCipher/cipher type to test\n"); |
| 152 |
fprintf(stderr, "\t-t --time\tExecution time in seconds\n"); |
| 153 |
fprintf(stderr, "\t-b --blocks\tNumber of blocks to process\n"); |
| 154 |
fprintf(stderr, "\t-r --raw\tPrint out raw numbers for postprocessing\n"); |
| 155 |
fprintf(stderr, "\t-v --vmsplice\tUse vmsplice kernel interface\n"); |
| 156 |
fprintf(stderr, "\t-s --sendmsg\tUse sendmsg kernel interface\n"); |
| 157 |
fprintf(stderr, "\t-o --aio\tUse AIO interface with given number of IOVECs\n"); |
| 158 |
} |
| 159 |
|
| 160 |
int main(int argc, char *argv[]) |
| 161 |
{ |
| 162 |
int c = 0; |
| 163 |
struct cp_test_param test_params; |
| 164 |
char *cipher = NULL; |
| 165 |
int raw = 0; |
| 166 |
int ret = 1; |
| 167 |
int i = 0; |
| 168 |
int alltests = 0; |
| 169 |
|
| 170 |
memset(&test_params, 0, sizeof(test_params)); |
| 171 |
|
| 172 |
test_params.len = 1; |
| 173 |
test_params.accesstype = KCAPI_ACCESS_HEURISTIC; |
| 174 |
|
| 175 |
register_tests(0); |
| 176 |
|
| 177 |
while(1) |
| 178 |
{ |
| 179 |
int opt_index = 0; |
| 180 |
static struct option opts[] = |
| 181 |
{ |
| 182 |
{"all", 0, 0, 'a'}, |
| 183 |
{"list", 0, 0, 'l'}, |
| 184 |
{"cipher", 1, 0, 'c'}, |
| 185 |
{"time", 1, 0, 't'}, |
| 186 |
{"blocks", 1, 0, 'b'}, |
| 187 |
{"raw", 0, 0, 'r'}, |
| 188 |
{"sendmsg", 0, 0, 's'}, |
| 189 |
{"vmsplice", 0, 0, 'v'}, |
| 190 |
{"aio", 1, 0, 'o'}, |
| 191 |
{0, 0, 0, 0} |
| 192 |
}; |
| 193 |
c = getopt_long(argc, argv, "alc:t:b:rsvo:", opts, &opt_index); |
| 194 |
if(-1 == c) |
| 195 |
break; |
| 196 |
switch(c) |
| 197 |
{ |
| 198 |
case 'a': |
| 199 |
alltests = 1; |
| 200 |
break; |
| 201 |
case 'l': |
| 202 |
for (i = 0; i < 4; i++) |
| 203 |
print_tests(&tests[i], 1); |
| 204 |
return 0; |
| 205 |
case 'c': |
| 206 |
free(cipher); |
| 207 |
cipher = strndup(optarg, 50); |
| 208 |
break; |
| 209 |
case 't': |
| 210 |
test_params.exectime = (unsigned int)atoi(optarg); |
| 211 |
break; |
| 212 |
case 'b': |
| 213 |
test_params.len = (unsigned int)atoi(optarg); |
| 214 |
break; |
| 215 |
case 'r': |
| 216 |
raw = 1; |
| 217 |
break; |
| 218 |
case 'v': |
| 219 |
test_params.accesstype = KCAPI_ACCESS_VMSPLICE; |
| 220 |
break; |
| 221 |
case 's': |
| 222 |
test_params.accesstype = KCAPI_ACCESS_SENDMSG; |
| 223 |
break; |
| 224 |
case 'o': |
| 225 |
test_params.aio = (unsigned int)atoi(optarg); |
| 226 |
break; |
| 227 |
|
| 228 |
default: |
| 229 |
usage(); |
| 230 |
goto out; |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
if (alltests) { |
| 235 |
for (i = 0; i < 4; i++) |
| 236 |
exec_all_tests(&tests[i], &test_params, raw); |
| 237 |
return 0; |
| 238 |
} |
| 239 |
|
| 240 |
if (!cipher) { |
| 241 |
usage(); |
| 242 |
goto out; |
| 243 |
} |
| 244 |
|
| 245 |
ret = exec_subset_test(cipher, raw, &test_params); |
| 246 |
|
| 247 |
out: |
| 248 |
free(cipher); |
| 249 |
return ret; |
| 250 |
} |