Re: [PATCH 2/7] crypto: add blkcipher implementation of ARC4

2010-04-05 Thread Herbert Xu
On Sat, Apr 03, 2010 at 09:49:24AM +0200, Sebastian Andrzej Siewior wrote:

 +#include crypto/arc4.h

This file doesn't seem to exist in the kernel tree or your patch-set?

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmVHI~} herb...@gondor.apana.org.au
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] crypto: add blkcipher implementation of ARC4

2010-04-05 Thread Sebastian Andrzej Siewior
This is a pure blkcipher implementation of ARC4. The internal state is
saved within an IV which is supplied by the user. The goal is that the
cipher does not change its internal state now, only the iv changes during
encryption.

Signed-off-by: Sebastian Andrzej Siewior sebast...@breakpoint.cc
---
 crypto/Kconfig|   13 
 crypto/Makefile   |1 +
 crypto/arc4blk.c  |  150 +
 crypto/testmgr.h  |3 +-
 include/crypto/arc4.h |   26 +
 5 files changed, 192 insertions(+), 1 deletions(-)
 create mode 100644 crypto/arc4blk.c
 create mode 100644 include/crypto/arc4.h

diff --git a/crypto/Kconfig b/crypto/Kconfig
index 81c185a..be9add2 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -570,6 +570,19 @@ config CRYPTO_ARC4
  WEP, but it should not be for other purposes because of the
  weakness of the algorithm.
 
+config CRYPTO_ARC4BLK
+   tristate ARC4 cipher algorithm (alternative implemenation)
+   select CRYPTO_BLKCIPHER
+   help
+ ARC4 cipher algorithm. This is an alternative ARC4 implementation 
which
+ will replace the other ARC4 implementation once all in-kernel users 
are
+ converted.
+
+ ARC4 is a stream cipher using keys ranging from 8 bits to 2048
+ bits in length.  This algorithm is required for driver-based
+ WEP, but it should not be for other purposes because of the
+ weakness of the algorithm.
+
 config CRYPTO_BLOWFISH
tristate Blowfish cipher algorithm
select CRYPTO_ALGAPI
diff --git a/crypto/Makefile b/crypto/Makefile
index 1f15112..11300e3 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -68,6 +68,7 @@ obj-$(CONFIG_CRYPTO_CAMELLIA) += camellia.o
 obj-$(CONFIG_CRYPTO_CAST5) += cast5.o
 obj-$(CONFIG_CRYPTO_CAST6) += cast6.o
 obj-$(CONFIG_CRYPTO_ARC4) += arc4cip.o
+obj-$(CONFIG_CRYPTO_ARC4BLK) += arc4blk.o
 obj-$(CONFIG_CRYPTO_TEA) += tea.o
 obj-$(CONFIG_CRYPTO_KHAZAD) += khazad.o
 obj-$(CONFIG_CRYPTO_ANUBIS) += anubis.o
