Patchwork Add a encryption key parameter to the compress / decompress function.

login
register
mail settings
Submitter Joel Reardon
Date March 25, 2012, 9:11 p.m.
Message ID <alpine.DEB.2.00.1203252302310.5527@eristoteles.iwoars.net>
Download mbox | patch
Permalink /patch/148586/
State New
Headers show

Comments

Joel Reardon - March 25, 2012, 9:11 p.m.
Compress and decompress now have an extra u8 *key field, and NULL is
passed wherever it is used. Later this will be used for an encryption key
for the data being compressed/decompressed (and NULL if no cryptographic operations should be done.)

Signed-off-by: Joel Reardon <reardonj@inf.ethz.ch>

From 650a52b5301778cf2f0c17ed993a104a4473a8fb Mon Sep 17 00:00:00 2001
From: Joel Reardon <jreardon@fatbottomsworth.(none)>
Date: Sun, 25 Mar 2012 23:06:03 +0200
Subject: [PATCH] Added a key parameter to de/compress.

---
 fs/ubifs/compress.c |    8 ++++++--
 fs/ubifs/file.c     |    5 +++--
 fs/ubifs/journal.c  |    7 ++++---
 fs/ubifs/ubifs.h    |    4 ++--
 4 files changed, 15 insertions(+), 9 deletions(-)
Artem Bityutskiy - March 27, 2012, 8:27 a.m.
On Sun, 2012-03-25 at 23:11 +0200, Joel Reardon wrote:
> Compress and decompress now have an extra u8 *key field, and NULL is
> passed wherever it is used. Later this will be used for an encryption key
> for the data being compressed/decompressed (and NULL if no cryptographic operations should be done.)
> 
> Signed-off-by: Joel Reardon <reardonj@inf.ethz.ch>
> 
> From 650a52b5301778cf2f0c17ed993a104a4473a8fb Mon Sep 17 00:00:00 2001
> From: Joel Reardon <jreardon@fatbottomsworth.(none)>
> Date: Sun, 25 Mar 2012 23:06:03 +0200
> Subject: [PATCH] Added a key parameter to de/compress.

If I use git-am I will get the above "From" etc stuff in the commit
message, which is not what was intended. Just send the 'git
format-patch' output "as-is".

> 
> ---
>  fs/ubifs/compress.c |    8 ++++++--
>  fs/ubifs/file.c     |    5 +++--
>  fs/ubifs/journal.c  |    7 ++++---
>  fs/ubifs/ubifs.h    |    4 ++--
>  4 files changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/ubifs/compress.c b/fs/ubifs/compress.c
> index 11e4132..d1812fa 100644
> --- a/fs/ubifs/compress.c
> +++ b/fs/ubifs/compress.c
> @@ -82,6 +82,8 @@ struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
>   * @out_len: output buffer length is returned here
>   * @compr_type: type of compression to use on enter, actually used compression
>   *              type on exit
> + * @key: a pointer to a key-sized buffer to use as the encryption key. if NULL
> + *      then no encryption is performed.

This is confusing. In UBIFS we already have notion of "key" with
established meaning, defined in fs/ubifs/key.h. Would you please use a
different term, e.g., "encryption key", "crypto-key", for better
readability. The same for the variable name - to avoid ambiguity, use
something like 'cryptokey' or at least 'ckey' or something else.

Also, the comment says "key-sized" buffer, which is also confusing.
Either do not say anything about the size or define it better.

Patch

diff --git a/fs/ubifs/compress.c b/fs/ubifs/compress.c
index 11e4132..d1812fa 100644
--- a/fs/ubifs/compress.c
+++ b/fs/ubifs/compress.c
@@ -82,6 +82,8 @@  struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
  * @out_len: output buffer length is returned here
  * @compr_type: type of compression to use on enter, actually used compression
  *              type on exit
+ * @key: a pointer to a key-sized buffer to use as the encryption key. if NULL
+ *      then no encryption is performed.
  *
  * This function compresses input buffer @in_buf of length @in_len and stores
  * the result in the output buffer @out_buf and the resulting length in
