[RFC] d80211: switch crypto to use block ciphers

2006-10-25 Thread David Kimdon
The purpose of this patch is to fix the compile-time warnings usch as:

warning: 'crypto_cipher_encrypt' is deprecated (declared at 
include/linux/crypto.h:842)

I have tested static WEP and it still works after this change.
AECS/CCM and TKIP I am assuming work as well.

I don't actually know the implications of that first hunk where we do
"arc4" -> "ecb(arc4)".  I look though the various commits by Herbert
Xu and that appeared to be the right thing.

Hopefully someone who understands this better than I can review the
change.

Thanks,

David

--

Switch d80211 software crypto to use the block cipher API.

Signed-off-by: David Kimdon <[EMAIL PROTECTED]>

Index: wireless-dev/net/d80211/wep.c
===
--- wireless-dev.orig/net/d80211/wep.c
+++ wireless-dev/net/d80211/wep.c
@@ -26,7 +26,8 @@ int ieee80211_wep_init(struct ieee80211_
/* start WEP IV from a random value */
get_random_bytes(&local->wep_iv, WEP_IV_LEN);
 
-   local->wep_tfm = crypto_alloc_tfm("arc4", 0);
+   local->wep_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0,
+   CRYPTO_ALG_ASYNC);
if (!local->wep_tfm)
return -ENOMEM;
 
@@ -35,7 +36,7 @@ int ieee80211_wep_init(struct ieee80211_
 
 void ieee80211_wep_free(struct ieee80211_local *local)
 {
-   crypto_free_tfm(local->wep_tfm);
+   crypto_free_blkcipher(local->wep_tfm);
 }
 
 static inline int ieee80211_wep_weak_iv(u32 iv, int keylen)
@@ -116,20 +117,21 @@ void ieee80211_wep_remove_iv(struct ieee
 /* Perform WEP encryption using given key. data buffer must have tailroom
  * for 4-byte ICV. data_len must not include this ICV. Note: this function
  * does _not_ add IV. data = RC4(data | CRC32(data)) */
-void ieee80211_wep_encrypt_data(struct crypto_tfm *tfm, u8 *rc4key,
+void ieee80211_wep_encrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
size_t klen, u8 *data, size_t data_len)
 {
+   struct blkcipher_desc desc = { .tfm = tfm };
struct scatterlist sg;
__le32 *icv;
 
icv = (__le32 *)(data + data_len);
*icv = cpu_to_le32(~crc32_le(~0, data, data_len));
 
-   crypto_cipher_setkey(tfm, rc4key, klen);
+   crypto_blkcipher_setkey(tfm, rc4key, klen);
sg.page = virt_to_page(data);
sg.offset = offset_in_page(data);
sg.length = data_len + WEP_ICV_LEN;
-   crypto_cipher_encrypt(tfm, &sg, &sg, sg.length);
+   crypto_blkcipher_encrypt(&desc, &sg, &sg, sg.length);
 }
 
 
@@ -183,17 +185,18 @@ int ieee80211_wep_encrypt(struct ieee802
 /* Perform WEP decryption using given key. data buffer includes encrypted
  * payload, including 4-byte ICV, but _not_ IV. data_len must not include ICV.
  * Return 0 on success and -1 on ICV mismatch. */
-int ieee80211_wep_decrypt_data(struct crypto_tfm *tfm, u8 *rc4key,
+int ieee80211_wep_decrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
   size_t klen, u8 *data, size_t data_len)
 {
+   struct blkcipher_desc desc = { .tfm = tfm };
struct scatterlist sg;
__le32 crc;
 
-   crypto_cipher_setkey(tfm, rc4key, klen);
+   crypto_blkcipher_setkey(tfm, rc4key, klen);
sg.page = virt_to_page(data);
sg.offset = offset_in_page(data);
sg.length = data_len + WEP_ICV_LEN;
-   crypto_cipher_decrypt(tfm, &sg, &sg, sg.length);
+   crypto_blkcipher_decrypt(&desc, &sg, &sg, sg.length);
 
crc = cpu_to_le32(~crc32_le(~0, data, data_len));
if (memcmp(&crc, data + data_len, WEP_ICV_LEN) != 0)
Index: wireless-dev/net/d80211/aes_ccm.c
===
--- wireless-dev.orig/net/d80211/aes_ccm.c
+++ wireless-dev/net/d80211/aes_ccm.c
@@ -16,9 +16,10 @@
 #include "aes_ccm.h"
 
 
-static void ieee80211_aes_encrypt(struct crypto_tfm *tfm,
+static void ieee80211_aes_encrypt(struct crypto_blkcipher *tfm,
  const u8 pt[16], u8 ct[16])
 {
+   struct blkcipher_desc desc = { .tfm = tfm };
struct scatterlist src, dst;
 
src.page = virt_to_page(pt);
@@ -29,11 +30,11 @@ static void ieee80211_aes_encrypt(struct
dst.offset = offset_in_page(ct);
dst.length = AES_BLOCK_LEN;
 
-   crypto_cipher_encrypt(tfm, &dst, &src, AES_BLOCK_LEN);
+   crypto_blkcipher_encrypt(&desc, &dst, &src, AES_BLOCK_LEN);
 }
 
 
-static inline void aes_ccm_prepare(struct crypto_tfm *tfm, u8 *b_0, u8 *aad,
+static inline void aes_ccm_prepare(struct crypto_blkcipher *tfm, u8 *b_0, u8 
*aad,
   u8 *b, u8 *s_0, u8 *a)
 {
int i;
@@ -61,7 +62,7 @@ static inline void aes_ccm_prepare(struc
 }
 
 
-void ieee80211_aes_ccm_encrypt(struct crypto_tfm *tfm, u8 *scratch,
+void ieee80211_aes_ccm_encrypt(struct crypto_blkcipher *tfm, u8 *scratch,
   u8 *b_0, u8 *aad, u8 *data, size_t data_len,
   

Re: [RFC] d80211: switch crypto to use block ciphers

2006-10-25 Thread Herbert Xu
On Wed, Oct 25, 2006 at 03:41:50PM -0700, David Kimdon wrote:
> 
> I don't actually know the implications of that first hunk where we do
> "arc4" -> "ecb(arc4)".  I look though the various commits by Herbert
> Xu and that appeared to be the right thing.

Basically if you encrypt/decrypt more than a block at a time and you're
using ECB then ecb(arc4) is right.  So the changes to net/d80211/wep.c
are good.

If you're only encrypting/decrypting a single block then you should
use the cipher interface.  So net/d80211/aes_ccm.c should do that
instead.  See drivers/net/wirless/airo.c for an example of that.

Thanks,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]>
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 netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html