linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Fruhwirth Clemens <clemens@endorphin.org>
Cc: James Morris <jmorris@redhat.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	cryptoapi@lists.logix.cz
Subject: [2/5] [CRYPTO] Handle in_place flag in crypt()
Date: Mon, 21 Mar 2005 20:49:39 +1100	[thread overview]
Message-ID: <20050321094939.GB23235@gondor.apana.org.au> (raw)
In-Reply-To: <20050321094807.GA23235@gondor.apana.org.au>

[-- Attachment #1: Type: text/plain, Size: 410 bytes --]

Hi:

Move the handling of in_place into crypt() itself.  This means that we only
need two temporary buffers instead of three.  It also allows us to simplify
the check in scatterwalk_samebuf.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

[-- Attachment #2: sg-2 --]
[-- Type: text/plain, Size: 2780 bytes --]

diff -Nru a/crypto/cipher.c b/crypto/cipher.c
--- a/crypto/cipher.c	2005-03-21 18:43:52 +11:00
+++ b/crypto/cipher.c	2005-03-21 18:43:52 +11:00
@@ -23,7 +23,7 @@
 
 typedef void (cryptfn_t)(void *, u8 *, const u8 *);
 typedef void (procfn_t)(struct crypto_tfm *, u8 *,
-                        u8*, cryptfn_t, int enc, void *, int);
+                        u8*, cryptfn_t, int enc, void *);
 
 static inline void xor_64(u8 *a, const u8 *b)
 {
@@ -74,22 +74,22 @@
 		scatterwalk_map(&walk_in, 0);
 		scatterwalk_map(&walk_out, 1);
 
+		in_place = scatterwalk_samebuf(&walk_in, &walk_out);
+
 		src_p = walk_in.data;
 		if (unlikely(scatterwalk_across_pages(&walk_in, bsize)))
 			src_p = tmp_src;
 
 		dst_p = walk_out.data;
-		if (unlikely(scatterwalk_across_pages(&walk_out, bsize)))
+		if (unlikely(scatterwalk_across_pages(&walk_out, bsize)) ||
+		    in_place)
 			dst_p = tmp_dst;
 
-		in_place = scatterwalk_samebuf(&walk_in, &walk_out,
-					       src_p, dst_p);
-
 		nbytes -= bsize;
 
 		scatterwalk_copychunks(src_p, &walk_in, bsize, 0);
 
-		prfn(tfm, dst_p, src_p, crfn, enc, info, in_place);
+		prfn(tfm, dst_p, src_p, crfn, enc, info);
 
 		scatterwalk_done(&walk_in, 0, nbytes);
 
@@ -104,7 +104,7 @@
 }
 
 static void cbc_process(struct crypto_tfm *tfm, u8 *dst, u8 *src,
-			cryptfn_t fn, int enc, void *info, int in_place)
+			cryptfn_t fn, int enc, void *info)
 {
 	u8 *iv = info;
 	
@@ -117,19 +117,14 @@
 		fn(crypto_tfm_ctx(tfm), dst, iv);
 		memcpy(iv, dst, crypto_tfm_alg_blocksize(tfm));
 	} else {
-		u8 stack[in_place ? crypto_tfm_alg_blocksize(tfm) : 0];
-		u8 *buf = in_place ? stack : dst;
-
-		fn(crypto_tfm_ctx(tfm), buf, src);
-		tfm->crt_u.cipher.cit_xor_block(buf, iv);
+		fn(crypto_tfm_ctx(tfm), dst, src);
+		tfm->crt_u.cipher.cit_xor_block(dst, iv);
 		memcpy(iv, src, crypto_tfm_alg_blocksize(tfm));
-		if (buf != dst)
-			memcpy(dst, buf, crypto_tfm_alg_blocksize(tfm));
 	}
 }
 
 static void ecb_process(struct crypto_tfm *tfm, u8 *dst, u8 *src,
-			cryptfn_t fn, int enc, void *info, int in_place)
+			cryptfn_t fn, int enc, void *info)
 {
 	fn(crypto_tfm_ctx(tfm), dst, src);
 }
diff -Nru a/crypto/scatterwalk.h b/crypto/scatterwalk.h
--- a/crypto/scatterwalk.h	2005-03-21 18:43:52 +11:00
+++ b/crypto/scatterwalk.h	2005-03-21 18:43:52 +11:00
@@ -34,12 +34,10 @@
 }
 
 static inline int scatterwalk_samebuf(struct scatter_walk *walk_in,
-				      struct scatter_walk *walk_out,
-				      void *src_p, void *dst_p)
+				      struct scatter_walk *walk_out)
 {
 	return walk_in->page == walk_out->page &&
-	       walk_in->offset == walk_out->offset &&
-	       walk_in->data == src_p && walk_out->data == dst_p;
+	       walk_in->offset == walk_out->offset;
 }
 
 static inline int scatterwalk_across_pages(struct scatter_walk *walk,

  reply	other threads:[~2005-03-21  9:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-21  9:40 [0/5] [CRYPTO] Speed up crypt() Herbert Xu
2005-03-21  9:48 ` [1/5] [CRYPTO] Do scatterwalk_whichbuf inline Herbert Xu
2005-03-21  9:49   ` Herbert Xu [this message]
2005-03-21  9:50     ` [3/5] [CRYPTO] Split src/dst handling out from crypt() Herbert Xu
2005-03-21  9:52       ` [4/5] [CRYPTO] Eliminate most calls to scatterwalk_copychunks " Herbert Xu
2005-03-21  9:53         ` [5/5] [CRYPTO] Optimise kmap calls in crypt() Herbert Xu
2005-03-21 11:30           ` Fruhwirth Clemens
2005-03-22  1:13             ` Herbert Xu
2005-03-22 10:24               ` Fruhwirth Clemens
2005-03-22 11:22 ` [7/*] [CRYPTO] Kill obsolete iv check in cbc_process() Herbert Xu
2005-03-22 11:24   ` [8/*] [CRYPTO] Split cbc_process into encrypt/decrypt Herbert Xu
2005-03-22 11:25     ` [9/*] [CRYPTO] Remap when walk_out crosses page in crypt() Herbert Xu
2005-03-23 20:17       ` David S. Miller

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=20050321094939.GB23235@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=clemens@endorphin.org \
    --cc=cryptoapi@lists.logix.cz \
    --cc=jmorris@redhat.com \
    --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;
as well as URLs for NNTP newsgroup(s).