diff --git a/crypto/arc4blk.c b/crypto/arc4blk.c
new file mode 100644
index 000..bdf938a
--- /dev/null
+++ b/crypto/arc4blk.c
@@ -0,0 +1,150 @@
+/*
+ * Cryptographic API
+ *
+ * ARC4 Cipher Algorithm
+ *
+ * Jon Oberheide j...@oberheide.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ */
+#include linux/module.h
+#include linux/init.h
+#include crypto/algapi.h
+#include crypto/arc4.h
+
+#define ARC4_MIN_KEY_SIZE  1
+#define ARC4_MAX_KEY_SIZE  256
+#define ARC4_BLOCK_SIZE1
+
+static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key,
+   unsigned int key_len)
+{
+   /*
+* ARC4 is special: The user should supply an IV as struct arc4_iv and
+* fill either the key or the iv.
+*/
+   return 0;
+}
+
+static void arc4_key_to_iv(const u8 *in_key, u32 key_len, struct arc4_iv *iv)
+{
+   int i, j = 0, k = 0;
+
+   iv-iv.x = 1;
+   iv-iv.y = 0;
+
+   for (i = 0; i  256; i++)
+   iv-iv.S[i] = i;
+
+   for (i = 0; i  256; i++)
+   {
+   u8 a = iv-iv.S[i];
+   j = (j + in_key[k] + a)  0xff;
+   iv-iv.S[i] = iv-iv.S[j];
+   iv-iv.S[j] = a;
+   if (++k = key_len)
+   k = 0;
+   }
+}
+
+static void arc4_ivsetup(struct arc4_iv *iv)
+{
+   struct arc4_iv tmp_iv;
+
+   if (iv-type == ARC4_TYPE_IV)
+   return;
+
+   memcpy(tmp_iv, iv, sizeof(tmp_iv));
+   arc4_key_to_iv(tmp_iv.key.key, tmp_iv.key.key_len, iv);
+   iv-type = ARC4_TYPE_IV;
+}
+
+static int arc4_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
+   struct scatterlist *src, unsigned int nbytes)
+{
+   struct blkcipher_walk walk;
+   struct arc4_iv *aiv;
+   u8 *S;
+   u8 x;
+   u8 y;
+   u8 a, b;
+   int ret;
+
+   blkcipher_walk_init(walk, dst, src, nbytes);
+   ret = blkcipher_walk_virt(desc, walk);
+   if (ret)
+   return ret;
+
+   aiv = (struct arc4_iv *)walk.iv;
+   arc4_ivsetup(aiv);
+
+   S = aiv-iv.S;
+   x = aiv-iv.x;
+   y = aiv-iv.y;
+
+   while (walk.nbytes) {
+   u8 *in = walk.src.virt.addr;
+   u8 *out = walk.dst.virt.addr;
+   u32 i;
+
+   for (i = 0; i  walk.nbytes; i++) {
+   a = S[x];
+   y = (y + a)  0xff;
+   b = S[y];
+   S[x] = b;
+   S[y] = a;
+   x = (x + 1)  0xff;
+   *out = *in ^ S[(a + b)  0xff];
+
+   in++;
+   out++;
+   }
+   

Re: [PATCH 4/7] net/wireless: switch lib80211_crypt_tkip from arc4 to arc4blk

2010-04-05 Thread John W. Linville
On Sat, Apr 03, 2010 at 09:49:26AM +0200, Sebastian Andrzej Siewior wrote:
 ecb(arc4) is getting replaced by arc4 which is a blkcipher by itself. The
 required selects are now pulled in by LIB80211_CRYPT_TKIP instead of
 selecting it by every driver.
 
 Signed-off-by: Sebastian Andrzej Siewior sebast...@breakpoint.cc

Fine by me...

John
-- 
John W. LinvilleSomeday the world will need a hero, and you
linvi...@tuxdriver.com  might be all we have.  Be ready.
--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 6/7] net/mac80211: convert wep from arc4 to arc4blk

2010-04-05 Thread John W. Linville
On Sat, Apr 03, 2010 at 09:49:28AM +0200, Sebastian Andrzej Siewior wrote:
 ecb(arc4) is getting replaced by arc4 which is a blkcipher by itself.
 
 Signed-off-by: Sebastian Andrzej Siewior sebast...@breakpoint.cc

Seems ok to me...

John
-- 
John W. LinvilleSomeday the world will need a hero, and you
linvi...@tuxdriver.com  might be all we have.  Be ready.
--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Convert arc4 from a cipher into a block cipher

2010-04-05 Thread Pavel Roskin
On Sat, 2010-04-03 at 09:49 +0200, Sebastian Andrzej Siewior wrote:
 This patch series converts arc4 into a block cipher and converts all its
 users (except those in staging) to use it. The first two patches ensure
 that two implementations can coexist, the following patches convert each
 user so we remain bisectable.
 - lib80211_crypt_tkip was tested with ipw2200
 - mac80211 was tested with zd1211rw

Are you trying to speed up arc4?  Or you want to simplify the code?  Or
maybe you are trying to make arc4 unsuitable for anything other than WEP
and TKIP?  The later should be fine, actually, considering the known
security issues.

-- 
Regards,
Pavel Roskin
--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Convert arc4 from a cipher into a block cipher

2010-04-05 Thread Herbert Xu
On Mon, Apr 05, 2010 at 04:33:45PM -0400, Pavel Roskin wrote:

 Are you trying to speed up arc4?  Or you want to simplify the code?  Or
 maybe you are trying to make arc4 unsuitable for anything other than WEP
 and TKIP?  The later should be fine, actually, considering the known
 security issues.

No the point is to make arc4 compliant with the crypto API by
being reentrant.

Functionality-wise there is no difference.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmVHI~} herb...@gondor.apana.org.au
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html