aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-kernel/cryptodev/sdk_patches/0081-add-sync-speed-tests-with-the-same-format-as-async-o.patch
blob: 5e8893b6516cd9497d8e0bd65be4620ce34fee7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
From b13160357e683b9d42ba513433b4c09456a8332b Mon Sep 17 00:00:00 2001
From: Alexe Radu <radu.alexe@nxp.com>
Date: Fri, 28 Oct 2016 13:39:50 +0300
Subject: [PATCH 081/104] add sync speed tests with the same format as async
 ones

The file speed.c was removed because has the same functionality
as sync_speed.c

Signed-off-by: Alexe Radu <radu.alexe@nxp.com>
---
 tests/Makefile     |   4 +-
 tests/speed.c      | 265 -----------------------------------
 tests/sync_speed.c | 399 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 401 insertions(+), 267 deletions(-)
 delete mode 100644 tests/speed.c
 create mode 100644 tests/sync_speed.c

diff --git a/tests/Makefile b/tests/Makefile
index 23d67f9..400fb7a 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -3,14 +3,14 @@ CFLAGS += -I.. $(CRYPTODEV_CFLAGS)
 
 comp_progs := cipher_comp hash_comp hmac_comp
 
-hostprogs := cipher cipher-aead hmac speed async_cipher async_hmac \
+hostprogs := cipher cipher-aead hmac sync_speed async_cipher async_hmac \
 	async_speed sha_speed hashcrypt_speed fullspeed cipher-gcm \
 	cipher-aead-srtp $(comp_progs)
 
 example-cipher-objs := cipher.o
 example-cipher-aead-objs := cipher-aead.o
 example-hmac-objs := hmac.o
-example-speed-objs := speed.c
+example-speed-objs := sync_speed.o
 example-fullspeed-objs := fullspeed.c
 example-sha-speed-objs := sha_speed.c
 example-async-cipher-objs := async_cipher.o
