From: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
To: linux-crypto@vger.kernel.org
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>
Subject: [PATCH 03/18] crypto: lrw: split gf128mul table initialization from setkey
Date: Tue, 18 Oct 2011 13:32:24 +0300 [thread overview]
Message-ID: <20111018103224.3074.92875.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20111018103208.3074.11546.stgit@localhost6.localdomain6>
Split gf128mul initialization from setkey so that it can be used outside
lrw-module.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
---
crypto/lrw.c | 61 ++++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 40 insertions(+), 21 deletions(-)
diff --git a/crypto/lrw.c b/crypto/lrw.c
index bee6022..91c17fa 100644
--- a/crypto/lrw.c
+++ b/crypto/lrw.c
@@ -29,8 +29,7 @@
#define LRW_BLOCK_SIZE 16
-struct priv {
- struct crypto_cipher *child;
+struct lrw_table_ctx {
/* optimizes multiplying a random (non incrementing, as at the
* start of a new sector) value with key2, we could also have
* used 4k optimization tables or no optimization at all. In the
@@ -45,6 +44,11 @@ struct priv {
be128 mulinc[128];
};
+struct priv {
+ struct crypto_cipher *child;
+ struct lrw_table_ctx table;
+};
+
static inline void setbit128_bbe(void *b, int bit)
{
__set_bit(bit ^ (0x80 -
@@ -56,28 +60,16 @@ static inline void setbit128_bbe(void *b, int bit)
), b);
}
-static int setkey(struct crypto_tfm *parent, const u8 *key,
- unsigned int keylen)
+static int lrw_init_table(struct lrw_table_ctx *ctx, const u8 *tweak)
{
- struct priv *ctx = crypto_tfm_ctx(parent);
- struct crypto_cipher *child = ctx->child;
- int err, i;
be128 tmp = { 0 };
- int bsize = LRW_BLOCK_SIZE;
-
- crypto_cipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
- crypto_cipher_set_flags(child, crypto_tfm_get_flags(parent) &
- CRYPTO_TFM_REQ_MASK);
- if ((err = crypto_cipher_setkey(child, key, keylen - bsize)))
- return err;
- crypto_tfm_set_flags(parent, crypto_cipher_get_flags(child) &
- CRYPTO_TFM_RES_MASK);
+ int i;
if (ctx->table)
gf128mul_free_64k(ctx->table);
/* initialize multiplication table for Key2 */
- ctx->table = gf128mul_init_64k_bbe((be128 *)(key + keylen - bsize));
+ ctx->table = gf128mul_init_64k_bbe((be128 *)tweak);
if (!ctx->table)
return -ENOMEM;
@@ -91,6 +83,32 @@ static int setkey(struct crypto_tfm *parent, const u8 *key,
return 0;
}
+static void lrw_free_table(struct lrw_table_ctx *ctx)
+{
+ if (ctx->table)
+ gf128mul_free_64k(ctx->table);
+}
+
+static int setkey(struct crypto_tfm *parent, const u8 *key,
+ unsigned int keylen)
+{
+ struct priv *ctx = crypto_tfm_ctx(parent);
+ struct crypto_cipher *child = ctx->child;
+ int err, bsize = LRW_BLOCK_SIZE;
+ const u8 *tweak = key + keylen - bsize;
+
+ crypto_cipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
+ crypto_cipher_set_flags(child, crypto_tfm_get_flags(parent) &
+ CRYPTO_TFM_REQ_MASK);
+ err = crypto_cipher_setkey(child, key, keylen - bsize);
+ if (err)
+ return err;
+ crypto_tfm_set_flags(parent, crypto_cipher_get_flags(child) &
+ CRYPTO_TFM_RES_MASK);
+
+ return lrw_init_table(&ctx->table, tweak);
+}
+
struct sinfo {
be128 t;
struct crypto_tfm *tfm;
@@ -157,7 +175,7 @@ static int crypt(struct blkcipher_desc *d,
s.t = *iv;
/* T <- I*Key2 */
- gf128mul_64k_bbe(&s.t, ctx->table);
+ gf128mul_64k_bbe(&s.t, ctx->table.table);
goto first;
@@ -165,7 +183,8 @@ static int crypt(struct blkcipher_desc *d,
do {
/* T <- I*Key2, using the optimization
* discussed in the specification */
- be128_xor(&s.t, &s.t, &ctx->mulinc[get_index128(iv)]);
+ be128_xor(&s.t, &s.t,
+ &ctx->table.mulinc[get_index128(iv)]);
inc(iv);
first:
@@ -233,8 +252,8 @@ static int init_tfm(struct crypto_tfm *tfm)
static void exit_tfm(struct crypto_tfm *tfm)
{
struct priv *ctx = crypto_tfm_ctx(tfm);
- if (ctx->table)
- gf128mul_free_64k(ctx->table);
+
+ lrw_free_table(&ctx->table);
crypto_free_cipher(ctx->child);
}
next prev parent reply other threads:[~2011-10-18 10:32 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-18 10:32 [PATCH 00/18] crypto: Add helper functions for parallelized LRW and XTS modes Jussi Kivilinna
2011-10-18 10:32 ` [PATCH 01/18] crypto: lrw: fix memleak Jussi Kivilinna
2011-10-18 10:32 ` [PATCH 02/18] crypto: lrw: use blocksize constant Jussi Kivilinna
2011-10-18 10:32 ` Jussi Kivilinna [this message]
2011-10-18 10:32 ` [PATCH 04/18] crypto: lrw: add interface for parallelized cipher implementions Jussi Kivilinna
2011-10-18 10:32 ` [PATCH 05/18] crypto: testmgr: add lrw(serpent) test vectors Jussi Kivilinna
2011-10-18 10:32 ` [PATCH 06/18] crypto: tcrypt: add lrw(serpent) tests Jussi Kivilinna
2011-10-18 10:32 ` [PATCH 07/18] crypto: serpent-sse2: add lrw support Jussi Kivilinna
2011-10-18 10:32 ` [PATCH 08/18] crypto: testmgr: add lrw(twofish) test vectors Jussi Kivilinna
2011-10-18 10:32 ` [PATCH 09/18] crypto: tcrypt: add lrw(twofish) tests Jussi Kivilinna
2011-10-18 10:33 ` [PATCH 10/18] crypto: twofish-x86_64-3way: add lrw support Jussi Kivilinna
2011-10-18 10:33 ` [PATCH 11/18] crypto: xts: use blocksize constant Jussi Kivilinna
2011-10-18 10:33 ` [PATCH 12/18] crypto: xts: add interface for parallelized cipher implementations Jussi Kivilinna
2011-10-18 10:33 ` [PATCH 13/18] crypto: testmgr: add xts(serpent) test vectors Jussi Kivilinna
2011-10-18 10:33 ` [PATCH 14/18] crypto: tcrypt: add xts(serpent) tests Jussi Kivilinna
2011-10-18 10:33 ` [PATCH 15/18] crypto: serpent-sse2: add xts support Jussi Kivilinna
2011-10-18 10:33 ` [PATCH 16/18] crypto: testmgr: add xts(twofish) test vectors Jussi Kivilinna
2011-10-18 10:33 ` [PATCH 17/18] crypto: tcrypt: add xts(twofish) tests Jussi Kivilinna
2011-10-18 10:33 ` [PATCH 18/18] crypto: twofish-x86_64-3way: add xts support Jussi Kivilinna
2011-11-09 4:00 ` [PATCH 00/18] crypto: Add helper functions for parallelized LRW and XTS modes Herbert Xu
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=20111018103224.3074.92875.stgit@localhost6.localdomain6 \
--to=jussi.kivilinna@mbnet.fi \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@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