mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nigel Cunningham <nigel@suspend2.net>
To: linux-kernel@vger.kernel.org
Subject: [Suspend2][ 04/12] [Suspend2] Encrypt a page being written.
Date: Tue, 27 Jun 2006 14:38:17 +1000	[thread overview]
Message-ID: <20060627043816.14437.68373.stgit@nigel.suspend2.net> (raw)
In-Reply-To: <20060627043803.14437.68085.stgit@nigel.suspend2.net>

Add the routine that processes pages being written in the image.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/encryption.c |   51 +++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/kernel/power/encryption.c b/kernel/power/encryption.c
index 98b0114..16a275b 100644
--- a/kernel/power/encryption.c
+++ b/kernel/power/encryption.c
@@ -125,11 +125,13 @@ static int suspend_encrypt_rw_prepare(in
 		return 1;
 	}
 
-	if (!(suspend_encryptor_transform = crypto_alloc_tfm(suspend_encryptor_name,
-					1 << suspend_encryptor_mode))) {
+	suspend_encryptor_transform = crypto_alloc_tfm(suspend_encryptor_name,
+					1 << suspend_encryptor_mode);
+	if (!suspend_encryptor_transform) {
 		printk("Suspend2: Failed to initialise the encryption "
 				"transform (%s, mode %d).\n",
 				suspend_encryptor_name, suspend_encryptor_mode);
+		suspend_encryption_ops.disabled = 1;
 		return 1;
 	}
 
@@ -157,3 +159,48 @@ static int suspend_encrypt_rw_prepare(in
 	return 0;
 }
 
+/* ---- Exported functions ---- */
+
+/* suspend_encrypt_write_chunk()
+ *
+ * Description:	Encrypt a page of data, buffering output and passing on
+ * 		filled pages to the next module in the pipeline.
+ * Arguments:	Buffer_page:	Pointer to a buffer of size PAGE_SIZE, 
+ * 				containing data to be encrypted.
+ * Returns:	0 on success. Otherwise the error is that returned by later
+ * 		modules, -ECHILD if we have a broken pipeline or -EIO if
+ * 		zlib errs.
+ */
+static int suspend_encrypt_write_chunk(struct page *buffer_page)
+{
+	int ret; 
+	unsigned int len;
+	u16 len_written;
+	char *buffer_start;
+	
+	if (!suspend_encryptor_transform)
+		return next_driver->write_chunk(buffer_page);
+
+	buffer_start = kmap(buffer_page);
+	memcpy(page_buffer, buffer_start, PAGE_SIZE);
+	kunmap(buffer_page);
+	
+	bytes_in += PAGE_SIZE;
+
+	len = PAGE_SIZE;
+
+	ret = crypto_cipher_encrypt(suspend_encryptor_transform,
+			suspend_crypt_sg, suspend_crypt_sg, PAGE_SIZE);
+	
+	if (ret) {
+		printk("Encryption failed.\n");
+		return -EIO;
+	}
+	
+	len_written = (u16) len;
+
+	ret = next_driver->write_chunk(virt_to_page(page_buffer));
+
+	return ret;
+}
+

--
Nigel Cunningham		nigel at suspend2 dot net

  parent reply	other threads:[~2006-06-27  4:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-27  4:38 [Suspend2][ 00/12] Encryption support Nigel Cunningham
2006-06-27  4:38 ` [Suspend2][ 01/12] [Suspend2] Encryption support header Nigel Cunningham
2006-06-27  4:38 ` [Suspend2][ 02/12] [Suspend2] Encryption buffer allocation Nigel Cunningham
2006-06-27  4:38 ` [Suspend2][ 03/12] [Suspend2] Encryption rw init & cleanup routines Nigel Cunningham
2006-06-27  4:38 ` Nigel Cunningham [this message]
2006-06-27  4:38 ` [Suspend2][ 05/12] [Suspend2] Prepare to encrypt or decrypt a stream of pages Nigel Cunningham
2006-06-27  4:38 ` [Suspend2][ 06/12] [Suspend2] Decrypt a page in the image Nigel Cunningham
2006-06-27  4:38 ` [Suspend2][ 07/12] [Suspend2] Encryption debug stats Nigel Cunningham
2006-06-27  4:38 ` [Suspend2][ 08/12] [Suspend2] Encryption resources needed Nigel Cunningham
2006-06-27  4:38 ` [Suspend2][ 09/12] [Suspend2] Encryption configuration serialisation Nigel Cunningham
2006-06-27  4:38 ` [Suspend2][ 10/12] [Suspend2] Encryption proc entries Nigel Cunningham
2006-06-27  4:38 ` [Suspend2][ 11/12] [Suspend2] Encryption module accessors structure Nigel Cunningham
2006-06-27  4:38 ` [Suspend2][ 12/12] [Suspend2] Load and unload routines Nigel Cunningham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060627043816.14437.68373.stgit@nigel.suspend2.net \
    --to=nigel@suspend2.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®