summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgnn <gnn@FreeBSD.org>2016-09-24 13:44:18 +0000
committergnn <gnn@FreeBSD.org>2016-09-24 13:44:18 +0000
commit1416a05e9cfe0bc7d1050a3c5522c32a53595367 (patch)
tree12ac18a3714f62817a92482f078485acbd93d083
parente26380ce48c0d2e98f182e649396cc13c214b0e9 (diff)
downloadFreeBSD-src-1416a05e9cfe0bc7d1050a3c5522c32a53595367.zip
FreeBSD-src-1416a05e9cfe0bc7d1050a3c5522c32a53595367.tar.gz
MFC: 305066,305304,305312
Update cryptotest for modern algorithms Clean up the usage message and remove dead code. Add cpuset support to separate forked processes. Reviewed by: cem Sponsored by: Rubicon Communications, LLC (Netgate)
-rw-r--r--tools/tools/crypto/cryptotest.c66
1 files changed, 36 insertions, 30 deletions
diff --git a/tools/tools/crypto/cryptotest.c b/tools/tools/crypto/cryptotest.c
index c13d3a45..bf0f8ee 100644
--- a/tools/tools/crypto/cryptotest.c
+++ b/tools/tools/crypto/cryptotest.c
@@ -84,6 +84,7 @@
*/
#include <sys/param.h>
+#include <sys/cpuset.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/sysctl.h>
@@ -96,6 +97,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sysexits.h>
#include <unistd.h>
#include <crypto/cryptodev.h>
@@ -126,12 +128,10 @@ struct alg {
{ "blf", 0, 8, 5, 56, CRYPTO_BLF_CBC },
{ "cast", 0, 8, 5, 16, CRYPTO_CAST_CBC },
{ "skj", 0, 8, 10, 10, CRYPTO_SKIPJACK_CBC },
- { "aes", 0, 16, 16, 16, CRYPTO_RIJNDAEL128_CBC},
- { "aes192", 0, 16, 24, 24, CRYPTO_RIJNDAEL128_CBC},
- { "aes256", 0, 16, 32, 32, CRYPTO_RIJNDAEL128_CBC},
-#ifdef notdef
- { "arc4", 0, 8, 1, 32, CRYPTO_ARC4 },
-#endif
+ { "rij", 0, 16, 16, 16, CRYPTO_RIJNDAEL128_CBC},
+ { "aes", 0, 16, 16, 16, CRYPTO_AES_CBC},
+ { "aes192", 0, 16, 24, 24, CRYPTO_AES_CBC},
+ { "aes256", 0, 16, 32, 32, CRYPTO_AES_CBC},
{ "md5", 1, 8, 16, 16, CRYPTO_MD5_HMAC },
{ "sha1", 1, 8, 20, 20, CRYPTO_SHA1_HMAC },
{ "sha256", 1, 8, 32, 32, CRYPTO_SHA2_256_HMAC },
@@ -139,27 +139,29 @@ struct alg {
{ "sha512", 1, 8, 64, 64, CRYPTO_SHA2_512_HMAC },
};
-static void
+void
usage(const char* cmd)
{
printf("usage: %s [-czsbv] [-d dev] [-a algorithm] [count] [size ...]\n",
cmd);
printf("where algorithm is one of:\n");
- printf(" des 3des (default) blowfish cast skipjack\n");
- printf(" aes (aka rijndael) aes192 aes256 arc4\n");
+ printf(" null des 3des (default) blowfish cast skipjack rij\n");
+ printf(" aes aes192 aes256 md5 sha1 sha256 sha384 sha512\n");
printf("count is the number of encrypt/decrypt ops to do\n");
printf("size is the number of bytes of text to encrypt+decrypt\n");
printf("\n");
printf("-c check the results (slows timing)\n");
- printf("-d use specific device\n");
+ printf("-d use specific device, specify 'soft' for testing software implementations\n");
+ printf("\tNOTE: to use software you must set:\n\t sysctl kern.cryptodevallowsoft=1\n");
printf("-z run all available algorithms on a variety of sizes\n");
printf("-v be verbose\n");
printf("-b mark operations for batching\n");
printf("-p profile kernel crypto operation (must be root)\n");
+ printf("-t n for n threads and run tests concurrently\n");
exit(-1);
}
-static struct alg*
+struct alg*
getalgbycode(int cipher)
{
int i;
@@ -170,7 +172,7 @@ getalgbycode(int cipher)
return NULL;
}
-static struct alg*
+struct alg*
getalgbyname(const char* name)
{
int i;
@@ -181,10 +183,10 @@ getalgbyname(const char* name)
return NULL;
}
-static int
+int
devcrypto(void)
{
- static int fd = -1;
+ int fd = -1;
if (fd < 0) {
fd = open(_PATH_DEV "crypto", O_RDWR, 0);
@@ -196,11 +198,14 @@ devcrypto(void)
return fd;
}
-static int
+int
crlookup(const char *devname)
{
struct crypt_find_op find;
+ if (strncmp(devname, "soft", 4) == 0)
+ return CRYPTO_FLAG_SOFTWARE;
+
find.crid = -1;
strlcpy(find.name, devname, sizeof(find.name));
if (ioctl(devcrypto(), CIOCFINDDEV, &find) == -1)
@@ -208,10 +213,10 @@ crlookup(const char *devname)
return find.crid;
}
-static const char *
+const char *
crfind(int crid)
{
- static struct crypt_find_op find;
+ struct crypt_find_op find;
bzero(&find, sizeof(find));
find.crid = crid;
@@ -220,7 +225,7 @@ crfind(int crid)
return find.name;
}
-static int
+int
crget(void)
{
int fd;
@@ -232,7 +237,7 @@ crget(void)
return fd;
}
-static char
+char
rdigit(void)
{
const char a[] = {
@@ -242,7 +247,7 @@ rdigit(void)
return 0x20+a[random()%nitems(a)];
}
-static void
+void
runtest(struct alg *alg, int count, int size, u_long cmd, struct timeval *tv)
{
int i, fd = crget();
@@ -386,7 +391,7 @@ runtest(struct alg *alg, int count, int size, u_long cmd, struct timeval *tv)
}
#ifdef __FreeBSD__
-static void
+void
resetstats()
{
struct cryptostats stats;
@@ -409,7 +414,7 @@ resetstats()
perror("kern.cryptostats");
}
-static void
+void
printt(const char* tag, struct cryptotstat *ts)
{
uint64_t avg, min, max;
@@ -424,7 +429,7 @@ printt(const char* tag, struct cryptotstat *ts)
}
#endif
-static void
+void
runtests(struct alg *alg, int count, int size, u_long cmd, int threads, int profile)
{
int i, status;
@@ -464,6 +469,11 @@ runtests(struct alg *alg, int count, int size, u_long cmd, int threads, int prof
if (threads > 1) {
for (i = 0; i < threads; i++)
if (fork() == 0) {
+ cpuset_t mask;
+ CPU_ZERO(&mask);
+ CPU_SET(i, &mask);
+ cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID,
+ -1, sizeof(mask), &mask);
runtest(alg, count, size, cmd, &tvp[i]);
exit(0);
}
@@ -478,17 +488,10 @@ runtests(struct alg *alg, int count, int size, u_long cmd, int threads, int prof
if (t) {
int nops = alg->ishash ? count : 2*count;
-#if 0
- t /= threads;
- printf("%6.3lf sec, %7d %6s crypts, %7d bytes, %8.0lf byte/sec, %7.1lf Mb/sec\n",
- t, nops, alg->name, size, (double)nops*size / t,
- (double)nops*size / t * 8 / 1024 / 1024);
-#else
nops *= threads;
printf("%8.3lf sec, %7d %6s crypts, %7d bytes, %8.0lf byte/sec, %7.1lf Mb/sec\n",
t, nops, alg->name, size, (double)nops*size / t,
(double)nops*size / t * 8 / 1024 / 1024);
-#endif
}
#ifdef __FreeBSD__
if (profile) {
@@ -576,6 +579,9 @@ main(int argc, char **argv)
}
argc--, argv++;
}
+ if (maxthreads > CPU_SETSIZE)
+ errx(EX_USAGE, "Too many threads, %d, choose fewer.", maxthreads);
+
if (nsizes == 0) {
if (alg)
sizes[nsizes++] = alg->blocksize;
OpenPOWER on IntegriCloud