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, linux-crypto@vger.kernel.org
Subject: [8/*] [CRYPTO] Split cbc_process into encrypt/decrypt
Date: Tue, 22 Mar 2005 22:24:16 +1100	[thread overview]
Message-ID: <20050322112416.GB7224@gondor.apana.org.au> (raw)
In-Reply-To: <20050322112231.GA7224@gondor.apana.org.au>

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

Hi:

Rather than taking a branch on the fast path, we might as well split
cbc_process into encrypt and decrypt since they don't share anything
in common.

We can get rid of the cryptfn argument too.  I'll do that next.
  
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-8 --]
[-- Type: text/plain, Size: 3731 bytes --]

===== cipher.c 1.25 vs edited =====
--- 1.25/crypto/cipher.c	2005-03-22 21:33:25 +11:00
+++ edited/cipher.c	2005-03-22 21:47:09 +11:00
@@ -24,7 +24,7 @@
 
 typedef void (cryptfn_t)(void *, u8 *, const u8 *);
 typedef void (procfn_t)(struct crypto_tfm *, u8 *,
-                        u8*, cryptfn_t, int enc, void *);
+                        u8*, cryptfn_t, void *);
 
 static inline void xor_64(u8 *a, const u8 *b)
 {
@@ -90,7 +90,7 @@
 		 struct scatterlist *dst,
 		 struct scatterlist *src,
                  unsigned int nbytes, cryptfn_t crfn,
-                 procfn_t prfn, int enc, void *info)
+                 procfn_t prfn, void *info)
 {
 	struct scatter_walk walk_in, walk_out;
 	const unsigned int bsize = crypto_tfm_alg_blocksize(tfm);
@@ -123,7 +123,7 @@
 			dst_p = prepare_dst(&walk_out, bsize, tmp_dst,
 					    in_place);
 
-			prfn(tfm, dst_p, src_p, crfn, enc, info);
+			prfn(tfm, dst_p, src_p, crfn, info);
 
 			complete_src(&walk_in, bsize, src_p, in_place);
 			complete_dst(&walk_out, bsize, dst_p, in_place);
@@ -141,24 +141,28 @@
 	}
 }
 
-static void cbc_process(struct crypto_tfm *tfm, u8 *dst, u8 *src,
-			cryptfn_t fn, int enc, void *info)
+static void cbc_process_encrypt(struct crypto_tfm *tfm, u8 *dst, u8 *src,
+				cryptfn_t fn, void *info)
 {
 	u8 *iv = info;
 
-	if (enc) {
-		tfm->crt_u.cipher.cit_xor_block(iv, src);
-		fn(crypto_tfm_ctx(tfm), dst, iv);
-		memcpy(iv, dst, crypto_tfm_alg_blocksize(tfm));
-	} else {
-		fn(crypto_tfm_ctx(tfm), dst, src);
-		tfm->crt_u.cipher.cit_xor_block(dst, iv);
-		memcpy(iv, src, crypto_tfm_alg_blocksize(tfm));
-	}
+	tfm->crt_u.cipher.cit_xor_block(iv, src);
+	fn(crypto_tfm_ctx(tfm), dst, iv);
+	memcpy(iv, dst, crypto_tfm_alg_blocksize(tfm));
+}
+
+static void cbc_process_decrypt(struct crypto_tfm *tfm, u8 *dst, u8 *src,
+				cryptfn_t fn, void *info)
+{
+	u8 *iv = info;
+
+	fn(crypto_tfm_ctx(tfm), dst, src);
+	tfm->crt_u.cipher.cit_xor_block(dst, iv);
+	memcpy(iv, src, crypto_tfm_alg_blocksize(tfm));
 }
 
 static void ecb_process(struct crypto_tfm *tfm, u8 *dst, u8 *src,
-			cryptfn_t fn, int enc, void *info)
+			cryptfn_t fn, void *info)
 {
 	fn(crypto_tfm_ctx(tfm), dst, src);
 }
@@ -181,7 +185,7 @@
 {
 	return crypt(tfm, dst, src, nbytes,
 	             tfm->__crt_alg->cra_cipher.cia_encrypt,
-	             ecb_process, 1, NULL);
+	             ecb_process, NULL);
 }
 
 static int ecb_decrypt(struct crypto_tfm *tfm,
@@ -191,7 +195,7 @@
 {
 	return crypt(tfm, dst, src, nbytes,
 	             tfm->__crt_alg->cra_cipher.cia_decrypt,
-	             ecb_process, 1, NULL);
+	             ecb_process, NULL);
 }
 
 static int cbc_encrypt(struct crypto_tfm *tfm,
@@ -201,7 +205,7 @@
 {
 	return crypt(tfm, dst, src, nbytes,
 	             tfm->__crt_alg->cra_cipher.cia_encrypt,
-	             cbc_process, 1, tfm->crt_cipher.cit_iv);
+	             cbc_process_encrypt, tfm->crt_cipher.cit_iv);
 }
 
 static int cbc_encrypt_iv(struct crypto_tfm *tfm,
@@ -211,7 +215,7 @@
 {
 	return crypt(tfm, dst, src, nbytes,
 	             tfm->__crt_alg->cra_cipher.cia_encrypt,
-	             cbc_process, 1, iv);
+	             cbc_process_encrypt, iv);
 }
 
 static int cbc_decrypt(struct crypto_tfm *tfm,
@@ -221,7 +225,7 @@
 {
 	return crypt(tfm, dst, src, nbytes,
 	             tfm->__crt_alg->cra_cipher.cia_decrypt,
-	             cbc_process, 0, tfm->crt_cipher.cit_iv);
+	             cbc_process_decrypt, tfm->crt_cipher.cit_iv);
 }
 
 static int cbc_decrypt_iv(struct crypto_tfm *tfm,
@@ -231,7 +235,7 @@
 {
 	return crypt(tfm, dst, src, nbytes,
 	             tfm->__crt_alg->cra_cipher.cia_decrypt,
-	             cbc_process, 0, iv);
+	             cbc_process_decrypt, iv);
 }
 
 static int nocrypt(struct crypto_tfm *tfm,

  reply	other threads:[~2005-03-22 11:26 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   ` [2/5] [CRYPTO] Handle in_place flag in crypt() Herbert Xu
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   ` Herbert Xu [this message]
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=20050322112416.GB7224@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-crypto@vger.kernel.org \
    --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).