From 86c4e3e8f9f9b7da425f18f6be09f4d4bb12bbf1 Mon Sep 17 00:00:00 2001
From: Nikos Mavrogiannopoulos <nmav@gnutls.org>
Date: Wed, 23 Jun 2010 00:19:08 +0200
Subject: [PATCH 062/291] cryptodev: cryptodev_test

---
 drivers/staging/crypto/cryptodev/examples/Makefile |   6 +-
 .../crypto/cryptodev/examples/cryptodev_test.c     | 128 ---------------------
 drivers/staging/crypto/cryptodev/examples/speed.c  | 128 +++++++++++++++++++++
 3 files changed, 131 insertions(+), 131 deletions(-)
 delete mode 100644 drivers/staging/crypto/cryptodev/examples/cryptodev_test.c
 create mode 100644 drivers/staging/crypto/cryptodev/examples/speed.c

diff --git a/drivers/staging/crypto/cryptodev/examples/Makefile b/drivers/staging/crypto/cryptodev/examples/Makefile
index 333db1c6aa85..937eb6d80f18 100644
--- a/drivers/staging/crypto/cryptodev/examples/Makefile
+++ b/drivers/staging/crypto/cryptodev/examples/Makefile
@@ -1,13 +1,13 @@
 KERNEL_DIR ?= /lib/modules/$(shell uname -r)/build
 
-hostprogs := cipher hmac cryptodev_test
+hostprogs := cipher hmac speed
 example-cipher-objs := cipher.o
 example-hmac-objs := hmac.o
-example-cryptodev_test-objs := cryptodev_test.c
+example-speed-objs := speed.c
 
 check: $(hostprogs)
 	./cipher
 	./hmac
 
 clean:
-	rm -f *.o *~ hmac cipher cryptodev_test
+	rm -f *.o *~ hmac cipher speed
diff --git a/drivers/staging/crypto/cryptodev/examples/cryptodev_test.c b/drivers/staging/crypto/cryptodev/examples/cryptodev_test.c
deleted file mode 100644
index 77d6d29f035e..000000000000
--- a/drivers/staging/crypto/cryptodev/examples/cryptodev_test.c
+++ /dev/null
@@ -1,128 +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 "../cryptodev.h"
-
-#if 1
-#define TEST_ALGO	CRYPTO_AES_CBC
-#define TEST_KEYLEN	32
-#else
-#define TEST_ALGO	CRYPTO_NULL
-#define TEST_KEYLEN	0
-#endif
-
-/* transcode a total of 1GB */
-#define TOT_LEN (1024 * 1024 * 1024)
-
-static long udifftimeval(struct timeval start, struct timeval end)
-{
-	return (end.tv_usec - start.tv_usec) +
-	       (end.tv_sec - start.tv_sec) * 1000 * 1000 + 0.5;
-}
-
-int encrypt_data(struct session_op *sess, int fdc, int len, int chunksize, int flags)
-{
-	struct crypt_op cop;
-	char *buffer, iv[32];
-	int i, buffercount;
-	static int val = 23;
-	struct timeval start, end;
-
-	if (len % chunksize) {
-		printf("got milk?!\n");
-		return 1;
-	}
-
-	buffercount = len / chunksize;
-
-	buffer = malloc(chunksize);
-	memset(iv, 0x23, 32);
-
-	printf("Encrypting %d x %d bytes: ", buffercount, chunksize);
-	fflush(stdout);
-
-	memset(buffer, val++, chunksize);
-
-	gettimeofday(&start, NULL);
-	for (i = 0; i < buffercount; i++) {
-		memset(&cop, 0, sizeof(cop));
-		cop.ses = sess->ses;
-		cop.len = chunksize;
-		cop.iv = (unsigned char *)iv;
-		cop.op = COP_ENCRYPT;
-		cop.flags = flags;
-		cop.src = cop.dst = (unsigned char *)buffer;
-
-		if (ioctl(fdc, CIOCCRYPT, &cop)) {
-			perror("ioctl(CIOCCRYPT)");
-			return 1;
-		}
-	}
-	gettimeofday(&end, NULL);
-
-	printf("done in %.5f seconds - %.5fMB/s\n", (double)udifftimeval(start, end) / 1000000.0,
-			(double)len / ((double)udifftimeval(start, end) / 1000000.0) / 1024 / 1024);
-	return 0;
-}
-
-int main(void)
-{
-	int fd, i, fdc = -1;
-	struct session_op sess;
-	char keybuf[32];
-
-	if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0) {
-		perror("open()");
-		return 1;
-	}
-	if (ioctl(fd, CRIOGET, &fdc)) {
-		perror("ioctl(CRIOGET)");
-		return 1;
-	}
-	memset(&sess, 0, sizeof(sess));
-	sess.cipher = TEST_ALGO;
-	sess.keylen = TEST_KEYLEN;
-	memset(keybuf, 0x42, 32);
-	sess.key = (unsigned char *)keybuf;
-	if (ioctl(fdc, CIOCGSESSION, &sess)) {
-		perror("ioctl(CIOCGSESSION)");
-		return 1;
-	}
-
-	printf("Standard operation:\n");
-	for (i = 256; i <= (64 * 4096); i *= 2) {
-		if (encrypt_data(&sess, fdc, TOT_LEN, i, 0))
-			break;
-	}
-	printf("Zero-Copy operation:\n");
-	for (i = 256; i <= (64 * 4096); i *= 2) {
-		if (encrypt_data(&sess, fdc, TOT_LEN, i, COP_FLAG_ZCOPY))
-			break;
-	}
-
-	close(fdc);
-	close(fd);
-	return 0;
-}
diff --git a/drivers/staging/crypto/cryptodev/examples/speed.c b/drivers/staging/crypto/cryptodev/examples/speed.c
new file mode 100644
index 000000000000..77d6d29f035e
--- /dev/null
+++ b/drivers/staging/crypto/cryptodev/examples/speed.c
@@ -0,0 +1,128 @@
+/*  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 "../cryptodev.h"
+
+#if 1
+#define TEST_ALGO	CRYPTO_AES_CBC
+#define TEST_KEYLEN	32
+#else
+#define TEST_ALGO	CRYPTO_NULL
+#define TEST_KEYLEN	0
+#endif
+
+/* transcode a total of 1GB */
+#define TOT_LEN (1024 * 1024 * 1024)
+
+static long udifftimeval(struct timeval start, struct timeval end)
+{
+	return (end.tv_usec - start.tv_usec) +
+	       (end.tv_sec - start.tv_sec) * 1000 * 1000 + 0.5;
+}
+
+int encrypt_data(struct session_op *sess, int fdc, int len, int chunksize, int flags)
+{
+	struct crypt_op cop;
+	char *buffer, iv[32];
+	int i, buffercount;
+	static int val = 23;
+	struct timeval start, end;
+
+	if (len % chunksize) {
+		printf("got milk?!\n");
+		return 1;
+	}
+
+	buffercount = len / chunksize;
+
+	buffer = malloc(chunksize);
+	memset(iv, 0x23, 32);
+
+	printf("Encrypting %d x %d bytes: ", buffercount, chunksize);
+	fflush(stdout);
+
+	memset(buffer, val++, chunksize);
+
+	gettimeofday(&start, NULL);
+	for (i = 0; i < buffercount; i++) {
+		memset(&cop, 0, sizeof(cop));
+		cop.ses = sess->ses;
+		cop.len = chunksize;
+		cop.iv = (unsigned char *)iv;
+		cop.op = COP_ENCRYPT;
+		cop.flags = flags;
+		cop.src = cop.dst = (unsigned char *)buffer;
+
+		if (ioctl(fdc, CIOCCRYPT, &cop)) {
+			perror("ioctl(CIOCCRYPT)");
+			return 1;
+		}
+	}
+	gettimeofday(&end, NULL);
+
+	printf("done in %.5f seconds - %.5fMB/s\n", (double)udifftimeval(start, end) / 1000000.0,
+			(double)len / ((double)udifftimeval(start, end) / 1000000.0) / 1024 / 1024);
+	return 0;
+}
+
+int main(void)
+{
+	int fd, i, fdc = -1;
+	struct session_op sess;
+	char keybuf[32];
+
+	if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0) {
+		perror("open()");
+		return 1;
+	}
+	if (ioctl(fd, CRIOGET, &fdc)) {
+		perror("ioctl(CRIOGET)");
+		return 1;
+	}
+	memset(&sess, 0, sizeof(sess));
+	sess.cipher = TEST_ALGO;
+	sess.keylen = TEST_KEYLEN;
+	memset(keybuf, 0x42, 32);
+	sess.key = (unsigned char *)keybuf;
+	if (ioctl(fdc, CIOCGSESSION, &sess)) {
+		perror("ioctl(CIOCGSESSION)");
+		return 1;
+	}
+
+	printf("Standard operation:\n");
+	for (i = 256; i <= (64 * 4096); i *= 2) {
+		if (encrypt_data(&sess, fdc, TOT_LEN, i, 0))
+			break;
+	}
+	printf("Zero-Copy operation:\n");
+	for (i = 256; i <= (64 * 4096); i *= 2) {
+		if (encrypt_data(&sess, fdc, TOT_LEN, i, COP_FLAG_ZCOPY))
+			break;
+	}
+
+	close(fdc);
+	close(fd);
+	return 0;
+}
-- 
2.1.0

