Commit f12cc209 authored by Herbert Xu's avatar Herbert Xu

[CRYPTO] users: Use block ciphers where applicable

This patch converts all remaining users to use the new block cipher type
where applicable.  It also changes all simple cipher operations to use
the new encrypt_one/decrypt_one interface.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 378c6697
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
* deprecated in 2.6 * deprecated in 2.6
*/ */
#include <linux/err.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/version.h> #include <linux/version.h>
...@@ -95,7 +96,7 @@ static inline void sha_pad_init(struct sha_pad *shapad) ...@@ -95,7 +96,7 @@ static inline void sha_pad_init(struct sha_pad *shapad)
* State for an MPPE (de)compressor. * State for an MPPE (de)compressor.
*/ */
struct ppp_mppe_state { struct ppp_mppe_state {
struct crypto_tfm *arc4; struct crypto_blkcipher *arc4;
struct crypto_tfm *sha1; struct crypto_tfm *sha1;
unsigned char *sha1_digest; unsigned char *sha1_digest;
unsigned char master_key[MPPE_MAX_KEY_LEN]; unsigned char master_key[MPPE_MAX_KEY_LEN];
...@@ -156,13 +157,14 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key) ...@@ -156,13 +157,14 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
{ {
unsigned char InterimKey[MPPE_MAX_KEY_LEN]; unsigned char InterimKey[MPPE_MAX_KEY_LEN];
struct scatterlist sg_in[1], sg_out[1]; struct scatterlist sg_in[1], sg_out[1];
struct blkcipher_desc desc = { .tfm = state->arc4 };
get_new_key_from_sha(state, InterimKey); get_new_key_from_sha(state, InterimKey);
if (!initial_key) { if (!initial_key) {
crypto_cipher_setkey(state->arc4, InterimKey, state->keylen); crypto_blkcipher_setkey(state->arc4, InterimKey, state->keylen);
setup_sg(sg_in, InterimKey, state->keylen); setup_sg(sg_in, InterimKey, state->keylen);
setup_sg(sg_out, state->session_key, state->keylen); setup_sg(sg_out, state->session_key, state->keylen);
if (crypto_cipher_encrypt(state->arc4, sg_out, sg_in, if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
state->keylen) != 0) { state->keylen) != 0) {
printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n"); printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n");
} }
...@@ -175,7 +177,7 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key) ...@@ -175,7 +177,7 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
state->session_key[1] = 0x26; state->session_key[1] = 0x26;
state->session_key[2] = 0x9e; state->session_key[2] = 0x9e;
} }
crypto_cipher_setkey(state->arc4, state->session_key, state->keylen); crypto_blkcipher_setkey(state->arc4, state->session_key, state->keylen);
} }
/* /*
...@@ -196,9 +198,11 @@ static void *mppe_alloc(unsigned char *options, int optlen) ...@@ -196,9 +198,11 @@ static void *mppe_alloc(unsigned char *options, int optlen)
memset(state, 0, sizeof(*state)); memset(state, 0, sizeof(*state));
state->arc4 = crypto_alloc_tfm("arc4", 0); state->arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
if (!state->arc4) if (IS_ERR(state->arc4)) {
state->arc4 = NULL;
goto out_free; goto out_free;
}
state->sha1 = crypto_alloc_tfm("sha1", 0); state->sha1 = crypto_alloc_tfm("sha1", 0);
if (!state->sha1) if (!state->sha1)
...@@ -231,7 +235,7 @@ static void *mppe_alloc(unsigned char *options, int optlen) ...@@ -231,7 +235,7 @@ static void *mppe_alloc(unsigned char *options, int optlen)
if (state->sha1) if (state->sha1)
crypto_free_tfm(state->sha1); crypto_free_tfm(state->sha1);
if (state->arc4) if (state->arc4)
crypto_free_tfm(state->arc4); crypto_free_blkcipher(state->arc4);
kfree(state); kfree(state);
out: out:
return NULL; return NULL;
...@@ -249,7 +253,7 @@ static void mppe_free(void *arg) ...@@ -249,7 +253,7 @@ static void mppe_free(void *arg)
if (state->sha1) if (state->sha1)
crypto_free_tfm(state->sha1); crypto_free_tfm(state->sha1);
if (state->arc4) if (state->arc4)
crypto_free_tfm(state->arc4); crypto_free_blkcipher(state->arc4);
kfree(state); kfree(state);
} }
} }
...@@ -356,6 +360,7 @@ mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf, ...@@ -356,6 +360,7 @@ mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
int isize, int osize) int isize, int osize)
{ {
struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
struct blkcipher_desc desc = { .tfm = state->arc4 };
int proto; int proto;
struct scatterlist sg_in[1], sg_out[1]; struct scatterlist sg_in[1], sg_out[1];
...@@ -413,7 +418,7 @@ mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf, ...@@ -413,7 +418,7 @@ mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
/* Encrypt packet */ /* Encrypt packet */
setup_sg(sg_in, ibuf, isize); setup_sg(sg_in, ibuf, isize);
setup_sg(sg_out, obuf, osize); setup_sg(sg_out, obuf, osize);
if (crypto_cipher_encrypt(state->arc4, sg_out, sg_in, isize) != 0) { if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in, isize) != 0) {
printk(KERN_DEBUG "crypto_cypher_encrypt failed\n"); printk(KERN_DEBUG "crypto_cypher_encrypt failed\n");
return -1; return -1;
} }
...@@ -462,6 +467,7 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf, ...@@ -462,6 +467,7 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
int osize) int osize)
{ {
struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
struct blkcipher_desc desc = { .tfm = state->arc4 };
unsigned ccount; unsigned ccount;
int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED; int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED;
int sanity = 0; int sanity = 0;
...@@ -599,7 +605,7 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf, ...@@ -599,7 +605,7 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
*/ */
setup_sg(sg_in, ibuf, 1); setup_sg(sg_in, ibuf, 1);
setup_sg(sg_out, obuf, 1); setup_sg(sg_out, obuf, 1);
if (crypto_cipher_decrypt(state->arc4, sg_out, sg_in, 1) != 0) { if (crypto_blkcipher_decrypt(&desc, sg_out, sg_in, 1) != 0) {
printk(KERN_DEBUG "crypto_cypher_decrypt failed\n"); printk(KERN_DEBUG "crypto_cypher_decrypt failed\n");
return DECOMP_ERROR; return DECOMP_ERROR;
} }
...@@ -619,7 +625,7 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf, ...@@ -619,7 +625,7 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
/* And finally, decrypt the rest of the packet. */ /* And finally, decrypt the rest of the packet. */
setup_sg(sg_in, ibuf + 1, isize - 1); setup_sg(sg_in, ibuf + 1, isize - 1);
setup_sg(sg_out, obuf + 1, osize - 1); setup_sg(sg_out, obuf + 1, osize - 1);
if (crypto_cipher_decrypt(state->arc4, sg_out, sg_in, isize - 1) != 0) { if (crypto_blkcipher_decrypt(&desc, sg_out, sg_in, isize - 1)) {
printk(KERN_DEBUG "crypto_cypher_decrypt failed\n"); printk(KERN_DEBUG "crypto_cypher_decrypt failed\n");
return DECOMP_ERROR; return DECOMP_ERROR;
} }
...@@ -694,7 +700,7 @@ static struct compressor ppp_mppe = { ...@@ -694,7 +700,7 @@ static struct compressor ppp_mppe = {
static int __init ppp_mppe_init(void) static int __init ppp_mppe_init(void)
{ {
int answer; int answer;
if (!(crypto_alg_available("arc4", 0) && if (!(crypto_alg_available("ecb(arc4)", 0) &&
crypto_alg_available("sha1", 0))) crypto_alg_available("sha1", 0)))
return -ENODEV; return -ENODEV;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
======================================================================*/ ======================================================================*/
#include <linux/err.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -1203,7 +1204,7 @@ struct airo_info { ...@@ -1203,7 +1204,7 @@ struct airo_info {
struct iw_spy_data spy_data; struct iw_spy_data spy_data;
struct iw_public_data wireless_data; struct iw_public_data wireless_data;
/* MIC stuff */ /* MIC stuff */
struct crypto_tfm *tfm; struct crypto_cipher *tfm;
mic_module mod[2]; mic_module mod[2];
mic_statistics micstats; mic_statistics micstats;
HostRxDesc rxfids[MPI_MAX_FIDS]; // rx/tx/config MPI350 descriptors HostRxDesc rxfids[MPI_MAX_FIDS]; // rx/tx/config MPI350 descriptors
...@@ -1271,7 +1272,8 @@ static int flashrestart(struct airo_info *ai,struct net_device *dev); ...@@ -1271,7 +1272,8 @@ static int flashrestart(struct airo_info *ai,struct net_device *dev);
static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq); static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq);
static void MoveWindow(miccntx *context, u32 micSeq); static void MoveWindow(miccntx *context, u32 micSeq);
static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *); static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
struct crypto_cipher *tfm);
static void emmh32_init(emmh32_context *context); static void emmh32_init(emmh32_context *context);
static void emmh32_update(emmh32_context *context, u8 *pOctets, int len); static void emmh32_update(emmh32_context *context, u8 *pOctets, int len);
static void emmh32_final(emmh32_context *context, u8 digest[4]); static void emmh32_final(emmh32_context *context, u8 digest[4]);
...@@ -1339,10 +1341,11 @@ static int micsetup(struct airo_info *ai) { ...@@ -1339,10 +1341,11 @@ static int micsetup(struct airo_info *ai) {
int i; int i;
if (ai->tfm == NULL) if (ai->tfm == NULL)
ai->tfm = crypto_alloc_tfm("aes", CRYPTO_TFM_REQ_MAY_SLEEP); ai->tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
if (ai->tfm == NULL) { if (IS_ERR(ai->tfm)) {
airo_print_err(ai->dev->name, "failed to load transform for AES"); airo_print_err(ai->dev->name, "failed to load transform for AES");
ai->tfm = NULL;
return ERROR; return ERROR;
} }
...@@ -1608,7 +1611,8 @@ static void MoveWindow(miccntx *context, u32 micSeq) ...@@ -1608,7 +1611,8 @@ static void MoveWindow(miccntx *context, u32 micSeq)
static unsigned char aes_counter[16]; static unsigned char aes_counter[16];
/* expand the key to fill the MMH coefficient array */ /* expand the key to fill the MMH coefficient array */
static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *tfm) static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
struct crypto_cipher *tfm)
{ {
/* take the keying material, expand if necessary, truncate at 16-bytes */ /* take the keying material, expand if necessary, truncate at 16-bytes */
/* run through AES counter mode to generate context->coeff[] */ /* run through AES counter mode to generate context->coeff[] */
...@@ -1616,7 +1620,6 @@ static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct ...@@ -1616,7 +1620,6 @@ static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct
int i,j; int i,j;
u32 counter; u32 counter;
u8 *cipher, plain[16]; u8 *cipher, plain[16];
struct scatterlist sg[1];
crypto_cipher_setkey(tfm, pkey, 16); crypto_cipher_setkey(tfm, pkey, 16);
counter = 0; counter = 0;
...@@ -1627,9 +1630,8 @@ static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct ...@@ -1627,9 +1630,8 @@ static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct
aes_counter[12] = (u8)(counter >> 24); aes_counter[12] = (u8)(counter >> 24);
counter++; counter++;
memcpy (plain, aes_counter, 16); memcpy (plain, aes_counter, 16);
sg_set_buf(sg, plain, 16); crypto_cipher_encrypt_one(tfm, plain, plain);
crypto_cipher_encrypt(tfm, sg, sg, 16); cipher = plain;
cipher = kmap(sg->page) + sg->offset;
for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) { for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) {
context->coeff[i++] = ntohl(*(u32 *)&cipher[j]); context->coeff[i++] = ntohl(*(u32 *)&cipher[j]);
j += 4; j += 4;
...@@ -2432,7 +2434,7 @@ void stop_airo_card( struct net_device *dev, int freeres ) ...@@ -2432,7 +2434,7 @@ void stop_airo_card( struct net_device *dev, int freeres )
ai->shared, ai->shared_dma); ai->shared, ai->shared_dma);
} }
} }
crypto_free_tfm(ai->tfm); crypto_free_cipher(ai->tfm);
del_airo_dev( dev ); del_airo_dev( dev );
free_netdev( dev ); free_netdev( dev );
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
* more details. * more details.
*/ */
#include <linux/err.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -48,7 +49,7 @@ struct ieee80211_ccmp_data { ...@@ -48,7 +49,7 @@ struct ieee80211_ccmp_data {
int key_idx; int key_idx;
struct crypto_tfm *tfm; struct crypto_cipher *tfm;
/* scratch buffers for virt_to_page() (crypto API) */ /* scratch buffers for virt_to_page() (crypto API) */
u8 tx_b0[AES_BLOCK_LEN], tx_b[AES_BLOCK_LEN], u8 tx_b0[AES_BLOCK_LEN], tx_b[AES_BLOCK_LEN],
...@@ -56,20 +57,10 @@ struct ieee80211_ccmp_data { ...@@ -56,20 +57,10 @@ struct ieee80211_ccmp_data {
u8 rx_b0[AES_BLOCK_LEN], rx_b[AES_BLOCK_LEN], rx_a[AES_BLOCK_LEN]; u8 rx_b0[AES_BLOCK_LEN], rx_b[AES_BLOCK_LEN], rx_a[AES_BLOCK_LEN];
}; };
static void ieee80211_ccmp_aes_encrypt(struct crypto_tfm *tfm, static inline void ieee80211_ccmp_aes_encrypt(struct crypto_cipher *tfm,
const u8 pt[16], u8 ct[16]) const u8 pt[16], u8 ct[16])
{ {
struct scatterlist src, dst; crypto_cipher_encrypt_one(tfm, ct, pt);
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);
} }
static void *ieee80211_ccmp_init(int key_idx) static void *ieee80211_ccmp_init(int key_idx)
...@@ -81,10 +72,11 @@ static void *ieee80211_ccmp_init(int key_idx) ...@@ -81,10 +72,11 @@ static void *ieee80211_ccmp_init(int key_idx)
goto fail; goto fail;
priv->key_idx = key_idx; priv->key_idx = key_idx;
priv->tfm = crypto_alloc_tfm("aes", 0); priv->tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
if (priv->tfm == NULL) { if (IS_ERR(priv->tfm)) {
printk(KERN_DEBUG "ieee80211_crypt_ccmp: could not allocate " printk(KERN_DEBUG "ieee80211_crypt_ccmp: could not allocate "
"crypto API aes\n"); "crypto API aes\n");
priv->tfm = NULL;
goto fail; goto fail;
} }
...@@ -93,7 +85,7 @@ static void *ieee80211_ccmp_init(int key_idx) ...@@ -93,7 +85,7 @@ static void *ieee80211_ccmp_init(int key_idx)
fail: fail:
if (priv) { if (priv) {
if (priv->tfm) if (priv->tfm)
crypto_free_tfm(priv->tfm); crypto_free_cipher(priv->tfm);
kfree(priv); kfree(priv);
} }
...@@ -104,7 +96,7 @@ static void ieee80211_ccmp_deinit(void *priv) ...@@ -104,7 +96,7 @@ static void ieee80211_ccmp_deinit(void *priv)
{ {
struct ieee80211_ccmp_data *_priv = priv; struct ieee80211_ccmp_data *_priv = priv;
if (_priv && _priv->tfm) if (_priv && _priv->tfm)
crypto_free_tfm(_priv->tfm); crypto_free_cipher(_priv->tfm);
kfree(priv); kfree(priv);
} }
...@@ -115,7 +107,7 @@ static inline void xor_block(u8 * b, u8 * a, size_t len) ...@@ -115,7 +107,7 @@ static inline void xor_block(u8 * b, u8 * a, size_t len)
b[i] ^= a[i]; b[i] ^= a[i];
} }
static void ccmp_init_blocks(struct crypto_tfm *tfm, static void ccmp_init_blocks(struct crypto_cipher *tfm,
struct ieee80211_hdr_4addr *hdr, struct ieee80211_hdr_4addr *hdr,
u8 * pn, size_t dlen, u8 * b0, u8 * auth, u8 * s0) u8 * pn, size_t dlen, u8 * b0, u8 * auth, u8 * s0)
{ {
...@@ -377,7 +369,7 @@ static int ieee80211_ccmp_set_key(void *key, int len, u8 * seq, void *priv) ...@@ -377,7 +369,7 @@ static int ieee80211_ccmp_set_key(void *key, int len, u8 * seq, void *priv)
{ {
struct ieee80211_ccmp_data *data = priv; struct ieee80211_ccmp_data *data = priv;
int keyidx; int keyidx;
struct crypto_tfm *tfm = data->tfm; struct crypto_cipher *tfm = data->tfm;
keyidx = data->key_idx; keyidx = data->key_idx;
memset(data, 0, sizeof(*data)); memset(data, 0, sizeof(*data));
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
* more details. * more details.
*/ */
#include <linux/err.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -52,7 +53,7 @@ struct ieee80211_tkip_data { ...@@ -52,7 +53,7 @@ struct ieee80211_tkip_data {
int key_idx; int key_idx;
struct crypto_tfm *tfm_arc4; struct crypto_blkcipher *tfm_arc4;
struct crypto_tfm *tfm_michael; struct crypto_tfm *tfm_michael;
/* scratch buffers for virt_to_page() (crypto API) */ /* scratch buffers for virt_to_page() (crypto API) */
...@@ -85,10 +86,12 @@ static void *ieee80211_tkip_init(int key_idx) ...@@ -85,10 +86,12 @@ static void *ieee80211_tkip_init(int key_idx)
priv->key_idx = key_idx; priv->key_idx = key_idx;
priv->tfm_arc4 = crypto_alloc_tfm("arc4", 0); priv->tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0,
if (priv->tfm_arc4 == NULL) { CRYPTO_ALG_ASYNC);
if (IS_ERR(priv->tfm_arc4)) {
printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate " printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
"crypto API arc4\n"); "crypto API arc4\n");
priv->tfm_arc4 = NULL;
goto fail; goto fail;
} }
...@@ -106,7 +109,7 @@ static void *ieee80211_tkip_init(int key_idx) ...@@ -106,7 +109,7 @@ static void *ieee80211_tkip_init(int key_idx)
if (priv->tfm_michael) if (priv->tfm_michael)
crypto_free_tfm(priv->tfm_michael); crypto_free_tfm(priv->tfm_michael);
if (priv->tfm_arc4) if (priv->tfm_arc4)
crypto_free_tfm(priv->tfm_arc4); crypto_free_blkcipher(priv->tfm_arc4);
kfree(priv); kfree(priv);
} }
...@@ -119,7 +122,7 @@ static void ieee80211_tkip_deinit(void *priv) ...@@ -119,7 +122,7 @@ static void ieee80211_tkip_deinit(void *priv)
if (_priv && _priv->tfm_michael) if (_priv && _priv->tfm_michael)
crypto_free_tfm(_priv->tfm_michael); crypto_free_tfm(_priv->tfm_michael);
if (_priv && _priv->tfm_arc4) if (_priv && _priv->tfm_arc4)
crypto_free_tfm(_priv->tfm_arc4); crypto_free_blkcipher(_priv->tfm_arc4);
kfree(priv); kfree(priv);
} }
...@@ -318,6 +321,7 @@ static int ieee80211_tkip_hdr(struct sk_buff *skb, int hdr_len, ...@@ -318,6 +321,7 @@ static int ieee80211_tkip_hdr(struct sk_buff *skb, int hdr_len,
static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv) static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
{ {
struct ieee80211_tkip_data *tkey = priv; struct ieee80211_tkip_data *tkey = priv;
struct blkcipher_desc desc = { .tfm = tkey->tfm_arc4 };
int len; int len;
u8 rc4key[16], *pos, *icv; u8 rc4key[16], *pos, *icv;
u32 crc; u32 crc;
...@@ -351,18 +355,17 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -351,18 +355,17 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
icv[2] = crc >> 16; icv[2] = crc >> 16;
icv[3] = crc >> 24; icv[3] = crc >> 24;
crypto_cipher_setkey(tkey->tfm_arc4, rc4key, 16); crypto_blkcipher_setkey(tkey->tfm_arc4, rc4key, 16);
sg.page = virt_to_page(pos); sg.page = virt_to_page(pos);
sg.offset = offset_in_page(pos); sg.offset = offset_in_page(pos);
sg.length = len + 4; sg.length = len + 4;
crypto_cipher_encrypt(tkey->tfm_arc4, &sg, &sg, len + 4); return crypto_blkcipher_encrypt(&desc, &sg, &sg, len + 4);
return 0;
} }
static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
{ {
struct ieee80211_tkip_data *tkey = priv; struct ieee80211_tkip_data *tkey = priv;
struct blkcipher_desc desc = { .tfm = tkey->tfm_arc4 };
u8 rc4key[16]; u8 rc4key[16];
u8 keyidx, *pos; u8 keyidx, *pos;
u32 iv32; u32 iv32;
...@@ -434,11 +437,18 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -434,11 +437,18 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
plen = skb->len - hdr_len - 12; plen = skb->len - hdr_len - 12;
crypto_cipher_setkey(tkey->tfm_arc4, rc4key, 16); crypto_blkcipher_setkey(tkey->tfm_arc4, rc4key, 16);
sg.page = virt_to_page(pos); sg.page = virt_to_page(pos);
sg.offset = offset_in_page(pos); sg.offset = offset_in_page(pos);
sg.length = plen + 4; sg.length = plen + 4;
crypto_cipher_decrypt(tkey->tfm_arc4, &sg, &sg, plen + 4); if (crypto_blkcipher_decrypt(&desc, &sg, &sg, plen + 4)) {
if (net_ratelimit()) {
printk(KERN_DEBUG ": TKIP: failed to decrypt "
"received packet from " MAC_FMT "\n",
MAC_ARG(hdr->addr2));
}
return -7;
}
crc = ~crc32_le(~0, pos, plen); crc = ~crc32_le(~0, pos, plen);
icv[0] = crc; icv[0] = crc;
...@@ -619,7 +629,7 @@ static int ieee80211_tkip_set_key(void *key, int len, u8 * seq, void *priv) ...@@ -619,7 +629,7 @@ static int ieee80211_tkip_set_key(void *key, int len, u8 * seq, void *priv)
struct ieee80211_tkip_data *tkey = priv; struct ieee80211_tkip_data *tkey = priv;
int keyidx; int keyidx;
struct crypto_tfm *tfm = tkey->tfm_michael; struct crypto_tfm *tfm = tkey->tfm_michael;
struct crypto_tfm *tfm2 = tkey->tfm_arc4; struct crypto_blkcipher *tfm2 = tkey->tfm_arc4;
keyidx = tkey->key_idx; keyidx = tkey->key_idx;
memset(tkey, 0, sizeof(*tkey)); memset(tkey, 0, sizeof(*tkey));
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
* more details. * more details.
*/ */
#include <linux/err.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -32,7 +33,7 @@ struct prism2_wep_data { ...@@ -32,7 +33,7 @@ struct prism2_wep_data {
u8 key[WEP_KEY_LEN + 1]; u8 key[WEP_KEY_LEN + 1];
u8 key_len; u8 key_len;
u8 key_idx; u8 key_idx;
struct crypto_tfm *tfm; struct crypto_blkcipher *tfm;
}; };
static void *prism2_wep_init(int keyidx) static void *prism2_wep_init(int keyidx)
...@@ -44,10 +45,11 @@ static void *prism2_wep_init(int keyidx) ...@@ -44,10 +45,11 @@ static void *prism2_wep_init(int keyidx)
goto fail; goto fail;
priv->key_idx = keyidx; priv->key_idx = keyidx;
priv->tfm = crypto_alloc_tfm("arc4", 0); priv->tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
if (priv->tfm == NULL) { if (IS_ERR(priv->tfm)) {
printk(KERN_DEBUG "ieee80211_crypt_wep: could not allocate " printk(KERN_DEBUG "ieee80211_crypt_wep: could not allocate "
"crypto API arc4\n"); "crypto API arc4\n");
priv->tfm = NULL;
goto fail; goto fail;
} }
...@@ -59,7 +61,7 @@ static void *prism2_wep_init(int keyidx) ...@@ -59,7 +61,7 @@ static void *prism2_wep_init(int keyidx)
fail: fail:
if (priv) { if (priv) {
if (priv->tfm) if (priv->tfm)
crypto_free_tfm(priv->tfm); crypto_free_blkcipher(priv->tfm);
kfree(priv); kfree(priv);
} }
return NULL; return NULL;
...@@ -69,7 +71,7 @@ static void prism2_wep_deinit(void *priv) ...@@ -69,7 +71,7 @@ static void prism2_wep_deinit(void *priv)
{ {
struct prism2_wep_data *_priv = priv; struct prism2_wep_data *_priv = priv;
if (_priv && _priv->tfm) if (_priv && _priv->tfm)
crypto_free_tfm(_priv->tfm); crypto_free_blkcipher(_priv->tfm);
kfree(priv); kfree(priv);
} }
...@@ -120,6 +122,7 @@ static int prism2_wep_build_iv(struct sk_buff *skb, int hdr_len, ...@@ -120,6 +122,7 @@ static int prism2_wep_build_iv(struct sk_buff *skb, int hdr_len,
static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv) static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
{ {
struct prism2_wep_data *wep = priv; struct prism2_wep_data *wep = priv;
struct blkcipher_desc desc = { .tfm = wep->tfm };
u32 crc, klen, len; u32 crc, klen, len;
u8 *pos, *icv; u8 *pos, *icv;
struct scatterlist sg; struct scatterlist sg;
...@@ -151,13 +154,11 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -151,13 +154,11 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
icv[2] = crc >> 16; icv[2] = crc >> 16;
icv[3] = crc >> 24; icv[3] = crc >> 24;
crypto_cipher_setkey(wep->tfm, key, klen); crypto_blkcipher_setkey(wep->tfm, key, klen);
sg.page = virt_to_page(pos); sg.page = virt_to_page(pos);
sg.offset = offset_in_page(pos); sg.offset = offset_in_page(pos);
sg.length = len + 4; sg.length = len + 4;
crypto_cipher_encrypt(wep->tfm, &sg, &sg, len + 4); return crypto_blkcipher_encrypt(&desc, &sg, &sg, len + 4);
return 0;
} }
/* Perform WEP decryption on given buffer. Buffer includes whole WEP part of /* Perform WEP decryption on given buffer. Buffer includes whole WEP part of
...@@ -170,6 +171,7 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -170,6 +171,7 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
static int prism2_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv) static int prism2_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
{ {
struct prism2_wep_data *wep = priv; struct prism2_wep_data *wep = priv;
struct blkcipher_desc desc = { .tfm = wep->tfm };
u32 crc, klen, plen; u32 crc, klen, plen;
u8 key[WEP_KEY_LEN + 3]; u8 key[WEP_KEY_LEN + 3];
u8 keyidx, *pos, icv[4]; u8 keyidx, *pos, icv[4];
...@@ -194,11 +196,12 @@ static int prism2_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -194,11 +196,12 @@ static int prism2_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
/* Apply RC4 to data and compute CRC32 over decrypted data */ /* Apply RC4 to data and compute CRC32 over decrypted data */
plen = skb->len - hdr_len - 8; plen = skb->len - hdr_len - 8;
crypto_cipher_setkey(wep->tfm, key, klen); crypto_blkcipher_setkey(wep->tfm, key, klen);
sg.page = virt_to_page(pos); sg.page = virt_to_page(pos);
sg.offset = offset_in_page(pos); sg.offset = offset_in_page(pos);
sg.length = plen + 4; sg.length = plen + 4;
crypto_cipher_decrypt(wep->tfm, &sg, &sg, plen + 4); if (crypto_blkcipher_decrypt(&desc, &sg, &sg, plen + 4))
return -7;
crc = ~crc32_le(~0, pos, plen); crc = ~crc32_le(~0, pos, plen);
icv[0] = crc; icv[0] = crc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment