Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * ppp_mppe.c - interface MPPE to the PPP code.
0003  * This version is for use with Linux kernel 2.6.14+
0004  *
0005  * By Frank Cusack <fcusack@fcusack.com>.
0006  * Copyright (c) 2002,2003,2004 Google, Inc.
0007  * All rights reserved.
0008  *
0009  * License:
0010  * Permission to use, copy, modify, and distribute this software and its
0011  * documentation is hereby granted, provided that the above copyright
0012  * notice appears in all copies.  This software is provided without any
0013  * warranty, express or implied.
0014  *
0015  * ALTERNATIVELY, provided that this notice is retained in full, this product
0016  * may be distributed under the terms of the GNU General Public License (GPL),
0017  * in which case the provisions of the GPL apply INSTEAD OF those given above.
0018  *
0019  *   This program is free software; you can redistribute it and/or modify
0020  *   it under the terms of the GNU General Public License as published by
0021  *   the Free Software Foundation; either version 2 of the License, or
0022  *   (at your option) any later version.
0023  *
0024  *   This program is distributed in the hope that it will be useful,
0025  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0026  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0027  *   GNU General Public License for more details.
0028  *
0029  *   You should have received a copy of the GNU General Public License
0030  *   along with this program; if not, see <http://www.gnu.org/licenses/>.
0031  *
0032  *
0033  * Changelog:
0034  *      08/12/05 - Matt Domsch <Matt_Domsch@dell.com>
0035  *                 Only need extra skb padding on transmit, not receive.
0036  *      06/18/04 - Matt Domsch <Matt_Domsch@dell.com>, Oleg Makarenko <mole@quadra.ru>
0037  *                 Use Linux kernel 2.6 arc4 and sha1 routines rather than
0038  *                 providing our own.
0039  *      2/15/04 - TS: added #include <version.h> and testing for Kernel
0040  *                    version before using
0041  *                    MOD_DEC_USAGE_COUNT/MOD_INC_USAGE_COUNT which are
0042  *                    deprecated in 2.6
0043  */
0044 
0045 #include <crypto/arc4.h>
0046 #include <crypto/hash.h>
0047 #include <linux/err.h>
0048 #include <linux/fips.h>
0049 #include <linux/module.h>
0050 #include <linux/kernel.h>
0051 #include <linux/init.h>
0052 #include <linux/types.h>
0053 #include <linux/slab.h>
0054 #include <linux/string.h>
0055 #include <linux/mm.h>
0056 #include <linux/ppp_defs.h>
0057 #include <linux/ppp-comp.h>
0058 #include <linux/scatterlist.h>
0059 #include <asm/unaligned.h>
0060 
0061 #include "ppp_mppe.h"
0062 
0063 MODULE_AUTHOR("Frank Cusack <fcusack@fcusack.com>");
0064 MODULE_DESCRIPTION("Point-to-Point Protocol Microsoft Point-to-Point Encryption support");
0065 MODULE_LICENSE("Dual BSD/GPL");
0066 MODULE_ALIAS("ppp-compress-" __stringify(CI_MPPE));
0067 MODULE_VERSION("1.0.2");
0068 
0069 #define SHA1_PAD_SIZE 40
0070 
0071 /*
0072  * kernel crypto API needs its arguments to be in kmalloc'd memory, not in the module
0073  * static data area.  That means sha_pad needs to be kmalloc'd.
0074  */
0075 
0076 struct sha_pad {
0077     unsigned char sha_pad1[SHA1_PAD_SIZE];
0078     unsigned char sha_pad2[SHA1_PAD_SIZE];
0079 };
0080 static struct sha_pad *sha_pad;
0081 
0082 static inline void sha_pad_init(struct sha_pad *shapad)
0083 {
0084     memset(shapad->sha_pad1, 0x00, sizeof(shapad->sha_pad1));
0085     memset(shapad->sha_pad2, 0xF2, sizeof(shapad->sha_pad2));
0086 }
0087 
0088 /*
0089  * State for an MPPE (de)compressor.
0090  */
0091 struct ppp_mppe_state {
0092     struct arc4_ctx arc4;
0093     struct shash_desc *sha1;
0094     unsigned char *sha1_digest;
0095     unsigned char master_key[MPPE_MAX_KEY_LEN];
0096     unsigned char session_key[MPPE_MAX_KEY_LEN];
0097     unsigned keylen;    /* key length in bytes             */
0098     /* NB: 128-bit == 16, 40-bit == 8! */
0099     /* If we want to support 56-bit,   */
0100     /* the unit has to change to bits  */
0101     unsigned char bits; /* MPPE control bits */
0102     unsigned ccount;    /* 12-bit coherency count (seqno)  */
0103     unsigned stateful;  /* stateful mode flag */
0104     int discard;        /* stateful mode packet loss flag */
0105     int sanity_errors;  /* take down LCP if too many */
0106     int unit;
0107     int debug;
0108     struct compstat stats;
0109 };
0110 
0111 /* struct ppp_mppe_state.bits definitions */
0112 #define MPPE_BIT_A  0x80    /* Encryption table were (re)inititalized */
0113 #define MPPE_BIT_B  0x40    /* MPPC only (not implemented) */
0114 #define MPPE_BIT_C  0x20    /* MPPC only (not implemented) */
0115 #define MPPE_BIT_D  0x10    /* This is an encrypted frame */
0116 
0117 #define MPPE_BIT_FLUSHED    MPPE_BIT_A
0118 #define MPPE_BIT_ENCRYPTED  MPPE_BIT_D
0119 
0120 #define MPPE_BITS(p) ((p)[4] & 0xf0)
0121 #define MPPE_CCOUNT(p) ((((p)[4] & 0x0f) << 8) + (p)[5])
0122 #define MPPE_CCOUNT_SPACE 0x1000    /* The size of the ccount space */
0123 
0124 #define MPPE_OVHD   2   /* MPPE overhead/packet */
0125 #define SANITY_MAX  1600    /* Max bogon factor we will tolerate */
0126 
0127 /*
0128  * Key Derivation, from RFC 3078, RFC 3079.
0129  * Equivalent to Get_Key() for MS-CHAP as described in RFC 3079.
0130  */
0131 static void get_new_key_from_sha(struct ppp_mppe_state * state)
0132 {
0133     crypto_shash_init(state->sha1);
0134     crypto_shash_update(state->sha1, state->master_key,
0135                 state->keylen);
0136     crypto_shash_update(state->sha1, sha_pad->sha_pad1,
0137                 sizeof(sha_pad->sha_pad1));
0138     crypto_shash_update(state->sha1, state->session_key,
0139                 state->keylen);
0140     crypto_shash_update(state->sha1, sha_pad->sha_pad2,
0141                 sizeof(sha_pad->sha_pad2));
0142     crypto_shash_final(state->sha1, state->sha1_digest);
0143 }
0144 
0145 /*
0146  * Perform the MPPE rekey algorithm, from RFC 3078, sec. 7.3.
0147  * Well, not what's written there, but rather what they meant.
0148  */
0149 static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
0150 {
0151     get_new_key_from_sha(state);
0152     if (!initial_key) {
0153         arc4_setkey(&state->arc4, state->sha1_digest, state->keylen);
0154         arc4_crypt(&state->arc4, state->session_key, state->sha1_digest,
0155                state->keylen);
0156     } else {
0157         memcpy(state->session_key, state->sha1_digest, state->keylen);
0158     }
0159     if (state->keylen == 8) {
0160         /* See RFC 3078 */
0161         state->session_key[0] = 0xd1;
0162         state->session_key[1] = 0x26;
0163         state->session_key[2] = 0x9e;
0164     }
0165     arc4_setkey(&state->arc4, state->session_key, state->keylen);
0166 }
0167 
0168 /*
0169  * Allocate space for a (de)compressor.
0170  */
0171 static void *mppe_alloc(unsigned char *options, int optlen)
0172 {
0173     struct ppp_mppe_state *state;
0174     struct crypto_shash *shash;
0175     unsigned int digestsize;
0176 
0177     if (optlen != CILEN_MPPE + sizeof(state->master_key) ||
0178         options[0] != CI_MPPE || options[1] != CILEN_MPPE ||
0179         fips_enabled)
0180         goto out;
0181 
0182     state = kzalloc(sizeof(*state), GFP_KERNEL);
0183     if (state == NULL)
0184         goto out;
0185 
0186 
0187     shash = crypto_alloc_shash("sha1", 0, 0);
0188     if (IS_ERR(shash))
0189         goto out_free;
0190 
0191     state->sha1 = kmalloc(sizeof(*state->sha1) +
0192                      crypto_shash_descsize(shash),
0193                   GFP_KERNEL);
0194     if (!state->sha1) {
0195         crypto_free_shash(shash);
0196         goto out_free;
0197     }
0198     state->sha1->tfm = shash;
0199 
0200     digestsize = crypto_shash_digestsize(shash);
0201     if (digestsize < MPPE_MAX_KEY_LEN)
0202         goto out_free;
0203 
0204     state->sha1_digest = kmalloc(digestsize, GFP_KERNEL);
0205     if (!state->sha1_digest)
0206         goto out_free;
0207 
0208     /* Save keys. */
0209     memcpy(state->master_key, &options[CILEN_MPPE],
0210            sizeof(state->master_key));
0211     memcpy(state->session_key, state->master_key,
0212            sizeof(state->master_key));
0213 
0214     /*
0215      * We defer initial key generation until mppe_init(), as mppe_alloc()
0216      * is called frequently during negotiation.
0217      */
0218 
0219     return (void *)state;
0220 
0221 out_free:
0222     kfree(state->sha1_digest);
0223     if (state->sha1) {
0224         crypto_free_shash(state->sha1->tfm);
0225         kfree_sensitive(state->sha1);
0226     }
0227     kfree(state);
0228 out:
0229     return NULL;
0230 }
0231 
0232 /*
0233  * Deallocate space for a (de)compressor.
0234  */
0235 static void mppe_free(void *arg)
0236 {
0237     struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
0238     if (state) {
0239         kfree(state->sha1_digest);
0240         crypto_free_shash(state->sha1->tfm);
0241         kfree_sensitive(state->sha1);
0242         kfree_sensitive(state);
0243     }
0244 }
0245 
0246 /*
0247  * Initialize (de)compressor state.
0248  */
0249 static int
0250 mppe_init(void *arg, unsigned char *options, int optlen, int unit, int debug,
0251       const char *debugstr)
0252 {
0253     struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
0254     unsigned char mppe_opts;
0255 
0256     if (optlen != CILEN_MPPE ||
0257         options[0] != CI_MPPE || options[1] != CILEN_MPPE)
0258         return 0;
0259 
0260     MPPE_CI_TO_OPTS(&options[2], mppe_opts);
0261     if (mppe_opts & MPPE_OPT_128)
0262         state->keylen = 16;
0263     else if (mppe_opts & MPPE_OPT_40)
0264         state->keylen = 8;
0265     else {
0266         printk(KERN_WARNING "%s[%d]: unknown key length\n", debugstr,
0267                unit);
0268         return 0;
0269     }
0270     if (mppe_opts & MPPE_OPT_STATEFUL)
0271         state->stateful = 1;
0272 
0273     /* Generate the initial session key. */
0274     mppe_rekey(state, 1);
0275 
0276     if (debug) {
0277         printk(KERN_DEBUG "%s[%d]: initialized with %d-bit %s mode\n",
0278                debugstr, unit, (state->keylen == 16) ? 128 : 40,
0279                (state->stateful) ? "stateful" : "stateless");
0280         printk(KERN_DEBUG
0281                "%s[%d]: keys: master: %*phN initial session: %*phN\n",
0282                debugstr, unit,
0283                (int)sizeof(state->master_key), state->master_key,
0284                (int)sizeof(state->session_key), state->session_key);
0285     }
0286 
0287     /*
0288      * Initialize the coherency count.  The initial value is not specified
0289      * in RFC 3078, but we can make a reasonable assumption that it will
0290      * start at 0.  Setting it to the max here makes the comp/decomp code
0291      * do the right thing (determined through experiment).
0292      */
0293     state->ccount = MPPE_CCOUNT_SPACE - 1;
0294 
0295     /*
0296      * Note that even though we have initialized the key table, we don't
0297      * set the FLUSHED bit.  This is contrary to RFC 3078, sec. 3.1.
0298      */
0299     state->bits = MPPE_BIT_ENCRYPTED;
0300 
0301     state->unit = unit;
0302     state->debug = debug;
0303 
0304     return 1;
0305 }
0306 
0307 static int
0308 mppe_comp_init(void *arg, unsigned char *options, int optlen, int unit,
0309            int hdrlen, int debug)
0310 {
0311     /* ARGSUSED */
0312     return mppe_init(arg, options, optlen, unit, debug, "mppe_comp_init");
0313 }
0314 
0315 /*
0316  * We received a CCP Reset-Request (actually, we are sending a Reset-Ack),
0317  * tell the compressor to rekey.  Note that we MUST NOT rekey for
0318  * every CCP Reset-Request; we only rekey on the next xmit packet.
0319  * We might get multiple CCP Reset-Requests if our CCP Reset-Ack is lost.
0320  * So, rekeying for every CCP Reset-Request is broken as the peer will not
0321  * know how many times we've rekeyed.  (If we rekey and THEN get another
0322  * CCP Reset-Request, we must rekey again.)
0323  */
0324 static void mppe_comp_reset(void *arg)
0325 {
0326     struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
0327 
0328     state->bits |= MPPE_BIT_FLUSHED;
0329 }
0330 
0331 /*
0332  * Compress (encrypt) a packet.
0333  * It's strange to call this a compressor, since the output is always
0334  * MPPE_OVHD + 2 bytes larger than the input.
0335  */
0336 static int
0337 mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
0338           int isize, int osize)
0339 {
0340     struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
0341     int proto;
0342 
0343     /*
0344      * Check that the protocol is in the range we handle.
0345      */
0346     proto = PPP_PROTOCOL(ibuf);
0347     if (proto < 0x0021 || proto > 0x00fa)
0348         return 0;
0349 
0350     /* Make sure we have enough room to generate an encrypted packet. */
0351     if (osize < isize + MPPE_OVHD + 2) {
0352         /* Drop the packet if we should encrypt it, but can't. */
0353         printk(KERN_DEBUG "mppe_compress[%d]: osize too small! "
0354                "(have: %d need: %d)\n", state->unit,
0355                osize, osize + MPPE_OVHD + 2);
0356         return -1;
0357     }
0358 
0359     osize = isize + MPPE_OVHD + 2;
0360 
0361     /*
0362      * Copy over the PPP header and set control bits.
0363      */
0364     obuf[0] = PPP_ADDRESS(ibuf);
0365     obuf[1] = PPP_CONTROL(ibuf);
0366     put_unaligned_be16(PPP_COMP, obuf + 2);
0367     obuf += PPP_HDRLEN;
0368 
0369     state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
0370     if (state->debug >= 7)
0371         printk(KERN_DEBUG "mppe_compress[%d]: ccount %d\n", state->unit,
0372                state->ccount);
0373     put_unaligned_be16(state->ccount, obuf);
0374 
0375     if (!state->stateful || /* stateless mode     */
0376         ((state->ccount & 0xff) == 0xff) || /* "flag" packet      */
0377         (state->bits & MPPE_BIT_FLUSHED)) { /* CCP Reset-Request  */
0378         /* We must rekey */
0379         if (state->debug && state->stateful)
0380             printk(KERN_DEBUG "mppe_compress[%d]: rekeying\n",
0381                    state->unit);
0382         mppe_rekey(state, 0);
0383         state->bits |= MPPE_BIT_FLUSHED;
0384     }
0385     obuf[0] |= state->bits;
0386     state->bits &= ~MPPE_BIT_FLUSHED;   /* reset for next xmit */
0387 
0388     obuf += MPPE_OVHD;
0389     ibuf += 2;      /* skip to proto field */
0390     isize -= 2;
0391 
0392     arc4_crypt(&state->arc4, obuf, ibuf, isize);
0393 
0394     state->stats.unc_bytes += isize;
0395     state->stats.unc_packets++;
0396     state->stats.comp_bytes += osize;
0397     state->stats.comp_packets++;
0398 
0399     return osize;
0400 }
0401 
0402 /*
0403  * Since every frame grows by MPPE_OVHD + 2 bytes, this is always going
0404  * to look bad ... and the longer the link is up the worse it will get.
0405  */
0406 static void mppe_comp_stats(void *arg, struct compstat *stats)
0407 {
0408     struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
0409 
0410     *stats = state->stats;
0411 }
0412 
0413 static int
0414 mppe_decomp_init(void *arg, unsigned char *options, int optlen, int unit,
0415          int hdrlen, int mru, int debug)
0416 {
0417     /* ARGSUSED */
0418     return mppe_init(arg, options, optlen, unit, debug, "mppe_decomp_init");
0419 }
0420 
0421 /*
0422  * We received a CCP Reset-Ack.  Just ignore it.
0423  */
0424 static void mppe_decomp_reset(void *arg)
0425 {
0426     /* ARGSUSED */
0427     return;
0428 }
0429 
0430 /*
0431  * Decompress (decrypt) an MPPE packet.
0432  */
0433 static int
0434 mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
0435         int osize)
0436 {
0437     struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
0438     unsigned ccount;
0439     int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED;
0440 
0441     if (isize <= PPP_HDRLEN + MPPE_OVHD) {
0442         if (state->debug)
0443             printk(KERN_DEBUG
0444                    "mppe_decompress[%d]: short pkt (%d)\n",
0445                    state->unit, isize);
0446         return DECOMP_ERROR;
0447     }
0448 
0449     /*
0450      * Make sure we have enough room to decrypt the packet.
0451      * Note that for our test we only subtract 1 byte whereas in
0452      * mppe_compress() we added 2 bytes (+MPPE_OVHD);
0453      * this is to account for possible PFC.
0454      */
0455     if (osize < isize - MPPE_OVHD - 1) {
0456         printk(KERN_DEBUG "mppe_decompress[%d]: osize too small! "
0457                "(have: %d need: %d)\n", state->unit,
0458                osize, isize - MPPE_OVHD - 1);
0459         return DECOMP_ERROR;
0460     }
0461     osize = isize - MPPE_OVHD - 2;  /* assume no PFC */
0462 
0463     ccount = MPPE_CCOUNT(ibuf);
0464     if (state->debug >= 7)
0465         printk(KERN_DEBUG "mppe_decompress[%d]: ccount %d\n",
0466                state->unit, ccount);
0467 
0468     /* sanity checks -- terminate with extreme prejudice */
0469     if (!(MPPE_BITS(ibuf) & MPPE_BIT_ENCRYPTED)) {
0470         printk(KERN_DEBUG
0471                "mppe_decompress[%d]: ENCRYPTED bit not set!\n",
0472                state->unit);
0473         state->sanity_errors += 100;
0474         goto sanity_error;
0475     }
0476     if (!state->stateful && !flushed) {
0477         printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set in "
0478                "stateless mode!\n", state->unit);
0479         state->sanity_errors += 100;
0480         goto sanity_error;
0481     }
0482     if (state->stateful && ((ccount & 0xff) == 0xff) && !flushed) {
0483         printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set on "
0484                "flag packet!\n", state->unit);
0485         state->sanity_errors += 100;
0486         goto sanity_error;
0487     }
0488 
0489     /*
0490      * Check the coherency count.
0491      */
0492 
0493     if (!state->stateful) {
0494         /* Discard late packet */
0495         if ((ccount - state->ccount) % MPPE_CCOUNT_SPACE
0496                         > MPPE_CCOUNT_SPACE / 2) {
0497             state->sanity_errors++;
0498             goto sanity_error;
0499         }
0500 
0501         /* RFC 3078, sec 8.1.  Rekey for every packet. */
0502         while (state->ccount != ccount) {
0503             mppe_rekey(state, 0);
0504             state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
0505         }
0506     } else {
0507         /* RFC 3078, sec 8.2. */
0508         if (!state->discard) {
0509             /* normal state */
0510             state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
0511             if (ccount != state->ccount) {
0512                 /*
0513                  * (ccount > state->ccount)
0514                  * Packet loss detected, enter the discard state.
0515                  * Signal the peer to rekey (by sending a CCP Reset-Request).
0516                  */
0517                 state->discard = 1;
0518                 return DECOMP_ERROR;
0519             }
0520         } else {
0521             /* discard state */
0522             if (!flushed) {
0523                 /* ccp.c will be silent (no additional CCP Reset-Requests). */
0524                 return DECOMP_ERROR;
0525             } else {
0526                 /* Rekey for every missed "flag" packet. */
0527                 while ((ccount & ~0xff) !=
0528                        (state->ccount & ~0xff)) {
0529                     mppe_rekey(state, 0);
0530                     state->ccount =
0531                         (state->ccount +
0532                          256) % MPPE_CCOUNT_SPACE;
0533                 }
0534 
0535                 /* reset */
0536                 state->discard = 0;
0537                 state->ccount = ccount;
0538                 /*
0539                  * Another problem with RFC 3078 here.  It implies that the
0540                  * peer need not send a Reset-Ack packet.  But RFC 1962
0541                  * requires it.  Hopefully, M$ does send a Reset-Ack; even
0542                  * though it isn't required for MPPE synchronization, it is
0543                  * required to reset CCP state.
0544                  */
0545             }
0546         }
0547         if (flushed)
0548             mppe_rekey(state, 0);
0549     }
0550 
0551     /*
0552      * Fill in the first part of the PPP header.  The protocol field
0553      * comes from the decrypted data.
0554      */
0555     obuf[0] = PPP_ADDRESS(ibuf);    /* +1 */
0556     obuf[1] = PPP_CONTROL(ibuf);    /* +1 */
0557     obuf += 2;
0558     ibuf += PPP_HDRLEN + MPPE_OVHD;
0559     isize -= PPP_HDRLEN + MPPE_OVHD;    /* -6 */
0560     /* net osize: isize-4 */
0561 
0562     /*
0563      * Decrypt the first byte in order to check if it is
0564      * a compressed or uncompressed protocol field.
0565      */
0566     arc4_crypt(&state->arc4, obuf, ibuf, 1);
0567 
0568     /*
0569      * Do PFC decompression.
0570      * This would be nicer if we were given the actual sk_buff
0571      * instead of a char *.
0572      */
0573     if ((obuf[0] & 0x01) != 0) {
0574         obuf[1] = obuf[0];
0575         obuf[0] = 0;
0576         obuf++;
0577         osize++;
0578     }
0579 
0580     /* And finally, decrypt the rest of the packet. */
0581     arc4_crypt(&state->arc4, obuf + 1, ibuf + 1, isize - 1);
0582 
0583     state->stats.unc_bytes += osize;
0584     state->stats.unc_packets++;
0585     state->stats.comp_bytes += isize;
0586     state->stats.comp_packets++;
0587 
0588     /* good packet credit */
0589     state->sanity_errors >>= 1;
0590 
0591     return osize;
0592 
0593 sanity_error:
0594     if (state->sanity_errors < SANITY_MAX)
0595         return DECOMP_ERROR;
0596     else
0597         /* Take LCP down if the peer is sending too many bogons.
0598          * We don't want to do this for a single or just a few
0599          * instances since it could just be due to packet corruption.
0600          */
0601         return DECOMP_FATALERROR;
0602 }
0603 
0604 /*
0605  * Incompressible data has arrived (this should never happen!).
0606  * We should probably drop the link if the protocol is in the range
0607  * of what should be encrypted.  At the least, we should drop this
0608  * packet.  (How to do this?)
0609  */
0610 static void mppe_incomp(void *arg, unsigned char *ibuf, int icnt)
0611 {
0612     struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
0613 
0614     if (state->debug &&
0615         (PPP_PROTOCOL(ibuf) >= 0x0021 && PPP_PROTOCOL(ibuf) <= 0x00fa))
0616         printk(KERN_DEBUG
0617                "mppe_incomp[%d]: incompressible (unencrypted) data! "
0618                "(proto %04x)\n", state->unit, PPP_PROTOCOL(ibuf));
0619 
0620     state->stats.inc_bytes += icnt;
0621     state->stats.inc_packets++;
0622     state->stats.unc_bytes += icnt;
0623     state->stats.unc_packets++;
0624 }
0625 
0626 /*************************************************************
0627  * Module interface table
0628  *************************************************************/
0629 
0630 /*
0631  * Procedures exported to if_ppp.c.
0632  */
0633 static struct compressor ppp_mppe = {
0634     .compress_proto = CI_MPPE,
0635     .comp_alloc     = mppe_alloc,
0636     .comp_free      = mppe_free,
0637     .comp_init      = mppe_comp_init,
0638     .comp_reset     = mppe_comp_reset,
0639     .compress       = mppe_compress,
0640     .comp_stat      = mppe_comp_stats,
0641     .decomp_alloc   = mppe_alloc,
0642     .decomp_free    = mppe_free,
0643     .decomp_init    = mppe_decomp_init,
0644     .decomp_reset   = mppe_decomp_reset,
0645     .decompress     = mppe_decompress,
0646     .incomp         = mppe_incomp,
0647     .decomp_stat    = mppe_comp_stats,
0648     .owner          = THIS_MODULE,
0649     .comp_extra     = MPPE_PAD,
0650 };
0651 
0652 /*
0653  * ppp_mppe_init()
0654  *
0655  * Prior to allowing load, try to load the arc4 and sha1 crypto
0656  * libraries.  The actual use will be allocated later, but
0657  * this way the module will fail to insmod if they aren't available.
0658  */
0659 
0660 static int __init ppp_mppe_init(void)
0661 {
0662     int answer;
0663     if (fips_enabled || !crypto_has_ahash("sha1", 0, CRYPTO_ALG_ASYNC))
0664         return -ENODEV;
0665 
0666     sha_pad = kmalloc(sizeof(struct sha_pad), GFP_KERNEL);
0667     if (!sha_pad)
0668         return -ENOMEM;
0669     sha_pad_init(sha_pad);
0670 
0671     answer = ppp_register_compressor(&ppp_mppe);
0672 
0673     if (answer == 0)
0674         printk(KERN_INFO "PPP MPPE Compression module registered\n");
0675     else
0676         kfree(sha_pad);
0677 
0678     return answer;
0679 }
0680 
0681 static void __exit ppp_mppe_cleanup(void)
0682 {
0683     ppp_unregister_compressor(&ppp_mppe);
0684     kfree(sha_pad);
0685 }
0686 
0687 module_init(ppp_mppe_init);
0688 module_exit(ppp_mppe_cleanup);