From b5a705a206c538358665bb90b65658297e378f0f Mon Sep 17 00:00:00 2001
From: Nikos Mavrogiannopoulos <nmav@gnutls.org>
Date: Sun, 11 Dec 2011 14:13:17 +0100
Subject: [PATCH 169/291] cryptodev: cleanups

---
 .../crypto/cryptodev/tests/cipher-aead-srtp.c      |  6 ------
 .../staging/crypto/cryptodev/tests/cipher-aead.c   | 23 ++++++++++++----------
 .../staging/crypto/cryptodev/tests/cipher-gcm.c    | 15 +++++---------
 3 files changed, 18 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/crypto/cryptodev/tests/cipher-aead-srtp.c b/drivers/staging/crypto/cryptodev/tests/cipher-aead-srtp.c
index d15fc3ee4cd8..5a6836a60ca7 100644
--- a/drivers/staging/crypto/cryptodev/tests/cipher-aead-srtp.c
+++ b/drivers/staging/crypto/cryptodev/tests/cipher-aead-srtp.c
@@ -27,7 +27,6 @@ get_sha1_hmac(int cfd, void* key, int key_size, void* data, int data_size, void*
 {
 	struct session_op sess;
 	struct crypt_op cryp;
-	int i;
 
 	memset(&sess, 0, sizeof(sess));
 	memset(&cryp, 0, sizeof(cryp));
@@ -84,7 +83,6 @@ test_crypto(int cfd)
 	unsigned char tag[20];
 	unsigned char mackey[] = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
 	int mackey_len = 16;
-	int pad, i;
 
 	struct session_op sess;
 	struct crypt_op co;
@@ -234,11 +232,9 @@ test_encrypt_decrypt(int cfd)
 	char ciphertext_raw[DATA_SIZE + 63], *ciphertext;
 	char iv[BLOCK_SIZE];
 	char key[KEY_SIZE];
-	unsigned char sha1mac[20];
 	unsigned char tag[20];
 	unsigned char mackey[] = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
 	int mackey_len = 16;
-	int pad, i;
 
 	struct session_op sess;
 	struct crypt_auth_op cao;
@@ -384,11 +380,9 @@ test_encrypt_decrypt_error(int cfd, int err)
 	char ciphertext_raw[DATA_SIZE + 63], *ciphertext;
 	char iv[BLOCK_SIZE];
 	char key[KEY_SIZE];
-	unsigned char sha1mac[20];
 	unsigned char tag[20];
 	unsigned char mackey[] = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
 	int mackey_len = 16;
-	int pad, i;
 
 	struct session_op sess;
 	struct crypt_auth_op cao;
diff --git a/drivers/staging/crypto/cryptodev/tests/cipher-aead.c b/drivers/staging/crypto/cryptodev/tests/cipher-aead.c
index ab29aeca8109..40470304dc7c 100644
--- a/drivers/staging/crypto/cryptodev/tests/cipher-aead.c
+++ b/drivers/staging/crypto/cryptodev/tests/cipher-aead.c
@@ -25,7 +25,6 @@ get_sha1_hmac(int cfd, void* key, int key_size, void* data1, int data1_size, voi
 {
 	struct session_op sess;
 	struct crypt_op cryp;
-	int i;
 
 	memset(&sess, 0, sizeof(sess));
 	memset(&cryp, 0, sizeof(cryp));
@@ -114,7 +113,7 @@ test_crypto(int cfd)
 	/* Get crypto session for AES128 */
 	sess.cipher = CRYPTO_AES_CBC;
 	sess.keylen = KEY_SIZE;
-	sess.key = key;
+	sess.key = (void*)key;
 
 	sess.mac = CRYPTO_SHA1_HMAC;
 	sess.mackeylen = 16;
@@ -147,14 +146,14 @@ test_crypto(int cfd)
 		return 1;
 	}
 
-	//memcpy(ciphertext, plaintext, DATA_SIZE);
+	memcpy(ciphertext, plaintext, DATA_SIZE);
 
 	/* Encrypt data.in to data.encrypted */
 	cao.ses = sess.ses;
 	cao.auth_src = auth;
 	cao.auth_len = sizeof(auth);
 	cao.len = DATA_SIZE;
-	cao.src = plaintext;
+	cao.src = ciphertext;
 	cao.dst = ciphertext;
 	cao.iv = iv;
 	cao.op = COP_ENCRYPT;
@@ -253,7 +252,7 @@ test_encrypt_decrypt(int cfd)
 	char key[KEY_SIZE];
 	char auth[AUTH_SIZE];
 	unsigned char sha1mac[20];
-	int pad, i, enc_len;
+	int enc_len;
 
 	struct session_op sess;
 	struct crypt_op co;
@@ -306,13 +305,15 @@ test_encrypt_decrypt(int cfd)
 		return 1;
 	}
 
+	memcpy(ciphertext, plaintext, DATA_SIZE);
+
 	/* Encrypt data.in to data.encrypted */
 	cao.ses = sess.ses;
-	cao.auth_src = auth;
+	cao.auth_src = (void*)auth;
 	cao.auth_len = sizeof(auth);
 	cao.len = DATA_SIZE;
-	cao.src = plaintext;
-	cao.dst = ciphertext;
+	cao.src = (void*)ciphertext;
+	cao.dst = (void*)ciphertext;
 	cao.iv = iv;
 	cao.op = COP_ENCRYPT;
 	cao.flags = COP_FLAG_AEAD_TLS_TYPE;
@@ -406,7 +407,7 @@ test_encrypt_decrypt_error(int cfd, int err)
 	char key[KEY_SIZE];
 	char auth[AUTH_SIZE];
 	unsigned char sha1mac[20];
-	int pad, i, enc_len;
+	int enc_len;
 
 	struct session_op sess;
 	struct crypt_op co;
@@ -458,13 +459,15 @@ test_encrypt_decrypt_error(int cfd, int err)
 		fprintf(stderr, "SHA1 MAC failed\n");
 		return 1;
 	}
+	
+	memcpy(ciphertext, plaintext, DATA_SIZE);
 
 	/* Encrypt data.in to data.encrypted */
 	cao.ses = sess.ses;
 	cao.auth_src = auth;
 	cao.auth_len = sizeof(auth);
 	cao.len = DATA_SIZE;
-	cao.src = plaintext;
+	cao.src = ciphertext;
 	cao.dst = ciphertext;
 	cao.iv = iv;
 	cao.op = COP_ENCRYPT;
diff --git a/drivers/staging/crypto/cryptodev/tests/cipher-gcm.c b/drivers/staging/crypto/cryptodev/tests/cipher-gcm.c
index 9b5f4f947075..bf74d4dff53a 100644
--- a/drivers/staging/crypto/cryptodev/tests/cipher-gcm.c
+++ b/drivers/staging/crypto/cryptodev/tests/cipher-gcm.c
@@ -91,16 +91,11 @@ struct aes_gcm_vectors_st aes_gcm_vectors[] = {
  */
 static int test_crypto(int cfd)
 {
-	char iv[BLOCK_SIZE];
-	unsigned char tag[16];
-	int pad, i;
+	int i;
 	int8_t tmp[128];
 
 	struct session_op sess;
 	struct crypt_auth_op cao;
-#ifdef CIOCGSESSINFO
-	struct session_info_op siop;
-#endif
 
 	/* Get crypto session for AES128 */
 
@@ -194,8 +189,7 @@ static int test_encrypt_decrypt(int cfd)
 	char iv[BLOCK_SIZE];
 	char key[KEY_SIZE];
 	char auth[AUTH_SIZE];
-	unsigned char sha1mac[20];
-	int pad, i, enc_len;
+	int enc_len;
 
 	struct session_op sess;
 	struct crypt_auth_op cao;
@@ -342,7 +336,7 @@ static int test_encrypt_decrypt_error(int cfd, int err)
 	char iv[BLOCK_SIZE];
 	char key[KEY_SIZE];
 	char auth[AUTH_SIZE];
-	int pad, i, enc_len;
+	int enc_len;
 
 	struct session_op sess;
 	struct crypt_op co;
@@ -397,13 +391,14 @@ static int test_encrypt_decrypt_error(int cfd, int err)
 	ciphertext = ciphertext_raw;
 #endif
 	memset(plaintext, 0x15, DATA_SIZE);
+	memcpy(ciphertext, plaintext, DATA_SIZE);
 
 	/* Encrypt data.in to data.encrypted */
 	cao.ses = sess.ses;
 	cao.auth_src = auth;
 	cao.auth_len = sizeof(auth);
 	cao.len = DATA_SIZE;
-	cao.src = plaintext;
+	cao.src = ciphertext;
 	cao.dst = ciphertext;
 	cao.iv = iv;
 	cao.op = COP_ENCRYPT;
-- 
2.1.0

