aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2006-08-22 06:36:13 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2006-09-20 21:46:15 -0400
commitf12cc2090d721647c23dfce20834f4306db3b77d (patch)
treefba6861bdb58153acaab1ba1e51ec4e48fe0fd99 /drivers/net
parent378c6697a282c383d89428380a3405bf95189347 (diff)
[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: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/ppp_mppe.c32
-rw-r--r--drivers/net/wireless/airo.c22
2 files changed, 31 insertions, 23 deletions
diff --git a/drivers/net/ppp_mppe.c b/drivers/net/ppp_mppe.c
index 51ff9a9d1bb5..495d8667419a 100644
--- a/drivers/net/ppp_mppe.c
+++ b/drivers/net/ppp_mppe.c
@@ -43,6 +43,7 @@
43 * deprecated in 2.6 43 * deprecated in 2.6
44 */ 44 */
45 45
46#include <linux/err.h>
46#include <linux/module.h> 47#include <linux/module.h>
47#include <linux/kernel.h> 48#include <linux/kernel.h>
48#include <linux/version.h> 49#include <linux/version.h>
@@ -95,7 +96,7 @@ static inline void sha_pad_init(struct sha_pad *shapad)
95 * State for an MPPE (de)compressor. 96 * State for an MPPE (de)compressor.
96 */ 97 */
97struct ppp_mppe_state { 98struct ppp_mppe_state {
98 struct crypto_tfm *arc4; 99 struct crypto_blkcipher *arc4;
99 struct crypto_tfm *sha1; 100 struct crypto_tfm *sha1;
100 unsigned char *sha1_digest; 101 unsigned char *sha1_digest;
101 unsigned char master_key[MPPE_MAX_KEY_LEN]; 102 unsigned char master_key[MPPE_MAX_KEY_LEN];
@@ -156,14 +157,15 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
156{ 157{
157 unsigned char InterimKey[MPPE_MAX_KEY_LEN]; 158 unsigned char InterimKey[MPPE_MAX_KEY_LEN];
158 struct scatterlist sg_in[1], sg_out[1]; 159 struct scatterlist sg_in[1], sg_out[1];
160 struct blkcipher_desc desc = { .tfm = state->arc4 };
159 161
160 get_new_key_from_sha(state, InterimKey); 162 get_new_key_from_sha(state, InterimKey);
161 if (!initial_key) { 163 if (!initial_key) {
162 crypto_cipher_setkey(state->arc4, InterimKey, state->keylen); 164 crypto_blkcipher_setkey(state->arc4, InterimKey, state->keylen);
163 setup_sg(sg_in, InterimKey, state->keylen); 165 setup_sg(sg_in, InterimKey, state->keylen);
164 setup_sg(sg_out, state->session_key, state->keylen); 166 setup_sg(sg_out, state->session_key, state->keylen);
165 if (crypto_cipher_encrypt(state->arc4, sg_out, sg_in, 167 if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
166 state->keylen) != 0) { 168 state->keylen) != 0) {
167 printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n"); 169 printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n");
168 } 170 }
169 } else { 171 } else {
@@ -175,7 +177,7 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
175 state->session_key[1] = 0x26; 177 state->session_key[1] = 0x26;
176 state->session_key[2] = 0x9e; 178 state->session_key[2] = 0x9e;
177 } 179 }
178 crypto_cipher_setkey(state->arc4, state->session_key, state->keylen); 180 crypto_blkcipher_setkey(state->arc4, state->session_key, state->keylen);
179} 181}
180 182
181/* 183/*
@@ -196,9 +198,11 @@ static void *mppe_alloc(unsigned char *options, int optlen)
196 198
197 memset(state, 0, sizeof(*state)); 199 memset(state, 0, sizeof(*state));
198 200
199 state->arc4 = crypto_alloc_tfm("arc4", 0); 201 state->arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
200 if (!state->arc4) 202 if (IS_ERR(state->arc4)) {
203 state->arc4 = NULL;
201 goto out_free; 204 goto out_free;
205 }
202 206
203 state->sha1 = crypto_alloc_tfm("sha1", 0); 207 state->sha1 = crypto_alloc_tfm("sha1", 0);
204 if (!state->sha1) 208 if (!state->sha1)
@@ -231,7 +235,7 @@ static void *mppe_alloc(unsigned char *options, int optlen)
231 if (state->sha1) 235 if (state->sha1)
232 crypto_free_tfm(state->sha1); 236 crypto_free_tfm(state->sha1);
233 if (state->arc4) 237 if (state->arc4)
234 crypto_free_tfm(state->arc4); 238 crypto_free_blkcipher(state->arc4);
235 kfree(state); 239 kfree(state);
236 out: 240 out:
237 return NULL; 241 return NULL;
@@ -249,7 +253,7 @@ static void mppe_free(void *arg)
249 if (state->sha1) 253 if (state->sha1)
250 crypto_free_tfm(state->sha1); 254 crypto_free_tfm(state->sha1);
251 if (state->arc4) 255 if (state->arc4)
252 crypto_free_tfm(state->arc4); 256 crypto_free_blkcipher(state->arc4);
253 kfree(state); 257 kfree(state);
254 } 258 }
255} 259}
@@ -356,6 +360,7 @@ mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
356 int isize, int osize) 360 int isize, int osize)
357{ 361{
358 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; 362 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
363 struct blkcipher_desc desc = { .tfm = state->arc4 };
359 int proto; 364 int proto;
360 struct scatterlist sg_in[1], sg_out[1]; 365 struct scatterlist sg_in[1], sg_out[1];
361 366
@@ -413,7 +418,7 @@ mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
413 /* Encrypt packet */ 418 /* Encrypt packet */
414 setup_sg(sg_in, ibuf, isize); 419 setup_sg(sg_in, ibuf, isize);
415 setup_sg(sg_out, obuf, osize); 420 setup_sg(sg_out, obuf, osize);
416 if (crypto_cipher_encrypt(state->arc4, sg_out, sg_in, isize) != 0) { 421 if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in, isize) != 0) {
417 printk(KERN_DEBUG "crypto_cypher_encrypt failed\n"); 422 printk(KERN_DEBUG "crypto_cypher_encrypt failed\n");
418 return -1; 423 return -1;
419 } 424 }
@@ -462,6 +467,7 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
462 int osize) 467 int osize)
463{ 468{
464 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; 469 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
470 struct blkcipher_desc desc = { .tfm = state->arc4 };
465 unsigned ccount; 471 unsigned ccount;
466 int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED; 472 int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED;
467 int sanity = 0; 473 int sanity = 0;
@@ -599,7 +605,7 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
599 */ 605 */
600 setup_sg(sg_in, ibuf, 1); 606 setup_sg(sg_in, ibuf, 1);
601 setup_sg(sg_out, obuf, 1); 607 setup_sg(sg_out, obuf, 1);
602 if (crypto_cipher_decrypt(state->arc4, sg_out, sg_in, 1) != 0) { 608 if (crypto_blkcipher_decrypt(&desc, sg_out, sg_in, 1) != 0) {
603 printk(KERN_DEBUG "crypto_cypher_decrypt failed\n"); 609 printk(KERN_DEBUG "crypto_cypher_decrypt failed\n");
604 return DECOMP_ERROR; 610 return DECOMP_ERROR;
605 } 611 }
@@ -619,7 +625,7 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
619 /* And finally, decrypt the rest of the packet. */ 625 /* And finally, decrypt the rest of the packet. */
620 setup_sg(sg_in, ibuf + 1, isize - 1); 626 setup_sg(sg_in, ibuf + 1, isize - 1);
621 setup_sg(sg_out, obuf + 1, osize - 1); 627 setup_sg(sg_out, obuf + 1, osize - 1);
622 if (crypto_cipher_decrypt(state->arc4, sg_out, sg_in, isize - 1) != 0) { 628 if (crypto_blkcipher_decrypt(&desc, sg_out, sg_in, isize - 1)) {
623 printk(KERN_DEBUG "crypto_cypher_decrypt failed\n"); 629 printk(KERN_DEBUG "crypto_cypher_decrypt failed\n");
624 return DECOMP_ERROR; 630 return DECOMP_ERROR;
625 } 631 }
@@ -694,7 +700,7 @@ static struct compressor ppp_mppe = {
694static int __init ppp_mppe_init(void) 700static int __init ppp_mppe_init(void)
695{ 701{
696 int answer; 702 int answer;
697 if (!(crypto_alg_available("arc4", 0) && 703 if (!(crypto_alg_available("ecb(arc4)", 0) &&
698 crypto_alg_available("sha1", 0))) 704 crypto_alg_available("sha1", 0)))
699 return -ENODEV; 705 return -ENODEV;
700 706
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index a4dd13942714..170c500169da 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -19,6 +19,7 @@
19 19
20======================================================================*/ 20======================================================================*/
21 21
22#include <linux/err.h>
22#include <linux/init.h> 23#include <linux/init.h>
23 24
24#include <linux/kernel.h> 25#include <linux/kernel.h>
@@ -1203,7 +1204,7 @@ struct airo_info {
1203 struct iw_spy_data spy_data; 1204 struct iw_spy_data spy_data;
1204 struct iw_public_data wireless_data; 1205 struct iw_public_data wireless_data;
1205 /* MIC stuff */ 1206 /* MIC stuff */
1206 struct crypto_tfm *tfm; 1207 struct crypto_cipher *tfm;
1207 mic_module mod[2]; 1208 mic_module mod[2];
1208 mic_statistics micstats; 1209 mic_statistics micstats;
1209 HostRxDesc rxfids[MPI_MAX_FIDS]; // rx/tx/config MPI350 descriptors 1210 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 1272
1272static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq); 1273static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq);
1273static void MoveWindow(miccntx *context, u32 micSeq); 1274static void MoveWindow(miccntx *context, u32 micSeq);
1274static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *); 1275static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
1276 struct crypto_cipher *tfm);
1275static void emmh32_init(emmh32_context *context); 1277static void emmh32_init(emmh32_context *context);
1276static void emmh32_update(emmh32_context *context, u8 *pOctets, int len); 1278static void emmh32_update(emmh32_context *context, u8 *pOctets, int len);
1277static void emmh32_final(emmh32_context *context, u8 digest[4]); 1279static void emmh32_final(emmh32_context *context, u8 digest[4]);
@@ -1339,10 +1341,11 @@ static int micsetup(struct airo_info *ai) {
1339 int i; 1341 int i;
1340 1342
1341 if (ai->tfm == NULL) 1343 if (ai->tfm == NULL)
1342 ai->tfm = crypto_alloc_tfm("aes", CRYPTO_TFM_REQ_MAY_SLEEP); 1344 ai->tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
1343 1345
1344 if (ai->tfm == NULL) { 1346 if (IS_ERR(ai->tfm)) {
1345 airo_print_err(ai->dev->name, "failed to load transform for AES"); 1347 airo_print_err(ai->dev->name, "failed to load transform for AES");
1348 ai->tfm = NULL;
1346 return ERROR; 1349 return ERROR;
1347 } 1350 }
1348 1351
@@ -1608,7 +1611,8 @@ static void MoveWindow(miccntx *context, u32 micSeq)
1608static unsigned char aes_counter[16]; 1611static unsigned char aes_counter[16];
1609 1612
1610/* expand the key to fill the MMH coefficient array */ 1613/* expand the key to fill the MMH coefficient array */
1611static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *tfm) 1614static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
1615 struct crypto_cipher *tfm)
1612{ 1616{
1613 /* take the keying material, expand if necessary, truncate at 16-bytes */ 1617 /* take the keying material, expand if necessary, truncate at 16-bytes */
1614 /* run through AES counter mode to generate context->coeff[] */ 1618 /* 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 int i,j; 1620 int i,j;
1617 u32 counter; 1621 u32 counter;
1618 u8 *cipher, plain[16]; 1622 u8 *cipher, plain[16];
1619 struct scatterlist sg[1];
1620 1623
1621 crypto_cipher_setkey(tfm, pkey, 16); 1624 crypto_cipher_setkey(tfm, pkey, 16);
1622 counter = 0; 1625 counter = 0;
@@ -1627,9 +1630,8 @@ static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct
1627 aes_counter[12] = (u8)(counter >> 24); 1630 aes_counter[12] = (u8)(counter >> 24);
1628 counter++; 1631 counter++;
1629 memcpy (plain, aes_counter, 16); 1632 memcpy (plain, aes_counter, 16);
1630 sg_set_buf(sg, plain, 16); 1633 crypto_cipher_encrypt_one(tfm, plain, plain);
1631 crypto_cipher_encrypt(tfm, sg, sg, 16); 1634 cipher = plain;
1632 cipher = kmap(sg->page) + sg->offset;
1633 for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) { 1635 for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) {
1634 context->coeff[i++] = ntohl(*(u32 *)&cipher[j]); 1636 context->coeff[i++] = ntohl(*(u32 *)&cipher[j]);
1635 j += 4; 1637 j += 4;
@@ -2432,7 +2434,7 @@ void stop_airo_card( struct net_device *dev, int freeres )
2432 ai->shared, ai->shared_dma); 2434 ai->shared, ai->shared_dma);
2433 } 2435 }
2434 } 2436 }
2435 crypto_free_tfm(ai->tfm); 2437 crypto_free_cipher(ai->tfm);
2436 del_airo_dev( dev ); 2438 del_airo_dev( dev );
2437 free_netdev( dev ); 2439 free_netdev( dev );
2438} 2440}