From 66976d5f30e050eafcbf891f79bdf394a30ae940 Mon Sep 17 00:00:00 2001
From: Phil Sutter <phil.sutter@viprinet.com>
Date: Fri, 17 Dec 2010 18:52:33 +0100
Subject: [PATCH 122/291] cryptodev: cipher,

In order to stay compatible with the original BSD interface, one can
check for existence of the CIOCGSESSINFO define, like done here.

Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
---
 drivers/staging/crypto/cryptodev/examples/cipher.c | 36 ++++++++++++++++
 drivers/staging/crypto/cryptodev/examples/hmac.c   | 48 ++++++++++++++++++++++
 2 files changed, 84 insertions(+)

diff --git a/drivers/staging/crypto/cryptodev/examples/cipher.c b/drivers/staging/crypto/cryptodev/examples/cipher.c
index 4ad1ec980512..9f19c5efee50 100644
--- a/drivers/staging/crypto/cryptodev/examples/cipher.c
+++ b/drivers/staging/crypto/cryptodev/examples/cipher.c
@@ -25,6 +25,9 @@ test_crypto(int cfd)
 	char key[KEY_SIZE];
 
 	struct session_op sess;
+#ifdef CIOCGSESSINFO
+	struct session_info_op siop;
+#endif
 	struct crypt_op cryp;
 
 	memset(&sess, 0, sizeof(sess));
@@ -42,6 +45,16 @@ test_crypto(int cfd)
 		return 1;
 	}
 
+#ifdef CIOCGSESSINFO
+	siop.ses = sess.ses;
+	if (ioctl(cfd, CIOCGSESSINFO, &siop)) {
+		perror("ioctl(CIOCGSESSINFO)");
+		return 1;
+	}
+	printf("requested cipher CRYPTO_AES_CBC, got %s with driver %s\n",
+			siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name);
+#endif
+
 	plaintext = (char *)(((unsigned long)plaintext_raw + sess.alignmask) & ~sess.alignmask);
 	ciphertext = (char *)(((unsigned long)ciphertext_raw + sess.alignmask) & ~sess.alignmask);
 	memset(plaintext, 0x15, DATA_SIZE);
@@ -68,6 +81,16 @@ test_crypto(int cfd)
 		return 1;
 	}
 
+#ifdef CIOCGSESSINFO
+	siop.ses = sess.ses;
+	if (ioctl(cfd, CIOCGSESSINFO, &siop)) {
+		perror("ioctl(CIOCGSESSINFO)");
+		return 1;
+	}
+	printf("requested cipher CRYPTO_AES_CBC, got %s with driver %s\n",
+			siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name);
+#endif
+
 	/* Decrypt data.encrypted to data.decrypted */
 	cryp.ses = sess.ses;
 	cryp.len = DATA_SIZE;
@@ -124,6 +147,9 @@ static int test_aes(int cfd)
 	char key2[KEY_SIZE];
 
 	struct session_op sess;
+#ifdef CIOCGSESSINFO
+	struct session_info_op siop;
+#endif
 	struct crypt_op cryp;
 
 	memset(&sess, 0, sizeof(sess));
@@ -176,6 +202,16 @@ static int test_aes(int cfd)
 		return 1;
 	}
 
+#ifdef CIOCGSESSINFO
+	siop.ses = sess.ses;
+	if (ioctl(cfd, CIOCGSESSINFO, &siop)) {
+		perror("ioctl(CIOCGSESSINFO)");
+		return 1;
+	}
+	printf("requested cipher CRYPTO_AES_CBC, got %s with driver %s\n",
+			siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name);
+#endif
+
 	plaintext2 = (char *)(((unsigned long)plaintext2_raw + sess.alignmask) & ~sess.alignmask);
 	memcpy(plaintext2, plaintext2_data, BLOCK_SIZE);
 
