From b0d0492c858ba8fe1829e3d358f3aac72e2c89c3 Mon Sep 17 00:00:00 2001
From: Nikos Mavrogiannopoulos <nmav@gnutls.org>
Date: Fri, 6 Jan 2012 22:39:37 +0100
Subject: [PATCH 172/291] cryptodev: updated

---
 drivers/staging/crypto/cryptodev/Makefile  |  2 +-
 drivers/staging/crypto/cryptodev/authenc.c | 59 ++--------------------
 drivers/staging/crypto/cryptodev/util.c    | 80 ++++++++++++++++++++++++++++++
 drivers/staging/crypto/cryptodev/util.h    |  2 +
 drivers/staging/crypto/cryptodev/zc.c      |  1 +
 5 files changed, 88 insertions(+), 56 deletions(-)
 create mode 100644 drivers/staging/crypto/cryptodev/util.c
 create mode 100644 drivers/staging/crypto/cryptodev/util.h

diff --git a/drivers/staging/crypto/cryptodev/Makefile b/drivers/staging/crypto/cryptodev/Makefile
index 67895d816214..e0c005acb86b 100644
--- a/drivers/staging/crypto/cryptodev/Makefile
+++ b/drivers/staging/crypto/cryptodev/Makefile
@@ -2,7 +2,7 @@ KBUILD_CFLAGS += -I$(src)
 KERNEL_DIR = /lib/modules/$(shell uname -r)/build
 VERSION = 1.0
 
-cryptodev-objs = ioctl.o main.o cryptlib.o authenc.o zc.o
+cryptodev-objs = ioctl.o main.o cryptlib.o authenc.o zc.o util.o
 
 obj-m += cryptodev.o
 
diff --git a/drivers/staging/crypto/cryptodev/authenc.c b/drivers/staging/crypto/cryptodev/authenc.c
index 2ad0daad9963..9b2ce0971dd4 100644
--- a/drivers/staging/crypto/cryptodev/authenc.c
+++ b/drivers/staging/crypto/cryptodev/authenc.c
@@ -1,7 +1,9 @@
 /*
  * Driver for /dev/crypto device (aka CryptoDev)
  *
- * Copyright (c) 2011 Nikos Mavrogiannopoulos <nmav@gnutls.org>
+ * Copyright (c) 2011, 2012 OpenSSL Software Foundation, Inc.
+ *
+ * Author: Nikos Mavrogiannopoulos
  *
  * This file is part of linux cryptodev.
  *
@@ -41,6 +43,7 @@
 #include <linux/scatterlist.h>
 #include "cryptodev_int.h"
 #include "zc.h"
+#include "util.h"
 #include "cryptlib.h"
 #include "version.h"
 
@@ -91,60 +94,6 @@ static int get_userbuf_tls(struct csession *ses, struct kernel_crypt_auth_op *kc
 	return 0;
 }
 
-/* Taken from Maxim Levitsky's patch
- */
-static struct scatterlist *sg_advance(struct scatterlist *sg, int consumed)
-{
-	while (consumed >= sg->length) {
-		consumed -= sg->length;
-
-		sg = sg_next(sg);
-		if (!sg)
-			break;
-	}
-
-	WARN_ON(!sg && consumed);
-
-	if (!sg)
-		return NULL;
-
-	sg->offset += consumed;
-	sg->length -= consumed;
-
-	if (sg->offset >= PAGE_SIZE) {
-		struct page *page =
-			nth_page(sg_page(sg), sg->offset / PAGE_SIZE);
-		sg_set_page(sg, page, sg->length, sg->offset % PAGE_SIZE);
-	}
-
-	return sg;
-}
-
-/**
- * sg_copy - copies sg entries from sg_from to sg_to, such
- * as sg_to covers first 'len' bytes from sg_from.
- */
-static int sg_copy(struct scatterlist *sg_from, struct scatterlist *sg_to, int len)
-{
-	while (len > sg_from->length) {
-		len -= sg_from->length;
-
-		sg_set_page(sg_to, sg_page(sg_from),
-				sg_from->length, sg_from->offset);
-
-		sg_to = sg_next(sg_to);
-		sg_from = sg_next(sg_from);
-
-		if (len && (!sg_from || !sg_to))
-			return -ENOMEM;
-	}
-
-	if (len)
-		sg_set_page(sg_to, sg_page(sg_from),
-				len, sg_from->offset);
-	sg_mark_end(sg_to);
-	return 0;
-}
 
 #define MAX_SRTP_AUTH_DATA_DIFF 256
 
