From d4aea6a55d61f15ac8433e3d01f14c7d9bc7e7cf Mon Sep 17 00:00:00 2001
From: Vladimir Zapolskiy <vzapolskiy@gmail.com>
Date: Fri, 25 Mar 2011 01:07:09 +0200
Subject: [PATCH 135/291] cryptodev: examples:

This change adds setting up of alignment mask for buffers according to
the value, which is obtained from the kernel algorithm definition.

Signed-off-by: Vladimir Zapolskiy <vzapolskiy@gmail.com>
---
 drivers/staging/crypto/cryptodev/examples/hashcrypt_speed.c | 10 ++++++----
 drivers/staging/crypto/cryptodev/examples/sha_speed.c       | 10 ++++++----
 drivers/staging/crypto/cryptodev/examples/speed.c           | 12 ++++++++++--
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/crypto/cryptodev/examples/hashcrypt_speed.c b/drivers/staging/crypto/cryptodev/examples/hashcrypt_speed.c
index f5e0e400cd27..234457712758 100644
--- a/drivers/staging/crypto/cryptodev/examples/hashcrypt_speed.c
+++ b/drivers/staging/crypto/cryptodev/examples/hashcrypt_speed.c
@@ -80,7 +80,7 @@ int hash_data(struct session_op *sess, int fdc, int chunksize, int alignmask)
 	uint8_t mac[AALG_MAX_RESULT_LEN];
 
 	if (alignmask) {
-		if (posix_memalign((void **)&buffer, alignmask, chunksize)) {
+		if (posix_memalign((void **)&buffer, alignmask + 1, chunksize)) {
 			printf("posix_memalign() failed!\n");
 			return 1;
 		}
@@ -128,7 +128,7 @@ int hash_data(struct session_op *sess, int fdc, int chunksize, int alignmask)
 
 int main(void)
 {
-	int fd, i, fdc = -1;
+	int fd, i, fdc = -1, alignmask = 0;
 	struct session_op sess;
 	char keybuf[32];
 #ifdef CIOCGSESSINFO
@@ -165,10 +165,11 @@ int main(void)
 	}
 	printf("requested hash CRYPTO_SHA1, got %s with driver %s\n",
 			siop.hash_info.cra_name, siop.hash_info.cra_driver_name);
+	alignmask = siop.alignmask;
 #endif
 
 	for (i = 256; i <= (64 * 4096); i *= 2) {
-		if (hash_data(&sess, fdc, i, siop.alignmask))
+		if (hash_data(&sess, fdc, i, alignmask))
 			break;
 	}
 
@@ -189,10 +190,11 @@ int main(void)
 	}
 	printf("requested hash CRYPTO_SHA2_256, got %s with driver %s\n",
 			siop.hash_info.cra_name, siop.hash_info.cra_driver_name);
+	alignmask = siop.alignmask;
 #endif
 
 	for (i = 256; i <= (64 * 1024); i *= 2) {
-		if (hash_data(&sess, fdc, i, 0))
+		if (hash_data(&sess, fdc, i, alignmask))
 			break;
 	}
 
diff --git a/drivers/staging/crypto/cryptodev/examples/sha_speed.c b/drivers/staging/crypto/cryptodev/examples/sha_speed.c
index f31558f40f2d..6389db22dab0 100644
--- a/drivers/staging/crypto/cryptodev/examples/sha_speed.c
+++ b/drivers/staging/crypto/cryptodev/examples/sha_speed.c
@@ -80,7 +80,7 @@ int hash_data(struct session_op *sess, int fdc, int chunksize, int alignmask)
 	uint8_t mac[AALG_MAX_RESULT_LEN];
 
 	if (alignmask) {
-		if (posix_memalign((void **)&buffer, alignmask, chunksize)) {
+		if (posix_memalign((void **)&buffer, alignmask + 1, chunksize)) {
 			printf("posix_memalign() failed!\n");
 			return 1;
 		}
@@ -128,7 +128,7 @@ int hash_data(struct session_op *sess, int fdc, int chunksize, int alignmask)
 
 int main(void)
 {
-	int fd, i, fdc = -1;
+	int fd, i, fdc = -1, alignmask = 0;
 	struct session_op sess;
 	char keybuf[32];
 #ifdef CIOCGSESSINFO
@@ -161,10 +161,11 @@ int main(void)
 	}
 	printf("requested hash CRYPTO_SHA1, got %s with driver %s\n",
 			siop.hash_info.cra_name, siop.hash_info.cra_driver_name);
+	alignmask = siop.alignmask;
 #endif
 
 	for (i = 256; i <= (64 * 4096); i *= 2) {
-		if (hash_data(&sess, fdc, i, siop.alignmask))
+		if (hash_data(&sess, fdc, i, alignmask))
 			break;
 	}
 
@@ -183,10 +184,11 @@ int main(void)
 	}
 	printf("requested hash CRYPTO_SHA2_256, got %s with driver %s\n",
 			siop.hash_info.cra_name, siop.hash_info.cra_driver_name);
+	alignmask = siop.alignmask;
 #endif
 
 	for (i = 256; i <= (64 * 1024); i *= 2) {
-		if (hash_data(&sess, fdc, i, 0))
+		if (hash_data(&sess, fdc, i, alignmask))
 			break;
 	}
 
diff --git a/drivers/staging/crypto/cryptodev/examples/speed.c b/drivers/staging/crypto/cryptodev/examples/speed.c
index 1d5525ce0c32..59eaf06c5948 100644
--- a/drivers/staging/crypto/cryptodev/examples/speed.c
+++ b/drivers/staging/crypto/cryptodev/examples/speed.c
@@ -80,7 +80,7 @@ int encrypt_data(struct session_op *sess, int fdc, int chunksize, int alignmask)
 	char metric[16];
 
 	if (alignmask) {
-		if (posix_memalign((void **)&buffer, alignmask, chunksize)) {
+		if (posix_memalign((void **)&buffer, alignmask + 1, chunksize)) {
 			printf("posix_memalign() failed!\n");
 			return 1;
 		}
@@ -191,9 +191,17 @@ int main(int argc, char** argv)
 		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 = 256; i <= (64 * 1024); i *= 2) {
-		if (encrypt_data(&sess, fdc, i, 0))
+		if (encrypt_data(&sess, fdc, i, alignmask))
 			break;
 	}
 
-- 
2.1.0