diff --git a/drivers/staging/crypto/cryptodev/examples/hmac.c b/drivers/staging/crypto/cryptodev/examples/hmac.c
index 3a308c965a27..549e9462e483 100644
--- a/drivers/staging/crypto/cryptodev/examples/hmac.c
+++ b/drivers/staging/crypto/cryptodev/examples/hmac.c
@@ -29,6 +29,9 @@ test_crypto(int cfd)
 			key[KEY_SIZE];
 	} data;
 	struct session_op sess;
+#ifdef CIOCGSESSINFO
+	struct session_info_op siop;
+#endif
 	struct crypt_op cryp;
 	uint8_t mac[AALG_MAX_RESULT_LEN];
 	uint8_t oldmac[AALG_MAX_RESULT_LEN];
@@ -52,6 +55,16 @@ test_crypto(int cfd)
 		return 1;
 	}
 
+#ifdef CIOCGSESSINFO
+	siop.ses = sess.ses;
+	if (ioctl(cfd, CIOCGSESSINFO, &siop)) {
+		perror("ioctl(CIOCGSESSINFO)");
+		return 1;
+	}
+	printf("requested mac CRYPTO_SHA1, got %s with driver %s\n",
+			siop.hash_info.cra_name, siop.hash_info.cra_driver_name);
+#endif
+
 	cryp.ses = sess.ses;
 	cryp.len = sizeof("what do ya want for nothing?")-1;
 	cryp.src = "what do ya want for nothing?";
@@ -85,6 +98,16 @@ test_crypto(int cfd)
 		return 1;
 	}
 
+#ifdef CIOCGSESSINFO
+	siop.ses = sess.ses;
+	if (ioctl(cfd, CIOCGSESSINFO, &siop)) {
+		perror("ioctl(CIOCGSESSINFO)");
+		return 1;
+	}
+	printf("requested mac CRYPTO_MD5_HMAC, got %s with driver %s\n",
+			siop.hash_info.cra_name, siop.hash_info.cra_driver_name);
+#endif
+
 	cryp.ses = sess.ses;
 	cryp.len = sizeof("what do ya want for nothing?")-1;
 	cryp.src = "what do ya want for nothing?";
@@ -118,6 +141,18 @@ test_crypto(int cfd)
 		return 1;
 	}
 
+#ifdef CIOCGSESSINFO
+	siop.ses = sess.ses;
+	if (ioctl(cfd, CIOCGSESSINFO, &siop)) {
+		perror("ioctl(CIOCGSESSINFO)");
+		return 1;
+	}
+	printf("requested cipher CRYPTO_AES_CBC and mac CRYPTO_SHA1_HMAC,"
+	       " got cipher %s with driver %s and hash %s with driver %s\n",
+			siop.cipher_info.cra_name, siop.cipher_info.cra_driver_name,
+			siop.hash_info.cra_name, siop.hash_info.cra_driver_name);
+#endif
+
 	/* Encrypt data.in to data.encrypted */
 	cryp.ses = sess.ses;
 	cryp.len = sizeof(data.in);
@@ -170,6 +205,9 @@ static int
 test_extras(int cfd)
 {
 	struct session_op sess;
+#ifdef CIOCGSESSINFO
+	struct session_info_op siop;
+#endif
 	struct crypt_op cryp;
 	uint8_t mac[AALG_MAX_RESULT_LEN];
 	uint8_t oldmac[AALG_MAX_RESULT_LEN];
@@ -193,6 +231,16 @@ test_extras(int cfd)
 		return 1;
 	}
 
+#ifdef CIOCGSESSINFO
+	siop.ses = sess.ses;
+	if (ioctl(cfd, CIOCGSESSINFO, &siop)) {
+		perror("ioctl(CIOCGSESSINFO)");
+		return 1;
+	}
+	printf("requested mac CRYPTO_SHA1, got %s with driver %s\n",
+			siop.hash_info.cra_name, siop.hash_info.cra_driver_name);
+#endif
+
 	cryp.ses = sess.ses;
 	cryp.len = sizeof("what do")-1;
 	cryp.src = "what do";
-- 
2.1.0