diff --git a/drivers/staging/crypto/cryptodev/util.c b/drivers/staging/crypto/cryptodev/util.c
new file mode 100644
index 000000000000..9eba4836ba6a
--- /dev/null
+++ b/drivers/staging/crypto/cryptodev/util.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2011 Maxim Levitsky
+ *
+ * This file is part of linux cryptodev.
+ *
+ * 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 Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include <crypto/scatterwalk.h>
+#include <linux/scatterlist.h>
+#include "util.h"
+
+/* These were taken from Maxim Levitsky's patch to lkml.
+ */
+struct scatterlist *sg_advance(struct scatterlist *sg, int consumed)
+{
+	while (consumed >= sg->length) {
+		consumed -= sg->length;
+
+		sg = sg_next(sg);
+		if (!sg)
+			break;
+	}
+
+	WARN_ON(!sg && consumed);
+
+	if (!sg)
+		return NULL;
+
+	sg->offset += consumed;
+	sg->length -= consumed;
+
+	if (sg->offset >= PAGE_SIZE) {
+		struct page *page =
+			nth_page(sg_page(sg), sg->offset / PAGE_SIZE);
+		sg_set_page(sg, page, sg->length, sg->offset % PAGE_SIZE);
+	}
+
+	return sg;
+}
+
+/**
+ * sg_copy - copies sg entries from sg_from to sg_to, such
+ * as sg_to covers first 'len' bytes from sg_from.
+ */
+int sg_copy(struct scatterlist *sg_from, struct scatterlist *sg_to, int len)
+{
+	while (len > sg_from->length) {
+		len -= sg_from->length;
+
+		sg_set_page(sg_to, sg_page(sg_from),
+				sg_from->length, sg_from->offset);
+
+		sg_to = sg_next(sg_to);
+		sg_from = sg_next(sg_from);
+
+		if (len && (!sg_from || !sg_to))
+			return -ENOMEM;
+	}
+
+	if (len)
+		sg_set_page(sg_to, sg_page(sg_from),
+				len, sg_from->offset);
+	sg_mark_end(sg_to);
+	return 0;
+}
+
diff --git a/drivers/staging/crypto/cryptodev/util.h b/drivers/staging/crypto/cryptodev/util.h
new file mode 100644
index 000000000000..204de7584c25
--- /dev/null
+++ b/drivers/staging/crypto/cryptodev/util.h
@@ -0,0 +1,2 @@
+int sg_copy(struct scatterlist *sg_from, struct scatterlist *sg_to, int len);
+struct scatterlist *sg_advance(struct scatterlist *sg, int consumed);
diff --git a/drivers/staging/crypto/cryptodev/zc.c b/drivers/staging/crypto/cryptodev/zc.c
index cf1aa25782de..778593fbc2e6 100644
--- a/drivers/staging/crypto/cryptodev/zc.c
+++ b/drivers/staging/crypto/cryptodev/zc.c
@@ -3,6 +3,7 @@
  *
  * Copyright (c) 2009-2011 Nikos Mavrogiannopoulos <nmav@gnutls.org>
  * Copyright (c) 2010 Phil Sutter
+ * Copyright (c) 2011, 2012 OpenSSL Software Foundation, Inc.
  *
  * This file is part of linux cryptodev.
  *
-- 
2.1.0

