All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Herbert Xu" <herbert@gondor.apana.org.au>
To: Eric Biggers <ebiggers@kernel.org>,
	Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
	Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH 3/4] crypto: arc4 - Add internal state
Date: Wed, 29 Nov 2023 14:29:48 +0800	[thread overview]
Message-ID: <E1r8E4p-004jEw-I3@formenos.hmeau.com> (raw)
In-Reply-To: ZWbZEnSPIP5aHydB@gondor.apana.org.au

The arc4 algorithm has always had internal state.  It's been buggy
from day one in that the state has been stored in the shared tfm
object.  That means two users sharing the same tfm will end up
affecting each other's output, or worse, they may end up with the
same output.

Fix this by declaring an internal state and storing the state there
instead of within the tfm context.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---

 crypto/arc4.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/crypto/arc4.c b/crypto/arc4.c
index 2150f94e7d03..e285bfcef667 100644
--- a/crypto/arc4.c
+++ b/crypto/arc4.c
@@ -23,10 +23,15 @@ static int crypto_arc4_setkey(struct crypto_lskcipher *tfm, const u8 *in_key,
 }
 
 static int crypto_arc4_crypt(struct crypto_lskcipher *tfm, const u8 *src,
-			     u8 *dst, unsigned nbytes, u8 *iv, u32 flags)
+			     u8 *dst, unsigned nbytes, u8 *siv, u32 flags)
 {
 	struct arc4_ctx *ctx = crypto_lskcipher_ctx(tfm);
 
+	if (!(flags & CRYPTO_LSKCIPHER_FLAG_CONT))
+		memcpy(siv, ctx, sizeof(*ctx));
+
+	ctx = (struct arc4_ctx *)siv;
+
 	arc4_crypt(ctx, dst, src, nbytes);
 	return 0;
 }
@@ -48,6 +53,7 @@ static struct lskcipher_alg arc4_alg = {
 	.co.base.cra_module		=	THIS_MODULE,
 	.co.min_keysize			=	ARC4_MIN_KEY_SIZE,
 	.co.max_keysize			=	ARC4_MAX_KEY_SIZE,
+	.co.statesize			=	sizeof(struct arc4_ctx),
 	.setkey				=	crypto_arc4_setkey,
 	.encrypt			=	crypto_arc4_crypt,
 	.decrypt			=	crypto_arc4_crypt,

  parent reply	other threads:[~2023-11-29  6:29 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-14  8:28 [PATCH 0/8] crypto: Add lskcipher API type Herbert Xu
2023-09-14  8:28 ` [PATCH 1/8] crypto: aead - Add crypto_has_aead Herbert Xu
2023-09-14  8:28 ` [PATCH 2/8] ipsec: Stop using crypto_has_alg Herbert Xu
2023-09-14  8:28 ` [PATCH 3/8] crypto: hash - Hide CRYPTO_ALG_TYPE_AHASH_MASK Herbert Xu
2023-09-14  8:28 ` [PATCH 4/8] crypto: skcipher - Add lskcipher Herbert Xu
2023-09-20  6:25   ` Eric Biggers
2023-09-21  4:32     ` Herbert Xu
2023-09-22  3:10       ` Eric Biggers
2023-11-17  5:19         ` Herbert Xu
2023-11-17  5:42           ` Eric Biggers
2023-11-17  9:07             ` Herbert Xu
2023-11-24 10:27               ` Herbert Xu
2023-11-27 22:28                 ` Eric Biggers
2023-11-29  6:24                   ` [PATCH 0/4] crypto: Fix chaining support for stream ciphers (arc4 only for now) Herbert Xu
2023-11-29  6:29                     ` [PATCH 1/4] crypto: skcipher - Add internal state support Herbert Xu
2023-11-29  6:29                     ` [PATCH 2/4] crypto: skcipher - Make use of internal state Herbert Xu
2023-11-29  6:29                     ` Herbert Xu [this message]
2023-11-29  6:29                     ` [PATCH 4/4] crypto: algif_skcipher - Fix stream cipher chaining Herbert Xu
2023-11-29 21:04                     ` [PATCH 0/4] crypto: Fix chaining support for stream ciphers (arc4 only for now) Eric Biggers
2023-11-30  2:17                       ` Herbert Xu
2023-11-30  9:55                     ` [v2 PATCH " Herbert Xu
2023-11-30  9:56                       ` [v2 PATCH 1/4] crypto: skcipher - Add internal state support Herbert Xu
2023-11-30  9:56                       ` [v2 PATCH 2/4] crypto: skcipher - Make use of internal state Herbert Xu
2023-11-30  9:56                       ` [v2 PATCH 3/4] crypto: arc4 - Add " Herbert Xu
2023-11-30  9:56                       ` [v2 PATCH 4/4] crypto: algif_skcipher - Fix stream cipher chaining Herbert Xu
2023-12-02  3:49                       ` [v3 PATCH 0/4] crypto: Fix chaining support for stream ciphers (arc4 only for now) Herbert Xu
2023-12-02  3:50                         ` [v3 PATCH 1/4] crypto: skcipher - Add internal state support Herbert Xu
2023-12-02  3:50                         ` [v3 PATCH 2/4] crypto: skcipher - Make use of internal state Herbert Xu
2023-12-02  3:50                         ` [v3 PATCH 3/4] crypto: arc4 - Add " Herbert Xu
2023-12-02  3:50                         ` [v3 PATCH 4/4] crypto: algif_skcipher - Fix stream cipher chaining Herbert Xu
2023-12-10 13:53                           ` [LTP] " kernel test robot
2023-12-10 13:53                             ` kernel test robot
2023-12-05  8:41         ` [PATCH 4/8] crypto: skcipher - Add lskcipher Herbert Xu
2023-12-05 20:17           ` Eric Biggers
2023-12-06  1:44             ` Herbert Xu
2023-09-14  8:28 ` [PATCH 5/8] crypto: lskcipher - Add compatibility wrapper around ECB Herbert Xu
2023-09-14  8:28 ` [PATCH 6/8] crypto: testmgr - Add support for lskcipher algorithms Herbert Xu
2023-09-14  8:28 ` [PATCH 7/8] crypto: ecb - Convert from skcipher to lskcipher Herbert Xu
2023-09-14  8:28 ` [PATCH 8/8] crypto: cbc " Herbert Xu
2023-10-02 20:25   ` Nathan Chancellor
2023-10-03  3:31     ` [PATCH] crypto: skcipher - Add dependency on ecb Herbert Xu
2023-10-03 15:25       ` Nathan Chancellor
2023-09-14  8:51 ` [PATCH 0/8] crypto: Add lskcipher API type Ard Biesheuvel
2023-09-14  8:56   ` Herbert Xu
2023-09-14  9:18     ` Ard Biesheuvel
2023-09-14  9:29       ` Herbert Xu
2023-09-14  9:31         ` Ard Biesheuvel
2023-09-14  9:34           ` Herbert Xu
2023-09-17 16:24             ` Ard Biesheuvel
2023-09-19  4:03               ` Herbert Xu
2023-09-14  9:32       ` 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=E1r8E4p-004jEw-I3@formenos.hmeau.com \
    --to=herbert@gondor.apana.org.au \
    --cc=ardb@kernel.org \
    --cc=ebiggers@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.