* [Suspend2][ 00/12] Encryption support.
@ 2006-06-27 4:38 Nigel Cunningham
2006-06-27 4:38 ` [Suspend2][ 01/12] [Suspend2] Encryption support header Nigel Cunningham
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:38 UTC (permalink / raw)
To: linux-kernel
Routines to implement Suspend2 image encryption support. This
is achieved via the cryptoapi plugins. We let the user configure
every aspect. They just need to set the appropriate /proc entries
and have the modules built-in or loadable from an initrd/ramfs
for resume-time.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Suspend2][ 01/12] [Suspend2] Encryption support header
2006-06-27 4:38 [Suspend2][ 00/12] Encryption support Nigel Cunningham
@ 2006-06-27 4:38 ` Nigel Cunningham
2006-06-27 4:38 ` [Suspend2][ 02/12] [Suspend2] Encryption buffer allocation Nigel Cunningham
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:38 UTC (permalink / raw)
To: linux-kernel
Add the header for the encryption support file.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/encryption.c | 47 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/kernel/power/encryption.c b/kernel/power/encryption.c
new file mode 100644
index 0000000..a90d3ca
--- /dev/null
+++ b/kernel/power/encryption.c
@@ -0,0 +1,47 @@
+/*
+ * kernel/power/suspend_core/encryption.c
+ *
+ * Copyright (C) 2003-2006 Nigel Cunningham <nigel@suspend2.net>
+ *
+ * This file is released under the GPLv2.
+ *
+ * This file contains data encryption routines for suspend,
+ * using cryptoapi transforms.
+ *
+ * ToDo:
+ * - Apply min/max_keysize the cipher changes.
+ * - Test.
+ */
+
+#include <linux/suspend.h>
+#include <linux/module.h>
+#include <linux/highmem.h>
+#include <linux/vmalloc.h>
+#include <linux/crypto.h>
+#include <asm/scatterlist.h>
+
+#include "suspend2.h"
+#include "modules.h"
+#include "proc.h"
+#include "suspend2_common.h"
+#include "io.h"
+
+#define S2C_WRITE 0
+#define S2C_READ 1
+
+static struct suspend_module_ops suspend_encryption_ops;
+static struct suspend_module_ops *next_driver;
+
+static char suspend_encryptor_name[32];
+static struct crypto_tfm *suspend_encryptor_transform;
+static char suspend_encryptor_key[256];
+static int suspend_key_len;
+static char suspend_encryptor_iv[256];
+static int suspend_encryptor_mode;
+static int suspend_encryptor_save_key_and_iv;
+
+static u8 *page_buffer = NULL;
+static unsigned int bufofs;
+
+static struct scatterlist suspend_crypt_sg[PAGE_SIZE/8];
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Suspend2][ 02/12] [Suspend2] Encryption buffer allocation.
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 ` Nigel Cunningham
2006-06-27 4:38 ` [Suspend2][ 03/12] [Suspend2] Encryption rw init & cleanup routines Nigel Cunningham
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:38 UTC (permalink / raw)
To: linux-kernel
Add support for allocating and freeing buffers used for encryption.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/encryption.c | 51 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/kernel/power/encryption.c b/kernel/power/encryption.c
index a90d3ca..45d325d 100644
--- a/kernel/power/encryption.c
+++ b/kernel/power/encryption.c
@@ -45,3 +45,54 @@ static unsigned int bufofs;
static struct scatterlist suspend_crypt_sg[PAGE_SIZE/8];
+/* ---- Local buffer management ---- */
+
+/* allocate_local_buffer
+ *
+ * Description: Allocates a page of memory for buffering output.
+ * Returns: Int: Zero if successful, -ENONEM otherwise.
+ */
+static int allocate_local_buffer(void)
+{
+ if (!page_buffer) {
+ int i, remainder;
+
+ page_buffer = (char *) get_zeroed_page(GFP_ATOMIC);
+
+ if (!page_buffer) {
+ printk(KERN_ERR
+ "Failed to allocate the page buffer for "
+ "suspend2 encryption driver.\n");
+ return -ENOMEM;
+ }
+
+ for (i=0; i < (PAGE_SIZE / suspend_key_len); i++) {
+ suspend_crypt_sg[i].page = virt_to_page(page_buffer);
+ suspend_crypt_sg[i].offset = suspend_key_len * i;
+ suspend_crypt_sg[i].length = suspend_key_len;
+ }
+
+ remainder = PAGE_SIZE % suspend_key_len;
+
+ if (remainder) {
+ suspend_crypt_sg[i].page = virt_to_page(page_buffer);
+ suspend_crypt_sg[i].offset = suspend_key_len * i;
+ suspend_crypt_sg[i].length = remainder;
+ }
+ }
+
+ return 0;
+}
+
+/* free_local_buffer
+ *
+ * Description: Frees memory allocated for buffering output.
+ */
+static void free_local_buffer(void)
+{
+ if (page_buffer)
+ free_page((unsigned long) page_buffer);
+
+ page_buffer = NULL;
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Suspend2][ 03/12] [Suspend2] Encryption rw init & cleanup routines.
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 ` Nigel Cunningham
2006-06-27 4:38 ` [Suspend2][ 04/12] [Suspend2] Encrypt a page being written Nigel Cunningham
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:38 UTC (permalink / raw)
To: linux-kernel
Add routines for preparing to read or write an image, and cleaning up
afterwards.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/encryption.c | 61 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/kernel/power/encryption.c b/kernel/power/encryption.c
index 45d325d..98b0114 100644
--- a/kernel/power/encryption.c
+++ b/kernel/power/encryption.c
@@ -96,3 +96,64 @@ static void free_local_buffer(void)
page_buffer = NULL;
}
+/* suspend_encrypt_rw_cleanup
+ *
+ * Description: Frees memory allocated for our labours.
+ */
+static int suspend_encrypt_rw_cleanup(int rw)
+{
+ if (suspend_encryptor_transform) {
+ crypto_free_tfm(suspend_encryptor_transform);
+ suspend_encryptor_transform = NULL;
+ }
+
+ free_local_buffer();
+
+ return 0;
+}
+
+/* suspend_crypto_prepare
+ *
+ * Description: Prepare to do some work by allocating buffers and transforms.
+ * Returns: Int: Zero if successful, 1 otherwise.
+ */
+static int suspend_encrypt_rw_prepare(int rw)
+{
+ if (!*suspend_encryptor_name) {
+ printk("Suspend2: Encryptor enabled but no name set.\n");
+ suspend_encryption_ops.disabled = 1;
+ return 1;
+ }
+
+ if (!(suspend_encryptor_transform = crypto_alloc_tfm(suspend_encryptor_name,
+ 1 << suspend_encryptor_mode))) {
+ printk("Suspend2: Failed to initialise the encryption "
+ "transform (%s, mode %d).\n",
+ suspend_encryptor_name, suspend_encryptor_mode);
+ return 1;
+ }
+
+ if (rw == READ)
+ bufofs = PAGE_SIZE;
+ else
+ bufofs = 0;
+
+ suspend_key_len = strlen(suspend_encryptor_key);
+
+ if (crypto_cipher_setkey(suspend_encryptor_transform, suspend_encryptor_key,
+ suspend_key_len)) {
+ printk("%d is an invalid key length for cipher %s.\n",
+ suspend_key_len,
+ suspend_encryptor_name);
+ return 1;
+ }
+
+ if (rw != READ) {
+ crypto_cipher_set_iv(suspend_encryptor_transform,
+ suspend_encryptor_iv,
+ crypto_tfm_alg_ivsize(suspend_encryptor_transform));
+ }
+
+ return 0;
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Suspend2][ 04/12] [Suspend2] Encrypt a page being written.
2006-06-27 4:38 [Suspend2][ 00/12] Encryption support Nigel Cunningham
` (2 preceding siblings ...)
2006-06-27 4:38 ` [Suspend2][ 03/12] [Suspend2] Encryption rw init & cleanup routines Nigel Cunningham
@ 2006-06-27 4:38 ` Nigel Cunningham
2006-06-27 4:38 ` [Suspend2][ 05/12] [Suspend2] Prepare to encrypt or decrypt a stream of pages Nigel Cunningham
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:38 UTC (permalink / raw)
To: linux-kernel
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
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Suspend2][ 05/12] [Suspend2] Prepare to encrypt or decrypt a stream of pages.
2006-06-27 4:38 [Suspend2][ 00/12] Encryption support Nigel Cunningham
` (3 preceding siblings ...)
2006-06-27 4:38 ` [Suspend2][ 04/12] [Suspend2] Encrypt a page being written Nigel Cunningham
@ 2006-06-27 4:38 ` Nigel Cunningham
2006-06-27 4:38 ` [Suspend2][ 06/12] [Suspend2] Decrypt a page in the image Nigel Cunningham
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:38 UTC (permalink / raw)
To: linux-kernel
This routine adds initialisation code for encrypting or decrypting a stream
of pages in the image.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/encryption.c | 34 ++++++++++++++++++++++++++++++++++
1 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/kernel/power/encryption.c b/kernel/power/encryption.c
index 16a275b..9b7dd93 100644
--- a/kernel/power/encryption.c
+++ b/kernel/power/encryption.c
@@ -204,3 +204,37 @@ static int suspend_encrypt_write_chunk(s
return ret;
}
+/* rw_init()
+ *
+ * Description: Prepare to read a new stream of data.
+ * Arguments: int: Section of image about to be read.
+ * Returns: int: Zero on success, error number otherwise.
+ */
+static int suspend_encrypt_rw_init(int rw, int stream_number)
+{
+ int result;
+
+ next_driver = suspend_get_next_filter(&suspend_encryption_ops);
+
+ if (!next_driver) {
+ printk("Encryption Driver: Argh! I'm at the end of the pipeline!");
+ return -ECHILD;
+ }
+
+ if ((result = suspend_encrypt_rw_prepare(rw))) {
+ set_result_state(SUSPEND_ENCRYPTION_SETUP_FAILED);
+ suspend_encrypt_rw_cleanup(rw);
+ return result;
+ }
+
+ if ((result = allocate_local_buffer()))
+ return result;
+
+ if (rw == WRITE && stream_number == 2)
+ bytes_in = bytes_out = 0;
+
+ bufofs = (rw == READ) ? PAGE_SIZE : 0;
+
+ return 0;
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Suspend2][ 06/12] [Suspend2] Decrypt a page in the image.
2006-06-27 4:38 [Suspend2][ 00/12] Encryption support Nigel Cunningham
` (4 preceding siblings ...)
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 ` Nigel Cunningham
2006-06-27 4:38 ` [Suspend2][ 07/12] [Suspend2] Encryption debug stats Nigel Cunningham
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:38 UTC (permalink / raw)
To: linux-kernel
Add support for decrypting a page being read from the storage.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/encryption.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/kernel/power/encryption.c b/kernel/power/encryption.c
index 9b7dd93..cd26e84 100644
--- a/kernel/power/encryption.c
+++ b/kernel/power/encryption.c
@@ -238,3 +238,44 @@ static int suspend_encrypt_rw_init(int r
return 0;
}
+/* suspend_encrypt_read_chunk()
+ *
+ * Description: Retrieve data from later modules and deencrypt it until the
+ * input buffer is filled.
+ * Arguments: Buffer_start: Pointer to a buffer of size PAGE_SIZE.
+ * Sync: Whether the previous module (or core) wants its
+ * data synchronously.
+ * Returns: Zero if successful. Error condition from me or from downstream
+ * on failure.
+ */
+static int suspend_encrypt_read_chunk(struct page *buffer_page, int sync)
+{
+ int ret;
+ char *buffer_start;
+
+ if (!suspend_encryptor_transform)
+ return next_driver->read_chunk(buffer_page, sync);
+
+ /*
+ * All our reads must be synchronous - we can't deencrypt
+ * data that hasn't been read yet.
+ */
+
+ if ((ret = next_driver->read_chunk(
+ virt_to_page(page_buffer), SUSPEND_SYNC)) < 0) {
+ printk("Failed to read an encrypted block.\n");
+ return ret;
+ }
+
+ ret = crypto_cipher_decrypt(suspend_encryptor_transform,
+ suspend_crypt_sg, suspend_crypt_sg, PAGE_SIZE);
+
+ if (ret)
+ printk("Decrypt function returned %d.\n", ret);
+
+ buffer_start = kmap(buffer_page);
+ memcpy(buffer_start, page_buffer, PAGE_SIZE);
+ kunmap(buffer_page);
+ return ret;
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Suspend2][ 07/12] [Suspend2] Encryption debug stats.
2006-06-27 4:38 [Suspend2][ 00/12] Encryption support Nigel Cunningham
` (5 preceding siblings ...)
2006-06-27 4:38 ` [Suspend2][ 06/12] [Suspend2] Decrypt a page in the image Nigel Cunningham
@ 2006-06-27 4:38 ` Nigel Cunningham
2006-06-27 4:38 ` [Suspend2][ 08/12] [Suspend2] Encryption resources needed Nigel Cunningham
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:38 UTC (permalink / raw)
To: linux-kernel
If encryption is enabled, add a message to the debug information to
indicate that it is enabled and which algorithm is being used.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/encryption.c | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/kernel/power/encryption.c b/kernel/power/encryption.c
index cd26e84..25db7ba 100644
--- a/kernel/power/encryption.c
+++ b/kernel/power/encryption.c
@@ -279,3 +279,21 @@ static int suspend_encrypt_read_chunk(st
return ret;
}
+/* suspend_encrypt_print_debug_stats
+ *
+ * Description: Print information to be recorded for debugging purposes into a
+ * buffer.
+ * Arguments: buffer: Pointer to a buffer into which the debug info will be
+ * printed.
+ * size: Size of the buffer.
+ * Returns: Number of characters written to the buffer.
+ */
+static int suspend_encrypt_print_debug_stats(char *buffer, int size)
+{
+ int len;
+
+ len = snprintf_used(buffer, size, "- Encryptor %s enabled.\n",
+ suspend_encryptor_name);
+ return len;
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Suspend2][ 08/12] [Suspend2] Encryption resources needed.
2006-06-27 4:38 [Suspend2][ 00/12] Encryption support Nigel Cunningham
` (6 preceding siblings ...)
2006-06-27 4:38 ` [Suspend2][ 07/12] [Suspend2] Encryption debug stats Nigel Cunningham
@ 2006-06-27 4:38 ` Nigel Cunningham
2006-06-27 4:38 ` [Suspend2][ 09/12] [Suspend2] Encryption configuration serialisation Nigel Cunningham
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:38 UTC (permalink / raw)
To: linux-kernel
Add routines to return the amount of memory and header storage needed for
the encryption module.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/encryption.c | 20 ++++++++++++++++++++
1 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/kernel/power/encryption.c b/kernel/power/encryption.c
index 25db7ba..d12eb47 100644
--- a/kernel/power/encryption.c
+++ b/kernel/power/encryption.c
@@ -297,3 +297,23 @@ static int suspend_encrypt_print_debug_s
return len;
}
+/* encryption_memory_needed
+ *
+ * Description: Tell the caller how much memory we need to operate during
+ * suspend/resume.
+ * Returns: Unsigned long. Maximum number of bytes of memory required for
+ * operation.
+ */
+static unsigned long suspend_encrypt_memory_needed(void)
+{
+ return PAGE_SIZE;
+}
+
+static unsigned long suspend_encrypt_storage_needed(void)
+{
+ return 4 + strlen(suspend_encryptor_name) +
+ (suspend_encryptor_save_key_and_iv ?
+ (4 + strlen(suspend_encryptor_key) +
+ strlen(suspend_encryptor_iv)) : 0);
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Suspend2][ 09/12] [Suspend2] Encryption configuration serialisation.
2006-06-27 4:38 [Suspend2][ 00/12] Encryption support Nigel Cunningham
` (7 preceding siblings ...)
2006-06-27 4:38 ` [Suspend2][ 08/12] [Suspend2] Encryption resources needed Nigel Cunningham
@ 2006-06-27 4:38 ` Nigel Cunningham
2006-06-27 4:38 ` [Suspend2][ 10/12] [Suspend2] Encryption proc entries Nigel Cunningham
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:38 UTC (permalink / raw)
To: linux-kernel
Add routines to read and write the encryption module configuration in an
image header.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/encryption.c | 83 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 83 insertions(+), 0 deletions(-)
diff --git a/kernel/power/encryption.c b/kernel/power/encryption.c
index d12eb47..1664b82 100644
--- a/kernel/power/encryption.c
+++ b/kernel/power/encryption.c
@@ -316,4 +316,87 @@ static unsigned long suspend_encrypt_sto
(4 + strlen(suspend_encryptor_key) +
strlen(suspend_encryptor_iv)) : 0);
}
+
+/* suspend_encrypt_save_config_info
+ *
+ * Description: Save informaton needed when reloading the image at resume time.
+ * Arguments: Buffer: Pointer to a buffer of size PAGE_SIZE.
+ * Returns: Number of bytes used for saving our data.
+ */
+static int suspend_encrypt_save_config_info(char *buffer)
+{
+ int buf_offset, str_size;
+ str_size = strlen(suspend_encryptor_name);
+ *buffer = (char) str_size;
+ strncpy(buffer + 1, suspend_encryptor_name, str_size + 1);
+ buf_offset = str_size + 2;
+
+ *(buffer + buf_offset) = (char) suspend_encryptor_mode;
+ buf_offset++;
+
+ *(buffer + buf_offset) = (char) suspend_encryptor_save_key_and_iv;
+ buf_offset++;
+
+ if (suspend_encryptor_save_key_and_iv) {
+
+ str_size = strlen(suspend_encryptor_key);
+ *(buffer + buf_offset) = (char) str_size;
+ strncpy(buffer + buf_offset + 1, suspend_encryptor_key, str_size + 1);
+
+ buf_offset+= str_size + 2;
+
+ str_size = strlen(suspend_encryptor_iv);
+ *(buffer + buf_offset) = (char) str_size;
+ strncpy(buffer + buf_offset + 1, suspend_encryptor_iv, str_size + 1);
+
+ buf_offset += str_size + 2;
+ }
+
+ return buf_offset;
+}
+
+/* suspend_encrypt_load_config_info
+ *
+ * Description: Reload information needed for deencrypting the image at
+ * resume time.
+ * Arguments: Buffer: Pointer to the start of the data.
+ * Size: Number of bytes that were saved.
+ */
+static void suspend_encrypt_load_config_info(char *buffer, int size)
+{
+ int buf_offset, str_size;
+
+ str_size = (int) *buffer;
+ strncpy(suspend_encryptor_name, buffer + 1, str_size + 1);
+ buf_offset = str_size + 2;
+
+ suspend_encryptor_mode = (int) *(buffer + buf_offset);
+ buf_offset++;
+
+ suspend_encryptor_save_key_and_iv = (int) *(buffer + buf_offset);
+ buf_offset++;
+
+ if (suspend_encryptor_save_key_and_iv) {
+ str_size = (int) *(buffer + buf_offset);
+ strncpy(suspend_encryptor_key, buffer + buf_offset + 1, str_size + 1);
+
+ buf_offset+= str_size + 2;
+
+ str_size = (int) *(buffer + buf_offset);
+ strncpy(suspend_encryptor_iv, buffer + buf_offset + 1, str_size + 1);
+
+ buf_offset += str_size + 2;
+ } else {
+ *suspend_encryptor_key = 0;
+ *suspend_encryptor_iv = 0;
+ }
+
+ if (buf_offset != size) {
+ printk("Suspend Encryptor config info size mismatch (%d != %d): settings ignored.\n",
+ buf_offset, size);
+ *suspend_encryptor_key = 0;
+ *suspend_encryptor_iv = 0;
+ }
+ return;
+}
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Suspend2][ 10/12] [Suspend2] Encryption proc entries.
2006-06-27 4:38 [Suspend2][ 00/12] Encryption support Nigel Cunningham
` (8 preceding siblings ...)
2006-06-27 4:38 ` [Suspend2][ 09/12] [Suspend2] Encryption configuration serialisation Nigel Cunningham
@ 2006-06-27 4:38 ` 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
11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:38 UTC (permalink / raw)
To: linux-kernel
Add data for the encryption related proc entries.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/encryption.c | 82 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 82 insertions(+), 0 deletions(-)
diff --git a/kernel/power/encryption.c b/kernel/power/encryption.c
index 1664b82..4e309e3 100644
--- a/kernel/power/encryption.c
+++ b/kernel/power/encryption.c
@@ -400,3 +400,85 @@ static void suspend_encrypt_load_config_
}
return;
}
+
+/*
+ * data for our proc entries.
+ */
+static struct suspend_proc_data proc_params[] = {
+{
+ .filename = "encryptor",
+ .permissions = PROC_RW,
+ .type = SUSPEND_PROC_DATA_STRING,
+ .data = {
+ .string = {
+ .variable = suspend_encryptor_name,
+ .max_length = 31,
+ }
+ },
+},
+
+{
+ .filename = "encryption_mode",
+ .permissions = PROC_RW,
+ .type = SUSPEND_PROC_DATA_INTEGER,
+ .data = {
+ .integer = {
+ .variable = &suspend_encryptor_mode,
+ .minimum = 0,
+ .maximum = 3,
+ }
+ }
+},
+
+{
+ .filename = "encryption_save_key_and_iv",
+ .permissions = PROC_RW,
+ .type = SUSPEND_PROC_DATA_INTEGER,
+ .data = {
+ .integer = {
+ .variable = &suspend_encryptor_save_key_and_iv,
+ .minimum = 0,
+ .maximum = 1,
+ }
+ }
+},
+
+{
+ .filename = "encryption_key",
+ .permissions = PROC_RW,
+ .type = SUSPEND_PROC_DATA_STRING,
+ .data = {
+ .string = {
+ .variable = suspend_encryptor_key,
+ .max_length = 255,
+ }
+ }
+},
+
+{
+ .filename = "encryption_iv",
+ .permissions = PROC_RW,
+ .type = SUSPEND_PROC_DATA_STRING,
+ .data = {
+ .string = {
+ .variable = suspend_encryptor_iv,
+ .max_length = 255,
+ }
+ }
+},
+
+{
+ .filename = "disable_encryption",
+ .permissions = PROC_RW,
+ .type = SUSPEND_PROC_DATA_INTEGER,
+ .data = {
+ .integer = {
+ .variable = &suspend_encryption_ops.disabled,
+ .minimum = 0,
+ .maximum = 1,
+ }
+ }
+},
+
+};
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Suspend2][ 11/12] [Suspend2] Encryption module accessors structure.
2006-06-27 4:38 [Suspend2][ 00/12] Encryption support Nigel Cunningham
` (9 preceding siblings ...)
2006-06-27 4:38 ` [Suspend2][ 10/12] [Suspend2] Encryption proc entries Nigel Cunningham
@ 2006-06-27 4:38 ` Nigel Cunningham
2006-06-27 4:38 ` [Suspend2][ 12/12] [Suspend2] Load and unload routines Nigel Cunningham
11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:38 UTC (permalink / raw)
To: linux-kernel
Add the struct that lets the encryption functions be used by the core.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/encryption.c | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/kernel/power/encryption.c b/kernel/power/encryption.c
index 4e309e3..8f544ff 100644
--- a/kernel/power/encryption.c
+++ b/kernel/power/encryption.c
@@ -482,3 +482,24 @@ static struct suspend_proc_data proc_par
};
+/*
+ * Ops structure.
+ */
+
+static struct suspend_module_ops suspend_encryption_ops = {
+ .type = FILTER_MODULE,
+ .name = "Encryptor",
+ .module = THIS_MODULE,
+ .memory_needed = suspend_encrypt_memory_needed,
+ .print_debug_info = suspend_encrypt_print_debug_stats,
+ .save_config_info = suspend_encrypt_save_config_info,
+ .load_config_info = suspend_encrypt_load_config_info,
+ .storage_needed = suspend_encrypt_storage_needed,
+
+ .rw_init = suspend_encrypt_rw_init,
+ .rw_cleanup = suspend_encrypt_rw_cleanup,
+
+ .write_chunk = suspend_encrypt_write_chunk,
+ .read_chunk = suspend_encrypt_read_chunk,
+};
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Suspend2][ 12/12] [Suspend2] Load and unload routines.
2006-06-27 4:38 [Suspend2][ 00/12] Encryption support Nigel Cunningham
` (10 preceding siblings ...)
2006-06-27 4:38 ` [Suspend2][ 11/12] [Suspend2] Encryption module accessors structure Nigel Cunningham
@ 2006-06-27 4:38 ` Nigel Cunningham
11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:38 UTC (permalink / raw)
To: linux-kernel
Add routines to register and deregister the encryption support and proc
entries on load and unload.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/encryption.c | 33 +++++++++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/kernel/power/encryption.c b/kernel/power/encryption.c
index 8f544ff..4d9091c 100644
--- a/kernel/power/encryption.c
+++ b/kernel/power/encryption.c
@@ -503,3 +503,36 @@ static struct suspend_module_ops suspend
.read_chunk = suspend_encrypt_read_chunk,
};
+/* ---- Registration ---- */
+
+static __init int suspend_encrypt_load(void)
+{
+ int result;
+ int i, numfiles = sizeof(proc_params) / sizeof(struct suspend_proc_data);
+
+ printk("Suspend2 Encryption Driver loading.\n");
+ if (!(result = suspend_register_module(&suspend_encryption_ops))) {
+ for (i=0; i< numfiles; i++)
+ suspend_register_procfile(&proc_params[i]);
+ } else
+ printk("Suspend2 Encryption Driver unable to register!\n");
+ return result;
+}
+
+#ifdef MODULE
+static __exit void suspend_compress_unload(void)
+{
+ printk("Suspend2 Encryption Driver unloading.\n");
+ for (i=0; i< numfiles; i++)
+ suspend_unregister_procfile(&proc_params[i]);
+ suspend_unregister_module(&suspend_encryption_ops);
+}
+
+module_init(suspend_encrypt_load);
+module_exit(suspend_encrypt_unload);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Nigel Cunningham");
+MODULE_DESCRIPTION("Encryption Support for Suspend2");
+#else
+late_initcall(suspend_encrypt_load);
+#endif
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2006-06-27 5:08 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [Suspend2][ 04/12] [Suspend2] Encrypt a page being written Nigel Cunningham
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
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®