sysfs: add struct file* to bin_attr callbacks
[safe/jmp/linux-2.6] / drivers / net / ppp_mppe.c
index 495d866..6d1a1b8 100644 (file)
@@ -46,7 +46,6 @@
 #include <linux/err.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/version.h>
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/slab.h>
@@ -55,7 +54,7 @@
 #include <linux/mm.h>
 #include <linux/ppp_defs.h>
 #include <linux/ppp-comp.h>
-#include <asm/scatterlist.h>
+#include <linux/scatterlist.h>
 
 #include "ppp_mppe.h"
 
@@ -65,12 +64,11 @@ MODULE_LICENSE("Dual BSD/GPL");
 MODULE_ALIAS("ppp-compress-" __stringify(CI_MPPE));
 MODULE_VERSION("1.0.2");
 
-static void
+static unsigned int
 setup_sg(struct scatterlist *sg, const void *address, unsigned int length)
 {
-       sg[0].page = virt_to_page(address);
-       sg[0].offset = offset_in_page(address);
-       sg[0].length = length;
+       sg_set_buf(sg, address, length);
+       return length;
 }
 
 #define SHA1_PAD_SIZE 40
@@ -97,7 +95,7 @@ static inline void sha_pad_init(struct sha_pad *shapad)
  */
 struct ppp_mppe_state {
        struct crypto_blkcipher *arc4;
-       struct crypto_tfm *sha1;
+       struct crypto_hash *sha1;
        unsigned char *sha1_digest;
        unsigned char master_key[MPPE_MAX_KEY_LEN];
        unsigned char session_key[MPPE_MAX_KEY_LEN];
@@ -135,18 +133,25 @@ struct ppp_mppe_state {
  * Key Derivation, from RFC 3078, RFC 3079.
  * Equivalent to Get_Key() for MS-CHAP as described in RFC 3079.
  */
-static void get_new_key_from_sha(struct ppp_mppe_state * state, unsigned char *InterimKey)
+static void get_new_key_from_sha(struct ppp_mppe_state * state)
 {
+       struct hash_desc desc;
        struct scatterlist sg[4];
+       unsigned int nbytes;
 
-       setup_sg(&sg[0], state->master_key, state->keylen);
-       setup_sg(&sg[1], sha_pad->sha_pad1, sizeof(sha_pad->sha_pad1));
-       setup_sg(&sg[2], state->session_key, state->keylen);
-       setup_sg(&sg[3], sha_pad->sha_pad2, sizeof(sha_pad->sha_pad2));
+       sg_init_table(sg, 4);
 
-       crypto_digest_digest (state->sha1, sg, 4, state->sha1_digest);
+       nbytes = setup_sg(&sg[0], state->master_key, state->keylen);
+       nbytes += setup_sg(&sg[1], sha_pad->sha_pad1,
+                          sizeof(sha_pad->sha_pad1));
+       nbytes += setup_sg(&sg[2], state->session_key, state->keylen);
+       nbytes += setup_sg(&sg[3], sha_pad->sha_pad2,
+                          sizeof(sha_pad->sha_pad2));
 
-       memcpy(InterimKey, state->sha1_digest, state->keylen);
+       desc.tfm = state->sha1;
+       desc.flags = 0;
+
+       crypto_hash_digest(&desc, sg, nbytes, state->sha1_digest);
 }
 
 /*
@@ -155,21 +160,23 @@ static void get_new_key_from_sha(struct ppp_mppe_state * state, unsigned char *I
  */
 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);
+       get_new_key_from_sha(state);
        if (!initial_key) {
-               crypto_blkcipher_setkey(state->arc4, InterimKey, state->keylen);
-               setup_sg(sg_in, InterimKey, state->keylen);
+               crypto_blkcipher_setkey(state->arc4, state->sha1_digest,
+                                       state->keylen);
+               sg_init_table(sg_in, 1);
+               sg_init_table(sg_out, 1);
+               setup_sg(sg_in, state->sha1_digest, state->keylen);
                setup_sg(sg_out, state->session_key, state->keylen);
                if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
                                             state->keylen) != 0) {
                    printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n");
                }
        } else {
-               memcpy(state->session_key, InterimKey, state->keylen);
+               memcpy(state->session_key, state->sha1_digest, state->keylen);
        }
        if (state->keylen == 8) {
                /* See RFC 3078 */
@@ -188,15 +195,14 @@ static void *mppe_alloc(unsigned char *options, int optlen)
        struct ppp_mppe_state *state;
        unsigned int digestsize;
 
-       if (optlen != CILEN_MPPE + sizeof(state->master_key)
-           || options[0] != CI_MPPE || options[1] != CILEN_MPPE)
+       if (optlen != CILEN_MPPE + sizeof(state->master_key) ||
+           options[0] != CI_MPPE || options[1] != CILEN_MPPE)
                goto out;
 
-       state = (struct ppp_mppe_state *) kmalloc(sizeof(*state), GFP_KERNEL);
+       state = kzalloc(sizeof(*state), GFP_KERNEL);
        if (state == NULL)
                goto out;
 
-       memset(state, 0, sizeof(*state));
 
        state->arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
        if (IS_ERR(state->arc4)) {
@@ -204,11 +210,13 @@ static void *mppe_alloc(unsigned char *options, int optlen)
                goto out_free;
        }
 
-       state->sha1 = crypto_alloc_tfm("sha1", 0);
-       if (!state->sha1)
+       state->sha1 = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC);
+       if (IS_ERR(state->sha1)) {
+               state->sha1 = NULL;
                goto out_free;
+       }
 
