]> code.ossystems Code Review - meta-freescale.git/blob
5e8893b6516cd9497d8e0bd65be4620ce34fee7f
[meta-freescale.git] /
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