@@ -93,7 +95,7 @@  struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
  * buffer and %UBIFS_COMPR_NONE is returned in @compr_type.
  */
 void ubifs_compress(const void *in_buf, int in_len, void *out_buf, int *out_len,
-		    int *compr_type)
+		    int *compr_type, u8 *key)
 {
 	int err;
 	struct ubifs_compressor *compr = ubifs_compressors[*compr_type];
@@ -140,13 +142,15 @@  no_compr:
  * @out_buf: output buffer where decompressed data should
  * @out_len: output length is returned here
  * @compr_type: type of compression
+ * @key: a pointer to a key-sized buffer to use as the decryption key. if
+ *	 NULL then no decryption is performed.
  *
  * This function decompresses data from buffer @in_buf into buffer @out_buf.
  * The length of the uncompressed data is returned in @out_len. This functions
  * returns %0 on success or a negative error code on failure.
  */
 int ubifs_decompress(const void *in_buf, int in_len, void *out_buf,
-		     int *out_len, int compr_type)
+		     int *out_len, int compr_type, u8 *key)
 {
 	int err;
 	struct ubifs_compressor *compr;
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
index f9c234b..2660c9f 100644
--- a/fs/ubifs/file.c
+++ b/fs/ubifs/file.c
@@ -80,7 +80,7 @@  static int read_block(struct inode *inode, void *addr, unsigned int block,
 	dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ;
 	out_len = UBIFS_BLOCK_SIZE;
 	err = ubifs_decompress(&dn->data, dlen, addr, &out_len,
-			       le16_to_cpu(dn->compr_type));
+			       le16_to_cpu(dn->compr_type), NULL);
 	if (err || len != out_len)
 		goto dump;

@@ -649,7 +649,8 @@  static int populate_page(struct ubifs_info *c, struct page *page,
 			dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ;
 			out_len = UBIFS_BLOCK_SIZE;
 			err = ubifs_decompress(&dn->data, dlen, addr, &out_len,
-					       le16_to_cpu(dn->compr_type));
+					       le16_to_cpu(dn->compr_type),
+					       NULL);
 			if (err || len != out_len)
 				goto out_err;

diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
index 2f438ab..9156395 100644
--- a/fs/ubifs/journal.c
+++ b/fs/ubifs/journal.c
@@ -727,7 +727,7 @@  int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode,
 		compr_type = ui->compr_type;

 	out_len = dlen - UBIFS_DATA_NODE_SZ;
-	ubifs_compress(buf, len, &data->data, &out_len, &compr_type);
+	ubifs_compress(buf, len, &data->data, &out_len, &compr_type, NULL);
 	ubifs_assert(out_len <= UBIFS_BLOCK_SIZE);

 	dlen = UBIFS_DATA_NODE_SZ + out_len;
@@ -1110,11 +1110,12 @@  static int recomp_data_node(struct ubifs_data_node *dn, int *new_len)

 	len = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ;
 	compr_type = le16_to_cpu(dn->compr_type);
-	err = ubifs_decompress(&dn->data, len, buf, &out_len, compr_type);
+	err = ubifs_decompress(
+		&dn->data, len, buf, &out_len, compr_type, NULL);
 	if (err)
 		goto out;

-	ubifs_compress(buf, *new_len, &dn->data, &out_len, &compr_type);
+	ubifs_compress(buf, *new_len, &dn->data, &out_len, &compr_type, NULL);
 	ubifs_assert(out_len <= UBIFS_BLOCK_SIZE);
 	dn->compr_type = cpu_to_le16(compr_type);
 	dn->size = cpu_to_le32(*new_len);
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index 93d59ac..0cc1180 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -1772,9 +1772,9 @@  long ubifs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
 int __init ubifs_compressors_init(void);
 void ubifs_compressors_exit(void);
 void ubifs_compress(const void *in_buf, int in_len, void *out_buf, int *out_len,
-		    int *compr_type);
+		    int *compr_type, u8 *key);
 int ubifs_decompress(const void *buf, int len, void *out, int *out_len,
-		     int compr_type);
+		     int compr_type, u8 *key);

 #include "debug.h"
 #include "misc.h"