diff options
author | Chunrong Guo <chunrong.guo@nxp.com> | 2017-04-18 15:11:50 +0800 |
---|---|---|
committer | Otavio Salvador <otavio@ossystems.com.br> | 2017-05-02 17:54:58 -0300 |
commit | e756964ac2595d880304f227dec7bdb424d7d974 (patch) | |
tree | 28c067a5652216278a92e39144d48ac95f0e8f12 /recipes-kernel/cryptodev/sdk_patches/0081-add-sync-speed-tests-with-the-same-format-as-async-o.patch | |
parent | cfb3ddaaaa78204ef5281c8627eed08f4f7e3f09 (diff) | |
download | meta-freescale-e756964ac2595d880304f227dec7bdb424d7d974.tar.gz |
cryptodev: update to 6c2b61c
**include the following changes
6c2b61c - update copyright notes
f79d523 - fix: reset finish condition before test start
e8f7a91 - Merge remote-tracking branch 'upstream/master'
6818263 - Fix ablkcipher algorithms usage in v4.8+ kernels
26e167f - zc: Use the power of #elif
e49fe25 - adjust to API changes in kernel >=4.10
2b29be8 - adjust to API changes in kernel >=4.10
c3afb40 - add support for rsa speed tests
c9b7a80 - close the session after every test
ba49470 - add support for authenc(hmac(sha1), cbc(aes)) speed tests
690cd62 - Merge branch 'master' into hpe2016
5adf04e - Merge remote-tracking branch 'upstream/master'
840c7ba - remove not used variable
2dbbb23 - do more strict code checking to avoid maintenance issues
88223e4 - avoid implicit conversion between signed and unsigned char
8db6905 - use buf_align macro to reduce code duplication
b6d0e0f - rename header file to clarify purpose
1fd6062 - fix warnings of "implicit declaration of function" in async_speed
ff3c8ab - remove not used local variables
25a1276 - fix incorrect return code in case of error from openssl_cioccrypt
e7ef4ea - Merge pull request #17 from michaelweiser/gup_flags
99c6d21 - fix ignored SIGALRM signals on some platforms
71975fa - setting KERNEL_DIR is not necessary to build tests
a96ff97 - fix issues with install target
07748d3 - Merge branch 'master' into hpe2016
cc89148 - Fix ablkcipher algorithms usage in v4.8+ kernels
4d6e4fb - Merge remote-tracking branch 'upstream/master'
f126e48 - Adjust to another change in the user page API
4257fce - add -async option to run_crypto_tests.sh
f953164 - merge sync and async benchmarks into a single program
e7af57b - add % to cpu idle for convenience
1883c95 - add a wrapper script for running all tests
998b66b - add notes about configured limits in SEC driver
b1a35f3 - fix ignored SIGALRM signals on some platforms
b754517 - use the same algorithm names in sync_speed as in async_speed
8baefa4 - force LC_TIME value to avoid mpstat not using ISO8601 format
d0978b5 - add sync speed tests with the same format as async ones
15d890b - graceful exit if cryptodev is not built with ASYNC flags
9a595bf - fix typo, use consistent spacing
9461878 - remove output line because it does not add clarity to the results
b09c17f - the C standard used by cryptodev is C90 with GNU extensions
447808d - exit early if cryptodev tests are not installed
493afd3 - fix incorrect handling of error cases...
e0d2c88 - make default output tabular
abc007a - really fix (again...) the mpstat issue
2696cd5 - use $(...) instead of `...` for consistency
e8fb004 - fix the scale of the runtime value
119151b - remove old results to avoid incorrect reports
71ac3d5 - fix the reported unit
8c47a0c - setting KERNEL_DIR is not necessary to build tests
182b307 - fix issues with install target
5021828 - do more strict code checking to avoid maintenance issues
ab239d7 - return error code of the test if there is one
b5228f2 - remove not used local variables
90d67ce - avoid implicit conversion between signed and unsigned char
4b442ca - fix build warnings on implicit function declarations
2821b92 - add a little space in the output for clarity
9d0ef05 - more precision in running mpstat
0180e2b - fix some issues with parsing mpstat output
4257fce - add -async option to run_crypto_tests.sh
f953164 - merge sync and async benchmarks into a single program
e7af57b - add % to cpu idle for convenience
7d7a733 - sanity check on /dev/crypto availability
137c0c4 - gracefull stop for async speed tests
600eb70 - fix: set min value when allocating alligned memory buffers
18408c9 - add multithreaded wrapper for async speed test
854cc84 - rename algorithm names for clarity
216f235 - honor the -m flag in async_speed
1023ede - add flag to report in a machine friendly format
219a8b4 - enable async code by default
9def784 - Merge remote-tracking branch 'radualexe/new_tests`
149dc1c - add basic optargs support for async_speed test
9595499 - add support for crc32c hash sync speed test
83e3840 - add support for aes-256-xts sync speed test
fff72ae - add support for sha2-256 hash async speed test
b961800 - add support for sha1 hash async speed test
fea5006 - add support for crc32c hash async speed test
8768fad - add aes-256-xts support for async speed test
Signed-off-by: Chunrong Guo <B40290@freescale.com>
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Diffstat (limited to 'recipes-kernel/cryptodev/sdk_patches/0081-add-sync-speed-tests-with-the-same-format-as-async-o.patch')
-rw-r--r-- | recipes-kernel/cryptodev/sdk_patches/0081-add-sync-speed-tests-with-the-same-format-as-async-o.patch | 718 |
1 files changed, 718 insertions, 0 deletions
diff --git a/recipes-kernel/cryptodev/sdk_patches/0081-add-sync-speed-tests-with-the-same-format-as-async-o.patch b/recipes-kernel/cryptodev/sdk_patches/0081-add-sync-speed-tests-with-the-same-format-as-async-o.patch new file mode 100644 index 00000000..5e8893b6 --- /dev/null +++ b/recipes-kernel/cryptodev/sdk_patches/0081-add-sync-speed-tests-with-the-same-format-as-async-o.patch | |||
@@ -0,0 +1,718 @@ | |||
1 | From b13160357e683b9d42ba513433b4c09456a8332b Mon Sep 17 00:00:00 2001 | ||
2 | From: Alexe Radu <radu.alexe@nxp.com> | ||
3 | Date: Fri, 28 Oct 2016 13:39:50 +0300 | ||
4 | Subject: [PATCH 081/104] add sync speed tests with the same format as async | ||
5 | ones | ||
6 | |||
7 | The file speed.c was removed because has the same functionality | ||
8 | as sync_speed.c | ||
9 | |||
10 | Signed-off-by: Alexe Radu <radu.alexe@nxp.com> | ||
11 | --- | ||
12 | tests/Makefile | 4 +- | ||
13 | tests/speed.c | 265 ----------------------------------- | ||
14 | tests/sync_speed.c | 399 +++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
15 | 3 files changed, 401 insertions(+), 267 deletions(-) | ||
16 | delete mode 100644 tests/speed.c | ||
17 | create mode 100644 tests/sync_speed.c | ||
18 | |||
19 | diff --git a/tests/Makefile b/tests/Makefile | ||
20 | index 23d67f9..400fb7a 100644 | ||
21 | --- a/tests/Makefile | ||
22 | +++ b/tests/Makefile | ||
23 | @@ -3,14 +3,14 @@ CFLAGS += -I.. $(CRYPTODEV_CFLAGS) | ||
24 | |||
25 | comp_progs := cipher_comp hash_comp hmac_comp | ||
26 | |||
27 | -hostprogs := cipher cipher-aead hmac speed async_cipher async_hmac \ | ||
28 | +hostprogs := cipher cipher-aead hmac sync_speed async_cipher async_hmac \ | ||
29 | async_speed sha_speed hashcrypt_speed fullspeed cipher-gcm \ | ||
30 | cipher-aead-srtp $(comp_progs) | ||
31 | |||
32 | example-cipher-objs := cipher.o | ||
33 | example-cipher-aead-objs := cipher-aead.o | ||
34 | example-hmac-objs := hmac.o | ||
35 | -example-speed-objs := speed.c | ||
36 | +example-speed-objs := sync_speed.o | ||
37 | example-fullspeed-objs := fullspeed.c | ||
38 | example-sha-speed-objs := sha_speed.c | ||
39 | example-async-cipher-objs := async_cipher.o | ||
40 | diff --git a/tests/speed.c b/tests/speed.c | ||
41 | deleted file mode 100644 | ||
42 | index 0e2bbc3..0000000 | ||
43 | --- a/tests/speed.c | ||
44 | +++ /dev/null | ||
45 | @@ -1,265 +0,0 @@ | ||
46 | -/* cryptodev_test - simple benchmark tool for cryptodev | ||
47 | - * | ||
48 | - * Copyright (C) 2010 by Phil Sutter <phil.sutter@viprinet.com> | ||
49 | - * | ||
50 | - * This program is free software; you can redistribute it and/or modify | ||
51 | - * it under the terms of the GNU General Public License as published by | ||
52 | - * the Free Software Foundation; either version 2 of the License, or | ||
53 | - * (at your option) any later version. | ||
54 | - * | ||
55 | - * This program is distributed in the hope that it will be useful, | ||
56 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
57 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
58 | - * GNU General Public License for more details. | ||
59 | - * | ||
60 | - * You should have received a copy of the GNU General Public License | ||
61 | - * along with this program; if not, write to the Free Software | ||
62 | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
63 | - */ | ||
64 | -#include <fcntl.h> | ||
65 | -#include <stdio.h> | ||
66 | -#include <stdlib.h> | ||
67 | -#include <string.h> | ||
68 | -#include <sys/ioctl.h> | ||
69 | -#include <sys/time.h> | ||
70 | -#include <sys/types.h> | ||
71 | -#include <signal.h> | ||
72 | -#include <unistd.h> | ||
73 | -#include <stdint.h> | ||
74 | - | ||
75 | -#include <crypto/cryptodev.h> | ||
76 | - | ||
77 | -static int si = 1; /* SI by default */ | ||
78 | - | ||
79 | -static double udifftimeval(struct timeval start, struct timeval end) | ||
80 | -{ | ||
81 | - return (double)(end.tv_usec - start.tv_usec) + | ||
82 | - (double)(end.tv_sec - start.tv_sec) * 1000 * 1000; | ||
83 | -} | ||
84 | - | ||
85 | -static int must_finish = 0; | ||
86 | - | ||
87 | -static void alarm_handler(int signo) | ||
88 | -{ | ||
89 | - must_finish = 1; | ||
90 | -} | ||
91 | - | ||
92 | -static char *units[] = { "", "Ki", "Mi", "Gi", "Ti", 0}; | ||
93 | -static char *si_units[] = { "", "K", "M", "G", "T", 0}; | ||
94 | - | ||
95 | -static void value2human(int si, double bytes, double time, double* data, double* speed,char* metric) | ||
96 | -{ | ||
97 | - int unit = 0; | ||
98 | - | ||
99 | - *data = bytes; | ||
100 | - | ||
101 | - if (si) { | ||
102 | - while (*data > 1000 && si_units[unit + 1]) { | ||
103 | - *data /= 1000; | ||
104 | - unit++; | ||
105 | - } | ||
106 | - *speed = *data / time; | ||
107 | - sprintf(metric, "%sB", si_units[unit]); | ||
108 | - } else { | ||
109 | - while (*data > 1024 && units[unit + 1]) { | ||
110 | - *data /= 1024; | ||
111 | - unit++; | ||
112 | - } | ||
113 | - *speed = *data / time; | ||
114 | - sprintf(metric, "%sB", units[unit]); | ||
115 | - } | ||
116 | -} | ||
117 | - | ||
118 | -#define MAX(x,y) ((x)>(y)?(x):(y)) | ||
119 | - | ||
120 | -int encrypt_data(struct session_op *sess, int fdc, int chunksize, int alignmask) | ||
121 | -{ | ||
122 | - struct crypt_op cop; | ||
123 | - char *buffer, iv[32]; | ||
124 | - uint8_t mac[HASH_MAX_LEN]; | ||
125 | - static int val = 23; | ||
126 | - struct timeval start, end; | ||
127 | - double total = 0; | ||
128 | - double secs, ddata, dspeed; | ||
129 | - char metric[16]; | ||
130 | - int min_alignmask = sizeof(void*) - 1; | ||
131 | - | ||
132 | - if (alignmask) { | ||
133 | - alignmask = ((alignmask < min_alignmask) ? min_alignmask : alignmask); | ||
134 | - if (posix_memalign((void **)&buffer, MAX(alignmask + 1, sizeof(void*)), chunksize)) { | ||
135 | - printf("posix_memalign() failed! (mask %x, size: %d)\n", alignmask+1, chunksize); | ||
136 | - return 1; | ||
137 | - } | ||
138 | - } else { | ||
139 | - if (!(buffer = malloc(chunksize))) { | ||
140 | - perror("malloc()"); | ||
141 | - return 1; | ||
142 | - } | ||
143 | - } | ||
144 | - | ||
145 | - memset(iv, 0x23, 32); | ||
146 | - | ||
147 | - printf("\tEncrypting in chunks of %d bytes: ", chunksize); | ||
148 | - fflush(stdout); | ||
149 | - | ||
150 | - memset(buffer, val++, chunksize); | ||
151 | - | ||
152 | - must_finish = 0; | ||
153 | - alarm(5); | ||
154 | - | ||
155 | - gettimeofday(&start, NULL); | ||
156 | - do { | ||
157 | - memset(&cop, 0, sizeof(cop)); | ||
158 | - cop.ses = sess->ses; | ||
159 | - cop.len = chunksize; | ||
160 | - cop.iv = (unsigned char *)iv; | ||
161 | - cop.op = COP_ENCRYPT; | ||
162 | - cop.src = cop.dst = (unsigned char *)buffer; | ||
163 | - cop.mac = mac; | ||
164 | - | ||
165 | - if (ioctl(fdc, CIOCCRYPT, &cop)) { | ||
166 | - perror("ioctl(CIOCCRYPT)"); | ||
167 | - return 1; | ||
168 | - } | ||
169 | - total+=chunksize; | ||
170 | - } while(must_finish==0); | ||
171 | - gettimeofday(&end, NULL); | ||
172 | - | ||
173 | - secs = udifftimeval(start, end)/ 1000000.0; | ||
174 | - | ||
175 | - value2human(si, total, secs, &ddata, &dspeed, metric); | ||
176 | - printf ("done. %.2f %s in %.2f secs: ", ddata, metric, secs); | ||
177 | - printf ("%.2f %s/sec\n", dspeed, metric); | ||
178 | - | ||
179 | - free(buffer); | ||
180 | - return 0; | ||
181 | -} | ||
182 | - | ||
183 | -int main(int argc, char** argv) | ||
184 | -{ | ||
185 | - int fd, i, fdc = -1, alignmask = 0; | ||
186 | - struct session_op sess; | ||
187 | -#ifdef CIOCGSESSINFO | ||
188 | - struct session_info_op siop; | ||
189 | -#endif | ||
190 | - char keybuf[32]; | ||
191 | - | ||
192 | - signal(SIGALRM, alarm_handler); | ||
193 | - | ||
194 | - if (argc > 1) { | ||
195 | - if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) { | ||
196 | - printf("Usage: speed [--kib]\n"); | ||
197 | - exit(0); | ||
198 | - } | ||
199 | - if (strcmp(argv[1], "--kib") == 0) { | ||
200 | - si = 0; | ||
201 | - } | ||
202 | - } | ||
203 | - | ||
204 | - if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0) { | ||
205 | - perror("open()"); | ||
206 | - return 1; | ||
207 | - } | ||
208 | - if (ioctl(fd, CRIOGET, &fdc)) { | ||
209 | - perror("ioctl(CRIOGET)"); | ||
210 | - return 1; | ||
211 | - } | ||
212 | - | ||
213 | - fprintf(stderr, "Testing NULL cipher: \n"); | ||
214 | - memset(&sess, 0, sizeof(sess)); | ||
215 | - sess.cipher = CRYPTO_NULL; | ||
216 | - sess.keylen = 0; | ||
217 | - sess.key = (unsigned char *)keybuf; | ||
218 | - if (ioctl(fdc, CIOCGSESSION, &sess)) { | ||
219 | - perror("ioctl(CIOCGSESSION)"); | ||
220 | - return 1; | ||
221 | - } | ||
222 | -#ifdef CIOCGSESSINFO | ||
223 | - siop.ses = sess.ses; | ||
224 | - if (ioctl(fdc, CIOCGSESSINFO, &siop)) { | ||
225 | - perror("ioctl(CIOCGSESSINFO)"); | ||
226 | - return 1; | ||
227 | - } | ||
228 | - alignmask = siop.alignmask; | ||
229 | -#endif | ||
230 | - | ||
231 | - for (i = 512; i <= (64 * 1024); i *= 2) { | ||
232 | - if (encrypt_data(&sess, fdc, i, alignmask)) | ||
233 | - break; | ||
234 | - } | ||
235 | - | ||
236 | - fprintf(stderr, "\nTesting AES-128-CBC cipher: \n"); | ||
237 | - memset(&sess, 0, sizeof(sess)); | ||
238 | - sess.cipher = CRYPTO_AES_CBC; | ||
239 | - sess.keylen = 16; | ||
240 | - memset(keybuf, 0x42, 16); | ||
241 | - sess.key = (unsigned char *)keybuf; | ||
242 | - if (ioctl(fdc, CIOCGSESSION, &sess)) { | ||
243 | - perror("ioctl(CIOCGSESSION)"); | ||
244 | - return 1; | ||
245 | - } | ||
246 | -#ifdef CIOCGSESSINFO | ||
247 | - siop.ses = sess.ses; | ||
248 | - if (ioctl(fdc, CIOCGSESSINFO, &siop)) { | ||
249 | - perror("ioctl(CIOCGSESSINFO)"); | ||
250 | - return 1; | ||
251 | - } | ||
252 | - alignmask = siop.alignmask; | ||
253 | -#endif | ||
254 | - | ||
255 | - for (i = 512; i <= (64 * 1024); i *= 2) { | ||
256 | - if (encrypt_data(&sess, fdc, i, alignmask)) | ||
257 | - break; | ||
258 | - } | ||
259 | - | ||
260 | - fprintf(stderr, "\nTesting AES-256-XTS cipher: \n"); | ||
261 | - memset(&sess, 0, sizeof(sess)); | ||
262 | - sess.cipher = CRYPTO_AES_XTS; | ||
263 | - sess.keylen = 32; | ||
264 | - memset(keybuf, 0x42, sess.keylen); | ||
265 | - sess.key = (unsigned char *)keybuf; | ||
266 | - if (ioctl(fdc, CIOCGSESSION, &sess)) { | ||
267 | - perror("ioctl(CIOCGSESSION)"); | ||
268 | - return 1; | ||
269 | - } | ||
270 | -#ifdef CIOCGSESSINFO | ||
271 | - siop.ses = sess.ses; | ||
272 | - if (ioctl(fdc, CIOCGSESSINFO, &siop)) { | ||
273 | - perror("ioctl(CIOCGSESSINFO)"); | ||
274 | - return 1; | ||
275 | - } | ||
276 | - alignmask = siop.alignmask; | ||
277 | -#endif | ||
278 | - | ||
279 | - for (i = 512; i <= (64 * 1024); i *= 2) { | ||
280 | - if (encrypt_data(&sess, fdc, i, alignmask)) | ||
281 | - break; | ||
282 | - } | ||
283 | - | ||
284 | - fprintf(stderr, "\nTesting CRC32C hash: \n"); | ||
285 | - memset(&sess, 0, sizeof(sess)); | ||
286 | - sess.mac = CRYPTO_CRC32C; | ||
287 | - if (ioctl(fdc, CIOCGSESSION, &sess)) { | ||
288 | - perror("ioctl(CIOCGSESSION)"); | ||
289 | - return 1; | ||
290 | - } | ||
291 | -#ifdef CIOCGSESSINFO | ||
292 | - siop.ses = sess.ses; | ||
293 | - if (ioctl(fdc, CIOCGSESSINFO, &siop)) { | ||
294 | - perror("ioctl(CIOCGSESSINFO)"); | ||
295 | - return 1; | ||
296 | - } | ||
297 | - printf("requested hash CRYPTO_CRC32C, got %s with driver %s\n", | ||
298 | - siop.hash_info.cra_name, siop.hash_info.cra_driver_name); | ||
299 | - alignmask = siop.alignmask; | ||
300 | -#endif | ||
301 | - | ||
302 | - for (i = 512; i <= (64 * 1024); i *= 2) { | ||
303 | - if (encrypt_data(&sess, fdc, i, alignmask)) | ||
304 | - break; | ||
305 | - } | ||
306 | - | ||
307 | - close(fdc); | ||
308 | - close(fd); | ||
309 | - return 0; | ||
310 | -} | ||
311 | diff --git a/tests/sync_speed.c b/tests/sync_speed.c | ||
312 | new file mode 100644 | ||
313 | index 0000000..b0cb9ad | ||
314 | --- /dev/null | ||
315 | +++ b/tests/sync_speed.c | ||
316 | @@ -0,0 +1,399 @@ | ||
317 | +/* cryptodev_test - simple benchmark tool for cryptodev | ||
318 | + * | ||
319 | + * Copyright (C) 2010 by Phil Sutter <phil.sutter@viprinet.com> | ||
320 | + * | ||
321 | + * This program is free software; you can redistribute it and/or modify | ||
322 | + * it under the terms of the GNU General Public License as published by | ||
323 | + * the Free Software Foundation; either version 2 of the License, or | ||
324 | + * (at your option) any later version. | ||
325 | + * | ||
326 | + * This program is distributed in the hope that it will be useful, | ||
327 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
328 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
329 | + * GNU General Public License for more details. | ||
330 | + * | ||
331 | + * You should have received a copy of the GNU General Public License | ||
332 | + * along with this program; if not, write to the Free Software | ||
333 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
334 | + */ | ||
335 | +#include <errno.h> | ||
336 | +#include <fcntl.h> | ||
337 | +#include <poll.h> | ||
338 | +#include <stdio.h> | ||
339 | +#include <stdlib.h> | ||
340 | +#include <string.h> | ||
341 | +#include <sys/ioctl.h> | ||
342 | +#include <sys/time.h> | ||
343 | +#include <sys/types.h> | ||
344 | +#include <signal.h> | ||
345 | +#include <crypto/cryptodev.h> | ||
346 | +#include <stdbool.h> | ||
347 | +#include <unistd.h> | ||
348 | + | ||
349 | +struct test_params { | ||
350 | + bool tflag; | ||
351 | + bool nflag; | ||
352 | + int tvalue; | ||
353 | + int nvalue; | ||
354 | +}; | ||
355 | + | ||
356 | +const char usage_str[] = "Usage: %s [OPTION]... <cipher>|<hash>\n" | ||
357 | + "Run benchmark test for cipher or hash\n\n" | ||
358 | + " -t <secs>\t" "time to run each test (default 10 secs)\n" | ||
359 | + " -n <bytes>\t" "size of the test buffer\n" | ||
360 | + " -h\t\t" "show this help\n" | ||
361 | +; | ||
362 | + | ||
363 | +int run_null(int fdc, struct test_params tp); | ||
364 | +int run_aes_cbc(int fdc, struct test_params tp); | ||
365 | +int run_aes_xts(int fdc, struct test_params tp); | ||
366 | +int run_crc32c(int fdc, struct test_params tp); | ||
367 | +int run_sha1(int fdc, struct test_params tp); | ||
368 | +int run_sha256(int fdc, struct test_params tp); | ||
369 | +int get_alignmask(int fdc, struct session_op *sess); | ||
370 | + | ||
371 | +#define ALG_COUNT 6 | ||
372 | +struct { | ||
373 | + char *name; | ||
374 | + int (*func)(int, struct test_params); | ||
375 | +} ciphers[ALG_COUNT] = { | ||
376 | + {"null", run_null}, | ||
377 | + {"aes-cbc", run_aes_cbc}, | ||
378 | + {"aes-xts", run_aes_xts}, | ||
379 | + {"crc32c", run_crc32c}, | ||
380 | + {"sha1", run_sha1}, | ||
381 | + {"sha256", run_sha256}, | ||
382 | +}; | ||
383 | + | ||
384 | +static double udifftimeval(struct timeval start, struct timeval end) | ||
385 | +{ | ||
386 | + return (double)(end.tv_usec - start.tv_usec) + | ||
387 | + (double)(end.tv_sec - start.tv_sec) * 1000 * 1000; | ||
388 | +} | ||
389 | + | ||
390 | +static int must_finish = 0; | ||
391 | +static int must_exit = 0; | ||
392 | + | ||
393 | +static void alarm_handler(int signo) | ||
394 | +{ | ||
395 | + must_finish = 1; | ||
396 | +} | ||
397 | + | ||
398 | +static void exit_handler(int signo) | ||
399 | +{ | ||
400 | + must_exit = 1; | ||
401 | + printf("\nexit requested by user through ctrl+c \n"); | ||
402 | +} | ||
403 | + | ||
404 | +static char *units[] = { "", "Ki", "Mi", "Gi", "Ti", 0}; | ||
405 | + | ||
406 | +static void value2human(double bytes, double time, double* data, double* speed,char* metric) | ||
407 | +{ | ||
408 | + int unit = 0; | ||
409 | + | ||
410 | + *data = bytes; | ||
411 | + while (*data > 1024 && units[unit + 1]) { | ||
412 | + *data /= 1024; | ||
413 | + unit++; | ||
414 | + } | ||
415 | + *speed = *data / time; | ||
416 | + sprintf(metric, "%sB", units[unit]); | ||
417 | +} | ||
418 | + | ||
419 | +static int encrypt_data(int fdc, struct test_params tp, struct session_op *sess) | ||
420 | +{ | ||
421 | + struct crypt_op cop; | ||
422 | + char *buffer, iv[32]; | ||
423 | + char mac[HASH_MAX_LEN]; | ||
424 | + static int val = 23; | ||
425 | + struct timeval start, end; | ||
426 | + double total = 0; | ||
427 | + double secs, ddata, dspeed; | ||
428 | + char metric[16]; | ||
429 | + int alignmask; | ||
430 | + int min_alignmask = sizeof(void*) - 1; | ||
431 | + | ||
432 | + memset(iv, 0x23, 32); | ||
433 | + | ||
434 | + printf("\tEncrypting in chunks of %d bytes: ", tp.nvalue); | ||
435 | + fflush(stdout); | ||
436 | + | ||
437 | + alignmask = get_alignmask(fdc, sess); | ||
438 | + if (alignmask) { | ||
439 | + alignmask = ((alignmask < min_alignmask) ? min_alignmask : alignmask); | ||
440 | + if (posix_memalign((void **)(&buffer), alignmask + 1, tp.nvalue)) { | ||
441 | + printf("posix_memalign() failed!\n"); | ||
442 | + return 1; | ||
443 | + } | ||
444 | + } else { | ||
445 | + if (!(buffer = malloc(tp.nvalue))) { | ||
446 | + perror("malloc()"); | ||
447 | + return 1; | ||
448 | + } | ||
449 | + } | ||
450 | + memset(buffer, val++, tp.nvalue); | ||
451 | + | ||
452 | + must_finish = 0; | ||
453 | + alarm(tp.tvalue); | ||
454 | + | ||
455 | + gettimeofday(&start, NULL); | ||
456 | + do { | ||
457 | + memset(&cop, 0, sizeof(cop)); | ||
458 | + cop.ses = sess->ses; | ||
459 | + cop.len = tp.nvalue; | ||
460 | + cop.iv = (unsigned char *)iv; | ||
461 | + cop.op = COP_ENCRYPT; | ||
462 | + cop.src = cop.dst = (unsigned char *)buffer; | ||
463 | + cop.mac = (unsigned char *)mac; | ||
464 | + | ||
465 | + if (ioctl(fdc, CIOCCRYPT, &cop)) { | ||
466 | + perror("ioctl(CIOCCRYPT)"); | ||
467 | + return 1; | ||
468 | + } | ||
469 | + total += cop.len; | ||
470 | + } while(!must_finish); | ||
471 | + gettimeofday(&end, NULL); | ||
472 | + | ||
473 | + secs = udifftimeval(start, end)/ 1000000.0; | ||
474 | + | ||
475 | + value2human(total, secs, &ddata, &dspeed, metric); | ||
476 | + printf ("done. %.2f %s in %.2f secs: ", ddata, metric, secs); | ||
477 | + printf ("%.2f %s/sec\n", dspeed, metric); | ||
478 | + | ||
479 | + free(buffer); | ||
480 | + return 0; | ||
481 | +} | ||
482 | + | ||
483 | +void usage(char *cmd_name) | ||
484 | +{ | ||
485 | + printf(usage_str, cmd_name); | ||
486 | +} | ||
487 | + | ||
488 | +int run_test(int id, struct test_params tp) | ||
489 | +{ | ||
490 | + int fd; | ||
491 | + int fdc; | ||
492 | + | ||
493 | + fd = open("/dev/crypto", O_RDWR, 0); | ||
494 | + if (fd < 0) { | ||
495 | + perror("open()"); | ||
496 | + return fd; | ||
497 | + } | ||
498 | + if (ioctl(fd, CRIOGET, &fdc)) { | ||
499 | + perror("ioctl(CRIOGET)"); | ||
500 | + return -EINVAL; | ||
501 | + } | ||
502 | + | ||
503 | + ciphers[id].func(fdc, tp); | ||
504 | + | ||
505 | + close(fdc); | ||
506 | + close(fd); | ||
507 | + | ||
508 | + return 0; | ||
509 | +} | ||
510 | + | ||
511 | +int get_alignmask(int fdc, struct session_op *sess) | ||
512 | +{ | ||
513 | + int alignmask; | ||
514 | + | ||
515 | +#ifdef CIOCGSESSINFO | ||
516 | + struct session_info_op siop; | ||
517 | + | ||
518 | + siop.ses = sess->ses; | ||
519 | + if (ioctl(fdc, CIOCGSESSINFO, &siop)) { | ||
520 | + perror("ioctl(CIOCGSESSINFO)"); | ||
521 | + return -EINVAL; | ||
522 | + } | ||
523 | + alignmask = siop.alignmask; | ||
524 | +#else | ||
525 | + alignmask = 0; | ||
526 | +#endif | ||
527 | + | ||
528 | + return alignmask; | ||
529 | +} | ||
530 | + | ||
531 | +void do_test_vectors(int fdc, struct test_params tp, struct session_op *sess) | ||
532 | +{ | ||
533 | + int i; | ||
534 | + | ||
535 | + if (tp.nflag) { | ||
536 | + encrypt_data(fdc, tp, sess); | ||
537 | + } else { | ||
538 | + for (i = 256; i <= (64 * 1024); i *= 2) { | ||
539 | + if (must_exit) | ||
540 | + break; | ||
541 | + | ||
542 | + tp.nvalue = i; | ||
543 | + if (encrypt_data(fdc, tp, sess)) { | ||
544 | + break; | ||
545 | + } | ||
546 | + } | ||
547 | + } | ||
548 | +} | ||
549 | + | ||
550 | + | ||
551 | +int run_null(int fdc, struct test_params tp) | ||
552 | +{ | ||
553 | + struct session_op sess; | ||
554 | + char keybuf[32]; | ||
555 | + | ||
556 | + fprintf(stderr, "Testing NULL cipher: \n"); | ||
557 | + memset(&sess, 0, sizeof(sess)); | ||
558 | + sess.cipher = CRYPTO_NULL; | ||
559 | + sess.keylen = 0; | ||
560 | + sess.key = (unsigned char *)keybuf; | ||
561 | + if (ioctl(fdc, CIOCGSESSION, &sess)) { | ||
562 | + perror("ioctl(CIOCGSESSION)"); | ||
563 | + return -EINVAL; | ||
564 | + } | ||
565 | + | ||
566 | + do_test_vectors(fdc, tp, &sess); | ||
567 | + return 0; | ||
568 | +} | ||
569 | + | ||
570 | +int run_aes_cbc(int fdc, struct test_params tp) | ||
571 | +{ | ||
572 | + struct session_op sess; | ||
573 | + char keybuf[32]; | ||
574 | + | ||
575 | + fprintf(stderr, "\nTesting AES-128-CBC cipher: \n"); | ||
576 | + memset(&sess, 0, sizeof(sess)); | ||
577 | + sess.cipher = CRYPTO_AES_CBC; | ||
578 | + sess.keylen = 16; | ||
579 | + memset(keybuf, 0x42, 16); | ||
580 | + sess.key = (unsigned char *)keybuf; | ||
581 | + if (ioctl(fdc, CIOCGSESSION, &sess)) { | ||
582 | + perror("ioctl(CIOCGSESSION)"); | ||
583 | + return -EINVAL; | ||
584 | + } | ||
585 | + | ||
586 | + do_test_vectors(fdc, tp, &sess); | ||
587 | + return 0; | ||
588 | +} | ||
589 | + | ||
590 | +int run_aes_xts(int fdc, struct test_params tp) | ||
591 | +{ | ||
592 | + struct session_op sess; | ||
593 | + char keybuf[32]; | ||
594 | + | ||
595 | + fprintf(stderr, "\nTesting AES-256-XTS cipher: \n"); | ||
596 | + memset(&sess, 0, sizeof(sess)); | ||
597 | + sess.cipher = CRYPTO_AES_XTS; | ||
598 | + sess.keylen = 32; | ||
599 | + memset(keybuf, 0x42, sess.keylen); | ||
600 | + sess.key = (unsigned char *)keybuf; | ||
601 | + if (ioctl(fdc, CIOCGSESSION, &sess)) { | ||
602 | + perror("ioctl(CIOCGSESSION)"); | ||
603 | + return -EINVAL; | ||
604 | + } | ||
605 | + | ||
606 | + do_test_vectors(fdc, tp, &sess); | ||
607 | + return 0; | ||
608 | +} | ||
609 | + | ||
610 | +int run_crc32c(int fdc, struct test_params tp) | ||
611 | +{ | ||
612 | + struct session_op sess; | ||
613 | + | ||
614 | + fprintf(stderr, "\nTesting CRC32C hash: \n"); | ||
615 | + memset(&sess, 0, sizeof(sess)); | ||
616 | + sess.mac = CRYPTO_CRC32C; | ||
617 | + if (ioctl(fdc, CIOCGSESSION, &sess)) { | ||
618 | + perror("ioctl(CIOCGSESSION)"); | ||
619 | + return 1; | ||
620 | + } | ||
621 | + | ||
622 | + do_test_vectors(fdc, tp, &sess); | ||
623 | + return 0; | ||
624 | +} | ||
625 | + | ||
626 | +int run_sha1(int fdc, struct test_params tp) | ||
627 | +{ | ||
628 | + struct session_op sess; | ||
629 | + | ||
630 | + fprintf(stderr, "\nTesting SHA-1 hash: \n"); | ||
631 | + memset(&sess, 0, sizeof(sess)); | ||
632 | + sess.mac = CRYPTO_SHA1; | ||
633 | + if (ioctl(fdc, CIOCGSESSION, &sess)) { | ||
634 | + perror("ioctl(CIOCGSESSION)"); | ||
635 | + return 1; | ||
636 | + } | ||
637 | + | ||
638 | + do_test_vectors(fdc, tp, &sess); | ||
639 | + return 0; | ||
640 | +} | ||
641 | + | ||
642 | +int run_sha256(int fdc, struct test_params tp) | ||
643 | +{ | ||
644 | + struct session_op sess; | ||
645 | + | ||
646 | + fprintf(stderr, "\nTesting SHA2-256 hash: \n"); | ||
647 | + memset(&sess, 0, sizeof(sess)); | ||
648 | + sess.mac = CRYPTO_SHA2_256; | ||
649 | + if (ioctl(fdc, CIOCGSESSION, &sess)) { | ||
650 | + perror("ioctl(CIOCGSESSION)"); | ||
651 | + return 1; | ||
652 | + } | ||
653 | + | ||
654 | + do_test_vectors(fdc, tp, &sess); | ||
655 | + return 0; | ||
656 | +} | ||
657 | + | ||
658 | +int main(int argc, char **argv) | ||
659 | +{ | ||
660 | + int i; | ||
661 | + int c; | ||
662 | + bool alg_flag; | ||
663 | + char *alg_name; | ||
664 | + struct test_params tp; | ||
665 | + | ||
666 | + tp.tflag = false; | ||
667 | + tp.nflag = false; | ||
668 | + alg_flag = false; | ||
669 | + opterr = 0; | ||
670 | + while ((c = getopt(argc, argv, "hn:t:")) != -1) { | ||
671 | + switch (c) { | ||
672 | + case 'n': | ||
673 | + tp.nvalue = atoi(optarg); | ||
674 | + tp.nflag = true; | ||
675 | + break; | ||
676 | + case 't': | ||
677 | + tp.tvalue = atoi(optarg); | ||
678 | + tp.tflag = true; | ||
679 | + break; | ||
680 | + case 'h': /* no break */ | ||
681 | + default: | ||
682 | + usage(argv[0]); | ||
683 | + exit(1); | ||
684 | + } | ||
685 | + } | ||
686 | + | ||
687 | + /* the name of a specific test asked on the command line */ | ||
688 | + if (optind < argc) { | ||
689 | + alg_name = argv[optind]; | ||
690 | + alg_flag = true; | ||
691 | + } | ||
692 | + | ||
693 | + /* default test time */ | ||
694 | + if (!tp.tflag) { | ||
695 | + tp.tvalue = 5; | ||
696 | + } | ||
697 | + | ||
698 | + signal(SIGALRM, alarm_handler); | ||
699 | + signal(SIGINT, exit_handler); | ||
700 | + | ||
701 | + for (i = 0; i < ALG_COUNT; i++) { | ||
702 | + if (must_exit) | ||
703 | + break; | ||
704 | + | ||
705 | + if (alg_flag) { | ||
706 | + if (strcmp(alg_name, ciphers[i].name) == 0) { | ||
707 | + run_test(i, tp); | ||
708 | + } | ||
709 | + } else { | ||
710 | + run_test(i, tp); | ||
711 | + } | ||
712 | + } | ||
713 | + | ||
714 | + return 0; | ||
715 | +} | ||
716 | -- | ||
717 | 2.10.2 | ||
718 | |||