-       digestsize = crypto_tfm_alg_digestsize(state->sha1);
+       digestsize = crypto_hash_digestsize(state->sha1);
        if (digestsize < MPPE_MAX_KEY_LEN)
                goto out_free;
 
@@ -233,7 +241,7 @@ static void *mppe_alloc(unsigned char *options, int optlen)
            if (state->sha1_digest)
                kfree(state->sha1_digest);
            if (state->sha1)
-               crypto_free_tfm(state->sha1);
+               crypto_free_hash(state->sha1);
            if (state->arc4)
                crypto_free_blkcipher(state->arc4);
            kfree(state);
@@ -251,7 +259,7 @@ static void mppe_free(void *arg)
            if (state->sha1_digest)
                kfree(state->sha1_digest);
            if (state->sha1)
-               crypto_free_tfm(state->sha1);
+               crypto_free_hash(state->sha1);
            if (state->arc4)
                crypto_free_blkcipher(state->arc4);
            kfree(state);
@@ -268,8 +276,8 @@ mppe_init(void *arg, unsigned char *options, int optlen, int unit, int debug,
        struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
        unsigned char mppe_opts;
 
-       if (optlen != CILEN_MPPE
-           || options[0] != CI_MPPE || options[1] != CILEN_MPPE)
+       if (optlen != CILEN_MPPE ||
+           options[0] != CI_MPPE || options[1] != CILEN_MPPE)
                return 0;
 
        MPPE_CI_TO_OPTS(&options[2], mppe_opts);
@@ -416,6 +424,8 @@ mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
        isize -= 2;
 
        /* Encrypt packet */
+       sg_init_table(sg_in, 1);
+       sg_init_table(sg_out, 1);
        setup_sg(sg_in, ibuf, isize);
        setup_sg(sg_out, obuf, osize);
        if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in, isize) != 0) {
@@ -603,6 +613,8 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
         * Decrypt the first byte in order to check if it is
         * a compressed or uncompressed protocol field.
         */
+       sg_init_table(sg_in, 1);
+       sg_init_table(sg_out, 1);
        setup_sg(sg_in, ibuf, 1);
        setup_sg(sg_out, obuf, 1);
        if (crypto_blkcipher_decrypt(&desc, sg_out, sg_in, 1) != 0) {
@@ -700,8 +712,8 @@ static struct compressor ppp_mppe = {
 static int __init ppp_mppe_init(void)
 {
        int answer;
-       if (!(crypto_alg_available("ecb(arc4)", 0) &&
-             crypto_alg_available("sha1", 0)))
+       if (!(crypto_has_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC) &&
+             crypto_has_hash("sha1", 0, CRYPTO_ALG_ASYNC)))
                return -ENODEV;
 
        sha_pad = kmalloc(sizeof(struct sha_pad), GFP_KERNEL);