]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/tools/crypto/cryptotest.c
Import Intel Processor Trace decoder library from
[FreeBSD/FreeBSD.git] / tools / tools / crypto / cryptotest.c
1 /*-
2  * Copyright (c) 2004 Sam Leffler, Errno Consulting
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer,
10  *    without modification.
11  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13  *    redistribution must be conditioned upon including a substantially
14  *    similar Disclaimer requirement for further binary redistribution.
15  * 3. Neither the names of the above-listed copyright holders nor the names
16  *    of any contributors may be used to endorse or promote products derived
17  *    from this software without specific prior written permission.
18  *
19  * NO WARRANTY
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
23  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
24  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
25  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
28  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30  * THE POSSIBILITY OF SUCH DAMAGES.
31  *
32  * $FreeBSD$
33  */
34
35 /*
36  * Simple tool for testing hardware/system crypto support.
37  *
38  * cryptotest [-czsbv] [-a algorithm] [count] [size ...]
39  *
40  * Run count iterations of a crypt+decrypt or mac operation on a buffer of
41  * size bytes.  A random key and iv are used.  Options:
42  *      -c      check the results
43  *      -d dev  pin work on device dev
44  *      -z      run all available algorithms on a variety of buffer sizes
45  *      -v      be verbose
46  *      -b      mark operations for batching
47  *      -p      profile kernel crypto operations (must be root)
48  *      -t n    fork n threads and run tests concurrently
49  * Known algorithms are:
50  *      null    null cbc
51  *      des     des cbc
52  *      3des    3des cbc
53  *      blf     blowfish cbc
54  *      cast    cast cbc
55  *      skj     skipjack cbc
56  *      aes     rijndael/aes 128-bit cbc
57  *      aes192  rijndael/aes 192-bit cbc
58  *      aes256  rijndael/aes 256-bit cbc
59  *      md5     md5 hmac
60  *      sha1    sha1 hmac
61  *      sha256  256-bit sha2 hmac
62  *      sha384  384-bit sha2 hmac
63  *      sha512  512--bit sha2 hmac
64  *
65  * For a test of how fast a crypto card is, use something like:
66  *      cryptotest -z 1024
67  * This will run a series of tests using the available crypto/cipher
68  * algorithms over a variety of buffer sizes.  The 1024 says to do 1024
69  * iterations.  Extra arguments can be used to specify one or more buffer
70  * sizes to use in doing tests.
71  *
72  * To fork multiple processes all doing the same work, specify -t X on the
73  * command line to get X "threads" running simultaneously.  No effort is made
74  * to synchronize the threads or otherwise maximize load.
75  *
76  * If the kernel crypto code is built with CRYPTO_TIMING and you run as root,
77  * then you can specify the -p option to get a "profile" of the time spent
78  * processing crypto operations.  At present this data is only meaningful for
79  * symmetric operations.  To get meaningful numbers you must run on an idle
80  * machine.
81  *
82  * Expect ~400 Mb/s for a Broadcom 582x for 8K buffers on a reasonable CPU
83  * (64-bit PCI helps).  Hifn 7811 parts top out at ~110 Mb/s.
84  */
85
86 #include <sys/param.h>
87 #include <sys/cpuset.h>
88 #include <sys/ioctl.h>
89 #include <sys/mman.h>
90 #include <sys/sysctl.h>
91 #include <sys/time.h>
92 #include <sys/wait.h>
93
94 #include <err.h>
95 #include <fcntl.h>
96 #include <paths.h>
97 #include <stdio.h>
98 #include <stdlib.h>
99 #include <string.h>
100 #include <sysexits.h>
101 #include <unistd.h>
102
103 #include <crypto/cryptodev.h>
104
105 #define CHUNK   64      /* how much to display */
106 #define streq(a,b)      (strcasecmp(a,b) == 0)
107
108 void    hexdump(char *, int);
109
110 int     verbose = 0;
111 int     opflags = 0;
112 int     verify = 0;
113 int     crid = CRYPTO_FLAG_HARDWARE;
114
115 struct alg {
116         const char* name;
117         int     ishash;
118         int     blocksize;
119         int     minkeylen;
120         int     maxkeylen;
121         int     code;
122 } algorithms[] = {
123 #ifdef CRYPTO_NULL_CBC
124         { "null",       0,      8,      1,      256,    CRYPTO_NULL_CBC },
125 #endif
126         { "des",        0,      8,      8,      8,      CRYPTO_DES_CBC },
127         { "3des",       0,      8,      24,     24,     CRYPTO_3DES_CBC },
128         { "blf",        0,      8,      5,      56,     CRYPTO_BLF_CBC },
129         { "cast",       0,      8,      5,      16,     CRYPTO_CAST_CBC },
130         { "skj",        0,      8,      10,     10,     CRYPTO_SKIPJACK_CBC },
131         { "rij",        0,      16,     16,     16,     CRYPTO_RIJNDAEL128_CBC},
132         { "aes",        0,      16,     16,     16,     CRYPTO_AES_CBC},
133         { "aes192",     0,      16,     24,     24,     CRYPTO_AES_CBC},
134         { "aes256",     0,      16,     32,     32,     CRYPTO_AES_CBC},
135         { "md5",        1,      8,      16,     16,     CRYPTO_MD5_HMAC },
136         { "sha1",       1,      8,      20,     20,     CRYPTO_SHA1_HMAC },
137         { "sha256",     1,      8,      32,     32,     CRYPTO_SHA2_256_HMAC },
138         { "sha384",     1,      8,      48,     48,     CRYPTO_SHA2_384_HMAC },
139         { "sha512",     1,      8,      64,     64,     CRYPTO_SHA2_512_HMAC },
140 };
141
142 void
143 usage(const char* cmd)
144 {
145         printf("usage: %s [-czsbv] [-d dev] [-a algorithm] [count] [size ...]\n",
146                 cmd);
147         printf("where algorithm is one of:\n");
148         printf("    null des 3des (default) blowfish cast skipjack rij\n");
149         printf("    aes aes192 aes256 md5 sha1 sha256 sha384 sha512\n");
150         printf(" or an encryption algorithm concatented with authentication\n");
151         printf(" algorithm with '+' in the middle, e.g., aes+sha1.\n");
152         printf("count is the number of encrypt/decrypt ops to do\n");
153         printf("size is the number of bytes of text to encrypt+decrypt\n");
154         printf("\n");
155         printf("-c check the results (slows timing)\n");
156         printf("-d use specific device, specify 'soft' for testing software implementations\n");
157         printf("\tNOTE: to use software you must set:\n\t sysctl kern.cryptodevallowsoft=1\n");
158         printf("-z run all available algorithms on a variety of sizes\n");
159         printf("-v be verbose\n");
160         printf("-b mark operations for batching\n");
161         printf("-p profile kernel crypto operation (must be root)\n");
162         printf("-t n for n threads and run tests concurrently\n");
163         exit(-1);
164 }
165
166 struct alg*
167 getalgbycode(int cipher)
168 {
169         int i;
170
171         for (i = 0; i < nitems(algorithms); i++)
172                 if (cipher == algorithms[i].code)
173                         return &algorithms[i];
174         return NULL;
175 }
176
177 struct alg*
178 getalgbyname(const char* name)
179 {
180         int i;
181
182         for (i = 0; i < nitems(algorithms); i++)
183                 if (streq(name, algorithms[i].name))
184                         return &algorithms[i];
185         return NULL;
186 }
187
188 int
189 devcrypto(void)
190 {
191         int fd = -1;
192
193         if (fd < 0) {
194                 fd = open(_PATH_DEV "crypto", O_RDWR, 0);
195                 if (fd < 0)
196                         err(1, _PATH_DEV "crypto");
197                 if (fcntl(fd, F_SETFD, 1) == -1)
198                         err(1, "fcntl(F_SETFD) (devcrypto)");
199         }
200         return fd;
201 }
202
203 int
204 crlookup(const char *devname)
205 {
206         struct crypt_find_op find;
207
208         if (strncmp(devname, "soft", 4) == 0)
209                 return CRYPTO_FLAG_SOFTWARE;
210
211         find.crid = -1;
212         strlcpy(find.name, devname, sizeof(find.name));
213         if (ioctl(devcrypto(), CIOCFINDDEV, &find) == -1)
214                 err(1, "ioctl(CIOCFINDDEV)");
215         return find.crid;
216 }
217
218 const char *
219 crfind(int crid)
220 {
221         static struct crypt_find_op find;
222
223         bzero(&find, sizeof(find));
224         find.crid = crid;
225         if (ioctl(devcrypto(), CRIOFINDDEV, &find) == -1)
226                 err(1, "ioctl(CIOCFINDDEV): crid %d", crid);
227         return find.name;
228 }
229
230 int
231 crget(void)
232 {
233         int fd;
234
235         if (ioctl(devcrypto(), CRIOGET, &fd) == -1)
236                 err(1, "ioctl(CRIOGET)");
237         if (fcntl(fd, F_SETFD, 1) == -1)
238                 err(1, "fcntl(F_SETFD) (crget)");
239         return fd;
240 }
241
242 char
243 rdigit(void)
244 {
245         const char a[] = {
246                 0x10,0x54,0x11,0x48,0x45,0x12,0x4f,0x13,0x49,0x53,0x14,0x41,
247                 0x15,0x16,0x4e,0x55,0x54,0x17,0x18,0x4a,0x4f,0x42,0x19,0x01
248         };
249         return 0x20+a[random()%nitems(a)];
250 }
251
252 void
253 runtest(struct alg *ealg, struct alg *alg, int count, int size, u_long cmd, struct timeval *tv)
254 {
255         int i, fd = crget();
256         struct timeval start, stop, dt;
257         char *cleartext, *ciphertext, *originaltext, *key;
258         struct session2_op sop;
259         struct crypt_op cop;
260         char iv[EALG_MAX_BLOCK_LEN];
261         char digest[512/8];
262
263         /* Canonicalize 'ealg' to crypt alg and 'alg' to authentication alg. */
264         if (ealg == NULL && !alg->ishash) {
265                 ealg = alg;
266                 alg = NULL;
267         }
268
269         bzero(&sop, sizeof(sop));
270         if (ealg != NULL) {
271                 sop.keylen = (ealg->minkeylen + ealg->maxkeylen)/2;
272                 key = (char *) malloc(sop.keylen);
273                 if (key == NULL)
274                         err(1, "malloc (key)");
275                 for (i = 0; i < sop.keylen; i++)
276                         key[i] = rdigit();
277                 sop.key = key;
278                 sop.cipher = ealg->code;
279         }
280         if (alg != NULL) {
281                 sop.mackeylen = (alg->minkeylen + alg->maxkeylen)/2;
282                 key = (char *) malloc(sop.mackeylen);
283                 if (key == NULL)
284                         err(1, "malloc (mac)");
285                 for (i = 0; i < sop.mackeylen; i++)
286                         key[i] = rdigit();
287                 sop.mackey = key;
288                 sop.mac = alg->code;
289         }
290
291         sop.crid = crid;
292         if (ioctl(fd, cmd, &sop) < 0) {
293                 if (cmd == CIOCGSESSION || cmd == CIOCGSESSION2) {
294                         close(fd);
295                         if (verbose) {
296                                 printf("cipher %s%s%s", ealg? ealg->name : "",
297                                     (ealg && alg) ? "+" : "",
298                                     alg? alg->name : "");
299
300                                 if (alg->ishash)
301                                         printf(" mackeylen %u\n", sop.mackeylen);
302                                 else
303                                         printf(" keylen %u\n", sop.keylen);
304                                 perror("CIOCGSESSION");
305                         }
306                         /* hardware doesn't support algorithm; skip it */
307                         return;
308                 }
309                 printf("cipher %s%s%s keylen %u mackeylen %u\n",
310                     ealg? ealg->name : "", (ealg && alg) ? "+" : "",
311                     alg? alg->name : "", sop.keylen, sop.mackeylen);
312                 err(1, "CIOCGSESSION");
313         }
314
315         originaltext = malloc(3*size);
316         if (originaltext == NULL)
317                 err(1, "malloc (text)");
318         cleartext = originaltext+size;
319         ciphertext = cleartext+size;
320         for (i = 0; i < size; i++)
321                 cleartext[i] = rdigit();
322         memcpy(originaltext, cleartext, size);
323         for (i = 0; i < nitems(iv); i++)
324                 iv[i] = rdigit();
325
326         if (verbose) {
327                 printf("session = 0x%x\n", sop.ses);
328                 printf("device = %s\n", crfind(sop.crid));
329                 printf("count = %d, size = %d\n", count, size);
330                 if (ealg) {
331                         printf("iv:");
332                         hexdump(iv, sizeof iv);
333                 }
334                 printf("cleartext:");
335                 hexdump(cleartext, MIN(size, CHUNK));
336         }
337
338         gettimeofday(&start, NULL);
339         if (ealg) {
340                 for (i = 0; i < count; i++) {
341                         cop.ses = sop.ses;
342                         cop.op = COP_ENCRYPT;
343                         cop.flags = opflags | COP_F_CIPHER_FIRST;
344                         cop.len = size;
345                         cop.src = cleartext;
346                         cop.dst = ciphertext;
347                         if (alg)
348                                 cop.mac = digest;
349                         else
350                                 cop.mac = 0;
351                         cop.iv = iv;
352
353                         if (ioctl(fd, CIOCCRYPT, &cop) < 0)
354                                 err(1, "ioctl(CIOCCRYPT)");
355
356                         if (verify && bcmp(ciphertext, cleartext, size) == 0) {
357                                 printf("cipher text unchanged:");
358                                 hexdump(ciphertext, size);
359                         }
360
361                         memset(cleartext, 'x', MIN(size, CHUNK));
362                         cop.ses = sop.ses;
363                         cop.op = COP_DECRYPT;
364                         cop.flags = opflags;
365                         cop.len = size;
366                         cop.src = ciphertext;
367                         cop.dst = cleartext;
368                         if (alg)
369                                 cop.mac = digest;
370                         else
371                                 cop.mac = 0;
372                         cop.iv = iv;
373
374                         if (ioctl(fd, CIOCCRYPT, &cop) < 0)
375                                 err(1, "ioctl(CIOCCRYPT)");
376
377                         if (verify && bcmp(cleartext, originaltext, size) != 0) {
378                                 printf("decrypt mismatch:\n");
379                                 printf("original:");
380                                 hexdump(originaltext, size);
381                                 printf("cleartext:");
382                                 hexdump(cleartext, size);
383                         }
384                 }
385         } else {
386                 for (i = 0; i < count; i++) {
387                         cop.ses = sop.ses;
388                         cop.op = 0;
389                         cop.flags = opflags;
390                         cop.len = size;
391                         cop.src = cleartext;
392                         cop.dst = 0;
393                         cop.mac = ciphertext;
394                         cop.iv = 0;
395
396                         if (ioctl(fd, CIOCCRYPT, &cop) < 0)
397                                 err(1, "ioctl(CIOCCRYPT)");
398                 }
399         }
400         gettimeofday(&stop, NULL);
401  
402         if (ioctl(fd, CIOCFSESSION, &sop.ses) < 0)
403                 perror("ioctl(CIOCFSESSION)");
404
405         if (verbose) {
406                 printf("cleartext:");
407                 hexdump(cleartext, MIN(size, CHUNK));
408         }
409         timersub(&stop, &start, tv);
410
411         free(originaltext);
412
413         close(fd);
414 }
415
416 #ifdef __FreeBSD__
417 void
418 resetstats()
419 {
420         struct cryptostats stats;
421         size_t slen;
422
423         slen = sizeof (stats);
424         if (sysctlbyname("kern.crypto_stats", &stats, &slen, NULL, 0) < 0) {
425                 perror("kern.crypto_stats");
426                 return;
427         }
428         bzero(&stats.cs_invoke, sizeof (stats.cs_invoke));
429         bzero(&stats.cs_done, sizeof (stats.cs_done));
430         bzero(&stats.cs_cb, sizeof (stats.cs_cb));
431         bzero(&stats.cs_finis, sizeof (stats.cs_finis));
432         stats.cs_invoke.min.tv_sec = 10000;
433         stats.cs_done.min.tv_sec = 10000;
434         stats.cs_cb.min.tv_sec = 10000;
435         stats.cs_finis.min.tv_sec = 10000;
436         if (sysctlbyname("kern.crypto_stats", NULL, NULL, &stats, sizeof (stats)) < 0)
437                 perror("kern.cryptostats");
438 }
439
440 void
441 printt(const char* tag, struct cryptotstat *ts)
442 {
443         uint64_t avg, min, max;
444
445         if (ts->count == 0)
446                 return;
447         avg = (1000000000LL*ts->acc.tv_sec + ts->acc.tv_nsec) / ts->count;
448         min = 1000000000LL*ts->min.tv_sec + ts->min.tv_nsec;
449         max = 1000000000LL*ts->max.tv_sec + ts->max.tv_nsec;
450         printf("%16.16s: avg %6llu ns : min %6llu ns : max %7llu ns [%u samps]\n",
451                 tag, avg, min, max, ts->count);
452 }
453 #endif
454
455 void
456 runtests(struct alg *ealg, struct alg *alg, int count, int size, u_long cmd, int threads, int profile)
457 {
458         int i, status;
459         double t;
460         void *region;
461         struct timeval *tvp;
462         struct timeval total;
463         int otiming;
464
465         if (size % alg->blocksize || (ealg && size % ealg->blocksize)) {
466                 if (verbose)
467                         printf("skipping blocksize %u 'cuz not a multiple of "
468                                 "%s blocksize %u (or %s blocksize %u)\n",
469                                 size, alg->name, alg->blocksize,
470                                 ealg ?  ealg->name : "n/a",
471                                 ealg ? ealg->blocksize : 0);
472                 return;
473         }
474
475         region = mmap(NULL, threads * sizeof (struct timeval),
476                         PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
477         if (region == MAP_FAILED) {
478                 perror("mmap");
479                 return;
480         }
481         tvp = (struct timeval *) region;
482 #ifdef __FreeBSD__
483         if (profile) {
484                 size_t tlen = sizeof (otiming);
485                 int timing = 1;
486
487                 resetstats();
488                 if (sysctlbyname("debug.crypto_timing", &otiming, &tlen,
489                                 &timing, sizeof (timing)) < 0)
490                         perror("debug.crypto_timing");
491         }
492 #endif
493
494         if (threads > 1) {
495                 for (i = 0; i < threads; i++)
496                         if (fork() == 0) {
497                                 cpuset_t mask;
498                                 CPU_ZERO(&mask);
499                                 CPU_SET(i, &mask);
500                                 cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID,
501                                     -1, sizeof(mask), &mask);
502                                 runtest(ealg, alg, count, size, cmd, &tvp[i]);
503                                 exit(0);
504                         }
505                 while (waitpid(WAIT_MYPGRP, &status, 0) != -1)
506                         ;
507         } else
508                 runtest(ealg, alg, count, size, cmd, tvp);
509
510         t = 0;
511         for (i = 0; i < threads; i++)
512                 t += (((double)tvp[i].tv_sec * 1000000 + tvp[i].tv_usec) / 1000000);
513         if (t) {
514                 int nops = alg->ishash ? count : 2*count;
515
516                 nops *= threads;
517                 printf("%8.3lf sec, %7d %6s%s%6s crypts, %7d bytes, %8.0lf byte/sec, %7.1lf Mb/sec\n",
518                     t, nops, alg->name, ealg? "+" : "", ealg? ealg->name : "",
519                     size, (double)nops*size / t,
520                     (double)nops*size / t * 8 / 1024 / 1024);
521         }
522 #ifdef __FreeBSD__
523         if (profile) {
524                 struct cryptostats stats;
525                 size_t slen = sizeof (stats);
526
527                 if (sysctlbyname("debug.crypto_timing", NULL, NULL,
528                                 &otiming, sizeof (otiming)) < 0)
529                         perror("debug.crypto_timing");
530                 if (sysctlbyname("kern.crypto_stats", &stats, &slen, NULL, 0) < 0)
531                         perror("kern.cryptostats");
532                 if (stats.cs_invoke.count) {
533                         printt("dispatch->invoke", &stats.cs_invoke);
534                         printt("invoke->done", &stats.cs_done);
535                         printt("done->cb", &stats.cs_cb);
536                         printt("cb->finis", &stats.cs_finis);
537                 }
538         }
539 #endif
540         fflush(stdout);
541 }
542
543 int
544 main(int argc, char **argv)
545 {
546         struct alg *alg = NULL, *ealg = NULL;
547         char *tmp;
548         int count = 1;
549         int sizes[128], nsizes = 0;
550         u_long cmd = CIOCGSESSION2;
551         int testall = 0;
552         int maxthreads = 1;
553         int profile = 0;
554         int i, ch;
555
556         while ((ch = getopt(argc, argv, "cpzsva:bd:t:")) != -1) {
557                 switch (ch) {
558 #ifdef CIOCGSSESSION
559                 case 's':
560                         cmd = CIOCGSSESSION;
561                         break;
562 #endif
563                 case 'v':
564                         verbose++;
565                         break;
566                 case 'a':
567                         tmp = strchr(optarg, '+');
568                         if (tmp != NULL) {
569                                 *tmp = '\0';
570                                 ealg = getalgbyname(optarg);
571                                 if (ealg == NULL || ealg->ishash)
572                                         usage(argv[0]);
573                                 optarg = tmp + 1;
574                         }
575
576                         alg = getalgbyname(optarg);
577                         if (alg == NULL) {
578                                 if (streq(optarg, "rijndael"))
579                                         alg = getalgbyname("aes");
580                                 else
581                                         usage(argv[0]);
582                         } else if (ealg != NULL && !alg->ishash)
583                                 usage(argv[0]);
584                         break;
585                 case 'd':
586                         crid = crlookup(optarg);
587                         break;
588                 case 't':
589                         maxthreads = atoi(optarg);
590                         break;
591                 case 'z':
592                         testall = 1;
593                         break;
594                 case 'p':
595                         profile = 1;
596                         break;
597                 case 'b':
598                         opflags |= COP_F_BATCH;
599                         break;
600                 case 'c':
601                         verify = 1;
602                         break;
603                 default:
604                         usage(argv[0]);
605                 }
606         }
607         argc -= optind, argv += optind;
608         if (argc > 0)
609                 count = atoi(argv[0]);
610         while (argc > 1) {
611                 int s = atoi(argv[1]);
612                 if (nsizes < nitems(sizes)) {
613                         sizes[nsizes++] = s;
614                 } else {
615                         printf("Too many sizes, ignoring %u\n", s);
616                 }
617                 argc--, argv++;
618         }
619         if (maxthreads > CPU_SETSIZE)
620                 errx(EX_USAGE, "Too many threads, %d, choose fewer.", maxthreads);
621         
622         if (nsizes == 0) {
623                 if (alg)
624                         sizes[nsizes++] = alg->blocksize;
625                 else
626                         sizes[nsizes++] = 8;
627                 if (testall) {
628                         while (sizes[nsizes-1] < 8*1024) {
629                                 sizes[nsizes] = sizes[nsizes-1]<<1;
630                                 nsizes++;
631                         }
632                 }
633         }
634
635         if (testall) {
636                 for (i = 0; i < nitems(algorithms); i++) {
637                         int j;
638                         alg = &algorithms[i];
639                         for (j = 0; j < nsizes; j++)
640                                 runtests(ealg, alg, count, sizes[j], cmd, maxthreads, profile);
641                 }
642         } else {
643                 if (alg == NULL)
644                         alg = getalgbycode(CRYPTO_3DES_CBC);
645                 for (i = 0; i < nsizes; i++)
646                         runtests(ealg, alg, count, sizes[i], cmd, maxthreads, profile);
647         }
648
649         return (0);
650 }
651
652 void
653 hexdump(char *p, int n)
654 {
655         int i, off;
656
657         for (off = 0; n > 0; off += 16, n -= 16) {
658                 printf("%s%04x:", off == 0 ? "\n" : "", off);
659                 i = (n >= 16 ? 16 : n);
660                 do {
661                         printf(" %02x", *p++ & 0xff);
662                 } while (--i);
663                 printf("\n");
664         }
665 }