From patchwork Sun Mar 25 21:11:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Reardon X-Patchwork-Id: 148586 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DDBA4B6F6E for ; Mon, 26 Mar 2012 08:12:57 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SBuiX-0004EV-Gd; Sun, 25 Mar 2012 21:11:13 +0000 Received: from [78.46.68.141] (helo=eristoteles.iwoars.net) by merlin.infradead.org with smtp (Exim 4.76 #1 (Red Hat Linux)) id 1SBuiT-0004EH-9S for linux-mtd@lists.infradead.org; Sun, 25 Mar 2012 21:11:11 +0000 Received: (qmail 8260 invoked by uid 5144); 25 Mar 2012 23:11:07 +0200 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 25 Mar 2012 23:11:07 +0200 Date: Sun, 25 Mar 2012 23:11:07 +0200 (CEST) From: Joel Reardon X-X-Sender: joel@eristoteles.iwoars.net To: Artem Bityutskiy Subject: [patch] Add a encryption key parameter to the compress / decompress function. In-Reply-To: <1332521515.22278.2.camel@sauron.fi.intel.com> Message-ID: References: <1330531826.3545.128.camel@sauron.fi.intel.com> <1332511796.18717.72.camel@sauron.fi.intel.com> <1332521515.22278.2.camel@sauron.fi.intel.com> User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -0.8 (/) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-0.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.8 RDNS_NONE Delivered to internal network by a host with no rDNS 0.3 FROM_12LTRDOM From a 12-letter domain Cc: linux-fsdevel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 From 650a52b5301778cf2f0c17ed993a104a4473a8fb Mon Sep 17 00:00:00 2001 From: Joel Reardon 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(-) 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"