diff --git a/tests/speed.c b/tests/speed.c
deleted file mode 100644
index 0e2bbc3..0000000
--- a/tests/speed.c
+++ /dev/null
@@ -1,265 +0,0 @@
-/*  cryptodev_test - simple benchmark tool for cryptodev
- *
- *    Copyright (C) 2010 by Phil Sutter <phil.sutter@viprinet.com>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <signal.h>
-#include <unistd.h>
-#include <stdint.h>
-
-#include <crypto/cryptodev.h>
-
-static int si = 1; /* SI by default */
-
-static double udifftimeval(struct timeval start, struct timeval end)
-{
-	return (double)(end.tv_usec - start.tv_usec) +
-	       (double)(end.tv_sec - start.tv_sec) * 1000 * 1000;
-}
-
-static int must_finish = 0;
-
-static void alarm_handler(int signo)
-{
-        must_finish = 1;
-}
-
-static char *units[] = { "", "Ki", "Mi", "Gi", "Ti", 0};
-static char *si_units[] = { "", "K", "M", "G", "T", 0};
-
-static void value2human(int si, double bytes, double time, double* data, double* speed,char* metric)
-{
-	int unit = 0;
-
-	*data = bytes;
-	
-	if (si) {
-		while (*data > 1000 && si_units[unit + 1]) {
-			*data /= 1000;
-			unit++;
-		}
-		*speed = *data / time;
-		sprintf(metric, "%sB", si_units[unit]);
-	} else {
-		while (*data > 1024 && units[unit + 1]) {
-			*data /= 1024;
-			unit++;
-		}
-		*speed = *data / time;
-		sprintf(metric, "%sB", units[unit]);
-	}
-}
-
-#define MAX(x,y) ((x)>(y)?(x):(y))
-
-int encrypt_data(struct session_op *sess, int fdc, int chunksize, int alignmask)
-{
-	struct crypt_op cop;
-	char *buffer, iv[32];
-	uint8_t mac[HASH_MAX_LEN];
-	static int val = 23;
-	struct timeval start, end;
-	double total = 0;
-	double secs, ddata, dspeed;
-	char metric[16];
-	int min_alignmask = sizeof(void*) - 1;
-
-	if (alignmask) {
-		alignmask = ((alignmask < min_alignmask) ? min_alignmask : alignmask);
-		if (posix_memalign((void **)&buffer, MAX(alignmask + 1, sizeof(void*)), chunksize)) {
-			printf("posix_memalign() failed! (mask %x, size: %d)\n", alignmask+1, chunksize);
-			return 1;
-		}
-	} else {
-		if (!(buffer = malloc(chunksize))) {
-			perror("malloc()");
-			return 1;
-		}
-	}
-
-	memset(iv, 0x23, 32);
-
-	printf("\tEncrypting in chunks of %d bytes: ", chunksize);
-	fflush(stdout);
-
-	memset(buffer, val++, chunksize);
-
-	must_finish = 0;
-	alarm(5);
-
-	gettimeofday(&start, NULL);
-	do {
-		memset(&cop, 0, sizeof(cop));
-		cop.ses = sess->ses;
-		cop.len = chunksize;
-		cop.iv = (unsigned char *)iv;
-		cop.op = COP_ENCRYPT;
-		cop.src = cop.dst = (unsigned char *)buffer;
-		cop.mac = mac;
-
-		if (ioctl(fdc, CIOCCRYPT, &cop)) {
-			perror("ioctl(CIOCCRYPT)");
-			return 1;
-		}
-		total+=chunksize;
-	} while(must_finish==0);
-	gettimeofday(&end, NULL);
-
-	secs = udifftimeval(start, end)/ 1000000.0;
-
-	value2human(si, total, secs, &ddata, &dspeed, metric);
-	printf ("done. %.2f %s in %.2f secs: ", ddata, metric, secs);
-	printf ("%.2f %s/sec\n", dspeed, metric);
-
-	free(buffer);
-	return 0;
-}
-
-int main(int argc, char** argv)
-{
-	int fd, i, fdc = -1, alignmask = 0;
-	struct session_op sess;
-#ifdef CIOCGSESSINFO
-	struct session_info_op siop;
-#endif
-	char keybuf[32];
-
-	signal(SIGALRM, alarm_handler);
-	
-	if (argc > 1) {
-		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) {
-			printf("Usage: speed [--kib]\n");
-			exit(0);
-		}
-		if (strcmp(argv[1], "--kib") == 0) {
-			si = 0;
-		}
-	}
-
-	if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0) {
-		perror("open()");
-		return 1;
-	}
-	if (ioctl(fd, CRIOGET, &fdc)) {
-		perror("ioctl(CRIOGET)");
-		return 1;
-	}
-
-	fprintf(stderr, "Testing NULL cipher: \n");
-	memset(&sess, 0, sizeof(sess));
-	sess.cipher = CRYPTO_NULL;
-	sess.keylen = 0;
-	sess.key = (unsigned char *)keybuf;
-	if (ioctl(fdc, CIOCGSESSION, &sess)) {
-		perror("ioctl(CIOCGSESSION)");
-		return 1;
-	}
-#ifdef CIOCGSESSINFO
-	siop.ses = sess.ses;
-	if (ioctl(fdc, CIOCGSESSINFO, &siop)) {
-		perror("ioctl(CIOCGSESSINFO)");
-		return 1;
-	}
-	alignmask = siop.alignmask;
-#endif
-
-	for (i = 512; i <= (64 * 1024); i *= 2) {
-		if (encrypt_data(&sess, fdc, i, alignmask))
-			break;
-	}
-
-	fprintf(stderr, "\nTesting AES-128-CBC cipher: \n");
-	memset(&sess, 0, sizeof(sess));
-	sess.cipher = CRYPTO_AES_CBC;
-	sess.keylen = 16;
-	memset(keybuf, 0x42, 16);
-	sess.key = (unsigned char *)keybuf;
-	if (ioctl(fdc, CIOCGSESSION, &sess)) {
-		perror("ioctl(CIOCGSESSION)");
-		return 1;
-	}
-#ifdef CIOCGSESSINFO
-	siop.ses = sess.ses;
-	if (ioctl(fdc, CIOCGSESSINFO, &siop)) {
-		perror("ioctl(CIOCGSESSINFO)");
-		return 1;
-	}
-	alignmask = siop.alignmask;
-#endif
-
-	for (i = 512; i <= (64 * 1024); i *= 2) {
-		if (encrypt_data(&sess, fdc, i, alignmask))
-			break;
-	}
-
-	fprintf(stderr, "\nTesting AES-256-XTS cipher: \n");
-	memset(&sess, 0, sizeof(sess));
-	sess.cipher = CRYPTO_AES_XTS;
-	sess.keylen = 32;
-	memset(keybuf, 0x42, sess.keylen);
-	sess.key = (unsigned char *)keybuf;
-	if (ioctl(fdc, CIOCGSESSION, &sess)) {
-		perror("ioctl(CIOCGSESSION)");
-		return 1;
-	}
-#ifdef CIOCGSESSINFO
-	siop.ses = sess.ses;
-	if (ioctl(fdc, CIOCGSESSINFO, &siop)) {
-		perror("ioctl(CIOCGSESSINFO)");
-		return 1;
-	}
-	alignmask = siop.alignmask;
-#endif
-
-	for (i = 512; i <= (64 * 1024); i *= 2) {
-		if (encrypt_data(&sess, fdc, i, alignmask))
-			break;
-	}
-
-	fprintf(stderr, "\nTesting CRC32C hash: \n");
-	memset(&sess, 0, sizeof(sess));
-	sess.mac = CRYPTO_CRC32C;
-	if (ioctl(fdc, CIOCGSESSION, &sess)) {
-		perror("ioctl(CIOCGSESSION)");
-		return 1;
-	}
-#ifdef CIOCGSESSINFO
-	siop.ses = sess.ses;
-	if (ioctl(fdc, CIOCGSESSINFO, &siop)) {
-		perror("ioctl(CIOCGSESSINFO)");
-		return 1;
-	}
-	printf("requested hash CRYPTO_CRC32C, got %s with driver %s\n",
-			siop.hash_info.cra_name, siop.hash_info.cra_driver_name);
-	alignmask = siop.alignmask;
-#endif
-
-	for (i = 512; i <= (64 * 1024); i *= 2) {
-		if (encrypt_data(&sess, fdc, i, alignmask))
-			break;
-	}
-
-	close(fdc);
-	close(fd);
-	return 0;
-}
diff --git a/tests/sync_speed.c b/tests/sync_speed.c
new file mode 100644
index 0000000..b0cb9ad
--- /dev/null
+++ b/tests/sync_speed.c
@@ -0,0 +1,399 @@
+/*  cryptodev_test - simple benchmark tool for cryptodev
+ *
+ *    Copyright (C) 2010 by Phil Sutter <phil.sutter@viprinet.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <crypto/cryptodev.h>
+#include <stdbool.h>
+#include <unistd.h>
+
+struct test_params {
+	bool tflag;
+	bool nflag;
+	int tvalue;
+	int nvalue;
+};
+
+const char usage_str[] = "Usage: %s [OPTION]... <cipher>|<hash>\n"
+	"Run benchmark test for cipher or hash\n\n"
+	"  -t <secs>\t" "time to run each test (default 10 secs)\n"
+	"  -n <bytes>\t" "size of the test buffer\n"
+	"  -h\t\t" "show this help\n"
+;
+
+int run_null(int fdc, struct test_params tp);
+int run_aes_cbc(int fdc, struct test_params tp);
+int run_aes_xts(int fdc, struct test_params tp);
+int run_crc32c(int fdc, struct test_params tp);
+int run_sha1(int fdc, struct test_params tp);
+int run_sha256(int fdc, struct test_params tp);
+int get_alignmask(int fdc, struct session_op *sess);
+
+#define ALG_COUNT	6
+struct {
+	char *name;
+	int (*func)(int, struct test_params);
+} ciphers[ALG_COUNT] = {
+	{"null",	run_null},
+	{"aes-cbc",	run_aes_cbc},
+	{"aes-xts",	run_aes_xts},
+	{"crc32c",	run_crc32c},
+	{"sha1",	run_sha1},
+	{"sha256",	run_sha256},
+};
+
+static double udifftimeval(struct timeval start, struct timeval end)
+{
+	return (double)(end.tv_usec - start.tv_usec) +
+	       (double)(end.tv_sec - start.tv_sec) * 1000 * 1000;
+}
+
+static int must_finish = 0;
+static int must_exit = 0;
+
+static void alarm_handler(int signo)
+{
+        must_finish = 1;
+}
+
+static void exit_handler(int signo)
+{
+	must_exit = 1;
+	printf("\nexit requested by user through ctrl+c \n");
+}
+
+static char *units[] = { "", "Ki", "Mi", "Gi", "Ti", 0};
+
+static void value2human(double bytes, double time, double* data, double* speed,char* metric)
+{
+	int unit = 0;
+
+	*data = bytes;
+	while (*data > 1024 && units[unit + 1]) {
+		*data /= 1024;
+		unit++;
+	}
+	*speed = *data / time;
+	sprintf(metric, "%sB", units[unit]);
+}
+
+static int encrypt_data(int fdc, struct test_params tp, struct session_op *sess)
+{
+	struct crypt_op cop;
+	char *buffer, iv[32];
+	char mac[HASH_MAX_LEN];
+	static int val = 23;
+	struct timeval start, end;
+	double total = 0;
+	double secs, ddata, dspeed;
+	char metric[16];
+	int alignmask;
+	int min_alignmask = sizeof(void*) - 1;
+
+	memset(iv, 0x23, 32);
+
+	printf("\tEncrypting in chunks of %d bytes: ", tp.nvalue);
+	fflush(stdout);
+
+	alignmask = get_alignmask(fdc, sess);
+	if (alignmask) {
+		alignmask = ((alignmask < min_alignmask) ? min_alignmask : alignmask);
+		if (posix_memalign((void **)(&buffer), alignmask + 1, tp.nvalue)) {
+			printf("posix_memalign() failed!\n");
+			return 1;
+		}
+	} else {
+		if (!(buffer = malloc(tp.nvalue))) {
+			perror("malloc()");
+			return 1;
+		}
+	}
+	memset(buffer, val++, tp.nvalue);
+	
+	must_finish = 0;
+	alarm(tp.tvalue);
+
+	gettimeofday(&start, NULL);
+	do {
+		memset(&cop, 0, sizeof(cop));
+		cop.ses = sess->ses;
+		cop.len = tp.nvalue;
+		cop.iv = (unsigned char *)iv;
+		cop.op = COP_ENCRYPT;
+		cop.src = cop.dst = (unsigned char *)buffer;
+		cop.mac = (unsigned char *)mac;
+
+		if (ioctl(fdc, CIOCCRYPT, &cop)) {
+			perror("ioctl(CIOCCRYPT)");
+			return 1;
+		}
+		total += cop.len;
+	} while(!must_finish);
+	gettimeofday(&end, NULL);
+
+	secs = udifftimeval(start, end)/ 1000000.0;
+
+	value2human(total, secs, &ddata, &dspeed, metric);
+	printf ("done. %.2f %s in %.2f secs: ", ddata, metric, secs);
+	printf ("%.2f %s/sec\n", dspeed, metric);
+
+	free(buffer);
+	return 0;
+}
+
+void usage(char *cmd_name)
+{
+	printf(usage_str, cmd_name);
+}
+
+int run_test(int id, struct test_params tp)
+{
+	int fd;
+	int fdc;
+
+	fd = open("/dev/crypto", O_RDWR, 0);
+	if (fd < 0) {
+		perror("open()");
+		return fd;
+	}
+	if (ioctl(fd, CRIOGET, &fdc)) {
+		perror("ioctl(CRIOGET)");
+		return -EINVAL;
+	}
+
+	ciphers[id].func(fdc, tp);
+
+	close(fdc);
+	close(fd);
+
+	return 0;
+}
+
+int get_alignmask(int fdc, struct session_op *sess)
+{
+	int alignmask;
+
+#ifdef CIOCGSESSINFO
+	struct session_info_op siop;
+
+	siop.ses = sess->ses;
+	if (ioctl(fdc, CIOCGSESSINFO, &siop)) {
+		perror("ioctl(CIOCGSESSINFO)");
+		return -EINVAL;
+	}
+	alignmask = siop.alignmask;
+#else
+	alignmask = 0;
+#endif
+
+	return alignmask;
+}
+
+void do_test_vectors(int fdc, struct test_params tp, struct session_op *sess)
+{
+	int i;
+
+	if (tp.nflag) {
+		encrypt_data(fdc, tp, sess);
+	} else {
+		for (i = 256; i <= (64 * 1024); i *= 2) {
+			if (must_exit)
+				break;
+
+			tp.nvalue = i;
+			if (encrypt_data(fdc, tp, sess)) {
+				break;
+			}
+		}
+	}
+}
+
+
+int run_null(int fdc, struct test_params tp)
+{
+	struct session_op sess;
+	char keybuf[32];
+
+	fprintf(stderr, "Testing NULL cipher: \n");
+	memset(&sess, 0, sizeof(sess));
+	sess.cipher = CRYPTO_NULL;
+	sess.keylen = 0;
+	sess.key = (unsigned char *)keybuf;
+	if (ioctl(fdc, CIOCGSESSION, &sess)) {
+		perror("ioctl(CIOCGSESSION)");
+		return -EINVAL;
+	}
+
+	do_test_vectors(fdc, tp, &sess);
+	return 0;
+}
+
+int run_aes_cbc(int fdc, struct test_params tp)
+{
+	struct session_op sess;
+	char keybuf[32];
+
+	fprintf(stderr, "\nTesting AES-128-CBC cipher: \n");
+	memset(&sess, 0, sizeof(sess));
+	sess.cipher = CRYPTO_AES_CBC;
+	sess.keylen = 16;
+	memset(keybuf, 0x42, 16);
+	sess.key = (unsigned char *)keybuf;
+	if (ioctl(fdc, CIOCGSESSION, &sess)) {
+		perror("ioctl(CIOCGSESSION)");
+		return -EINVAL;
+	}
+
+	do_test_vectors(fdc, tp, &sess);
+	return 0;
+}
+
+int run_aes_xts(int fdc, struct test_params tp)
+{
+	struct session_op sess;
+	char keybuf[32];
+
+	fprintf(stderr, "\nTesting AES-256-XTS cipher: \n");
+	memset(&sess, 0, sizeof(sess));
+	sess.cipher = CRYPTO_AES_XTS;
+	sess.keylen = 32;
+	memset(keybuf, 0x42, sess.keylen);
+	sess.key = (unsigned char *)keybuf;
+	if (ioctl(fdc, CIOCGSESSION, &sess)) {
+		perror("ioctl(CIOCGSESSION)");
+		return -EINVAL;
+	}
+
+	do_test_vectors(fdc, tp, &sess);
+	return 0;
+}
+
+int run_crc32c(int fdc, struct test_params tp)
+{
+	struct session_op sess;
+
+	fprintf(stderr, "\nTesting CRC32C hash: \n");
+	memset(&sess, 0, sizeof(sess));
+	sess.mac = CRYPTO_CRC32C;
+	if (ioctl(fdc, CIOCGSESSION, &sess)) {
+		perror("ioctl(CIOCGSESSION)");
+		return 1;
+	}
+
+	do_test_vectors(fdc, tp, &sess);
+	return 0;
+}
+
+int run_sha1(int fdc, struct test_params tp)
+{
+	struct session_op sess;
+
+	fprintf(stderr, "\nTesting SHA-1 hash: \n");
+	memset(&sess, 0, sizeof(sess));
+	sess.mac = CRYPTO_SHA1;
+	if (ioctl(fdc, CIOCGSESSION, &sess)) {
+		perror("ioctl(CIOCGSESSION)");
+		return 1;
+	}
+
+	do_test_vectors(fdc, tp, &sess);
+	return 0;
+}
+
+int run_sha256(int fdc, struct test_params tp)
+{
+	struct session_op sess;
+
+	fprintf(stderr, "\nTesting SHA2-256 hash: \n");
+	memset(&sess, 0, sizeof(sess));
+	sess.mac = CRYPTO_SHA2_256;
+	if (ioctl(fdc, CIOCGSESSION, &sess)) {
+		perror("ioctl(CIOCGSESSION)");
+		return 1;
+	}
+
+	do_test_vectors(fdc, tp, &sess);
+	return 0;
+}
+
+int main(int argc, char **argv)
+{
+	int i;
+	int c;
+	bool alg_flag;
+	char *alg_name;
+	struct test_params tp;
+
+	tp.tflag = false;
+	tp.nflag = false;
+	alg_flag = false;
+	opterr = 0;
+	while ((c = getopt(argc, argv, "hn:t:")) != -1) {
+		switch (c) {
+		case 'n':
+			tp.nvalue = atoi(optarg);
+			tp.nflag = true;
+			break;
+		case 't':
+			tp.tvalue = atoi(optarg);
+			tp.tflag = true;
+			break;
+		case 'h': /* no break */
+		default:
+			usage(argv[0]);
+			exit(1);
+		}
+	}
+
+	/* the name of a specific test asked on the command line */
+	if (optind < argc) {
+		alg_name = argv[optind];
+		alg_flag = true;
+	}
+
+	/* default test time */
+	if (!tp.tflag) {
+		tp.tvalue = 5;
+	}
+
+	signal(SIGALRM, alarm_handler);
+	signal(SIGINT, exit_handler);
+
+	for (i = 0; i < ALG_COUNT; i++) {
+		if (must_exit)
+			break;
+
+		if (alg_flag) {
+			if (strcmp(alg_name, ciphers[i].name) == 0) {
+				run_test(i, tp);
+			}
+		} else {
+			run_test(i, tp);
+		}
+	}
+
+	return 0;
+}
-- 
2.10.2