Re: [take1] d80211: switch crypto to use new ciphers API

2006-11-02 Thread John W. Linville
On Mon, Oct 30, 2006 at 10:08:58AM -0800, David Kimdon wrote:
 On Thu, Oct 26, 2006 at 10:06:24AM +1000, Herbert Xu wrote:
  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 Herbert.
 
 Updated patch, now aes, tkip and wep are all tested.
 
 Changes from take0:
 
 Use IS_ERR() to evaluate return value of crypto_alloc_cipher().  Use
 ciper interface rather than blkcipher for aes encryption since we only
 encrypt a single block at a time.
 
 
 
 Switch d80211 software crypto to use the new cipher API.

Applied to wireless-dev.

-- 
John W. Linville
[EMAIL PROTECTED]
-
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


[take1] d80211: switch crypto to use new ciphers API

2006-10-30 Thread David Kimdon
On Thu, Oct 26, 2006 at 10:06:24AM +1000, Herbert Xu wrote:
 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 Herbert.

Updated patch, now aes, tkip and wep are all tested.

Changes from take0:

Use IS_ERR() to evaluate return value of crypto_alloc_cipher().  Use
ciper interface rather than blkcipher for aes encryption since we only
encrypt a single block at a time.



Switch d80211 software crypto to use the new 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
@@ -14,6 +14,7 @@
 #include linux/compiler.h
 #include linux/crc32.h
 #include linux/crypto.h
+#include linux/err.h
 #include asm/scatterlist.h
 
 #include net/d80211.h
@@ -26,8 +27,9 @@ 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);
-   if (!local-wep_tfm)
+   local-wep_tfm = crypto_alloc_blkcipher(ecb(arc4), 0,
+   CRYPTO_ALG_ASYNC);
+   if (IS_ERR(local-wep_tfm))
return -ENOMEM;
 
return 0;
@@ -35,7 +37,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 +118,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 +186,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
@@ -9,6 +9,7 @@
 
 #include linux/types.h
 #include linux/crypto.h
+#include linux/err.h
 #include asm/scatterlist.h
 
 #include net/d80211.h
@@ -16,24 +17,14 @@
 #include aes_ccm.h
 
 
-static void ieee80211_aes_encrypt(struct crypto_tfm *tfm,
+static void ieee80211_aes_encrypt(struct crypto_cipher *tfm,
  const u8 pt[16], u8 ct[16])
 {
-   struct scatterlist src, dst;
-
-   src.page = virt_to_page(pt);
-   src.offset = offset_in_page(pt);
-   src.length = AES_BLOCK_LEN;
-
-   dst.page = virt_to_page(ct);
-   dst.offset = offset_in_page(ct);
-   dst.length = AES_BLOCK_LEN;
-
-   crypto_cipher_encrypt(tfm, dst, src, AES_BLOCK_LEN);
+   crypto_cipher_encrypt_one(tfm, ct, pt);
 }
 
 
-static inline void aes_ccm_prepare(struct crypto_tfm *tfm, u8 *b_0, u8 *aad,
+static inline void aes_ccm_prepare(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
   u8 *b, u8 *s_0, u8 *a)
 {
int i;

Re: [take1] d80211: switch crypto to use new ciphers API

2006-10-30 Thread Herbert Xu
On Mon, Oct 30, 2006 at 10:08:58AM -0800, David Kimdon wrote:
 
 Updated patch, now aes, tkip and wep are all tested.
 
 Changes from take0:
 
 Use IS_ERR() to evaluate return value of crypto_alloc_cipher().  Use
 ciper interface rather than blkcipher for aes encryption since we only
 encrypt a single block at a time.
 
 
 
 Switch d80211 software crypto to use the new cipher API.
 
 Signed-off-by: David Kimdon [EMAIL PROTECTED]

Thanks David.  Looks good here.

Acked-by: Herbert Xu [EMAIL PROTECTED]

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmVHI~} [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