[CRYPTO] users: Use block ciphers where applicable
[safe/jmp/linux-2.6] / drivers / net / ppp_mppe.c
index 51ff9a9..495d866 100644 (file)
@@ -43,6 +43,7 @@
  *                    deprecated in 2.6
  */
 
+#include <linux/err.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/version.h>
@@ -95,7 +96,7 @@ static inline void sha_pad_init(struct sha_pad *shapad)
  * State for an MPPE (de)compressor.
  */
 struct ppp_mppe_state {
-       struct crypto_tfm *arc4;
+       struct crypto_blkcipher *arc4;
        struct crypto_tfm *sha1;
        unsigned char *sha1_digest;
        unsigned char master_key[MPPE_MAX_KEY_LEN];
@@ -156,14 +157,15 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
 {
        unsigned char InterimKey[MPPE_MAX_KEY_LEN];
        struct scatterlist sg_in[1], sg_out[1];
+       struct blkcipher_desc desc = { .tfm = state->arc4 };
 
        get_new_key_from_sha(state, InterimKey);
        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_out, state->session_key, state->keylen);
-               if (crypto_cipher_encrypt(state->arc4, sg_out, sg_in,
-                                     state->keylen) != 0) {
+               if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
+                                            state->keylen) != 0) {
                    printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n");
                }
        } else {
@@ -175,7 +177,7 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
                state->session_key[1] = 0x26;
                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)
 
        memset(state, 0, sizeof(*state));
 
-       state->arc4 = crypto_alloc_tfm("arc4", 0);
-       if (!state->arc4)
+       state->arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
+       if (IS_ERR(state->arc4)) {
+               state->arc4 = NULL;
                goto out_free;
+       }
 
        state->sha1 = crypto_alloc_tfm("sha1", 0);
        if (!state->sha1)
@@ -231,7 +235,7 @@ static void *mppe_alloc(unsigned char *options, int optlen)
            if (state->sha1)
                crypto_free_tfm(state->sha1);
            if (state->arc4)
-               crypto_free_tfm(state->arc4);
+               crypto_free_blkcipher(state->arc4);
            kfree(state);
        out:
        return NULL;
@@ -249,7 +253,7 @@ static void mppe_free(void *arg)
            if (state->sha1)
                crypto_free_tfm(state->sha1);
            if (state->arc4)
-               crypto_free_tfm(state->arc4);
+               crypto_free_blkcipher(state->arc4);
            kfree(state);
        }
 }
@@ -356,6 +360,7 @@ mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
              int isize, int osize)
 {
        struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
+       struct blkcipher_desc desc = { .tfm = state->arc4 };
        int proto;
        struct scatterlist sg_in[1], sg_out[1];
 
@@ -413,7 +418,7 @@ mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
        /* Encrypt packet */
        setup_sg(sg_in, ibuf, isize);
        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");
                return -1;
        }
@@ -462,6 +467,7 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
                int osize)
 {
        struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
+       struct blkcipher_desc desc = { .tfm = state->arc4 };
        unsigned ccount;
        int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED;
        int sanity = 0;
@@ -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_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");
                return DECOMP_ERROR;
        }
@@ -619,7 +625,7 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
        /* And finally, decrypt the rest of the packet. */
        setup_sg(sg_in, ibuf + 1, isize - 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");
                return DECOMP_ERROR;
        }
@@ -694,7 +700,7 @@ static struct compressor ppp_mppe = {
 static int __init ppp_mppe_init(void)
 {
        int answer;
-       if (!(crypto_alg_available("arc4", 0) &&
+       if (!(crypto_alg_available("ecb(arc4)", 0) &&
              crypto_alg_available("sha1", 0)))
                return -ENODEV;