xref: /openbmc/linux/drivers/net/ppp/ppp_mppe.c (revision 2f5947df)
1 /*
2  * ppp_mppe.c - interface MPPE to the PPP code.
3  * This version is for use with Linux kernel 2.6.14+
4  *
5  * By Frank Cusack <fcusack@fcusack.com>.
6  * Copyright (c) 2002,2003,2004 Google, Inc.
7  * All rights reserved.
8  *
9  * License:
10  * Permission to use, copy, modify, and distribute this software and its
11  * documentation is hereby granted, provided that the above copyright
12  * notice appears in all copies.  This software is provided without any
13  * warranty, express or implied.
14  *
15  * ALTERNATIVELY, provided that this notice is retained in full, this product
16  * may be distributed under the terms of the GNU General Public License (GPL),
17  * in which case the provisions of the GPL apply INSTEAD OF those given above.
18  *
19  *   This program is free software; you can redistribute it and/or modify
20  *   it under the terms of the GNU General Public License as published by
21  *   the Free Software Foundation; either version 2 of the License, or
22  *   (at your option) any later version.
23  *
24  *   This program is distributed in the hope that it will be useful,
25  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
26  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  *   GNU General Public License for more details.
28  *
29  *   You should have received a copy of the GNU General Public License
30  *   along with this program; if not, see <http://www.gnu.org/licenses/>.
31  *
32  *
33  * Changelog:
34  *      08/12/05 - Matt Domsch <Matt_Domsch@dell.com>
35  *                 Only need extra skb padding on transmit, not receive.
36  *      06/18/04 - Matt Domsch <Matt_Domsch@dell.com>, Oleg Makarenko <mole@quadra.ru>
37  *                 Use Linux kernel 2.6 arc4 and sha1 routines rather than
38  *                 providing our own.
39  *      2/15/04 - TS: added #include <version.h> and testing for Kernel
40  *                    version before using
41  *                    MOD_DEC_USAGE_COUNT/MOD_INC_USAGE_COUNT which are
42  *                    deprecated in 2.6
43  */
44 
45 #include <crypto/arc4.h>
46 #include <crypto/hash.h>
47 #include <linux/err.h>
48 #include <linux/fips.h>
49 #include <linux/module.h>
50 #include <linux/kernel.h>
51 #include <linux/init.h>
52 #include <linux/types.h>
53 #include <linux/slab.h>
54 #include <linux/string.h>
55 #include <linux/mm.h>
56 #include <linux/ppp_defs.h>
57 #include <linux/ppp-comp.h>
58 #include <linux/scatterlist.h>
59 #include <asm/unaligned.h>
60 
61 #include "ppp_mppe.h"
62 
63 MODULE_AUTHOR("Frank Cusack <fcusack@fcusack.com>");
64 MODULE_DESCRIPTION("Point-to-Point Protocol Microsoft Point-to-Point Encryption support");
65 MODULE_LICENSE("Dual BSD/GPL");
66 MODULE_ALIAS("ppp-compress-" __stringify(CI_MPPE));
67 MODULE_SOFTDEP("pre: arc4");
68 MODULE_VERSION("1.0.2");
69 
70 #define SHA1_PAD_SIZE 40
71 
72 /*
73  * kernel crypto API needs its arguments to be in kmalloc'd memory, not in the module
74  * static data area.  That means sha_pad needs to be kmalloc'd.
75  */
76 
77 struct sha_pad {
78 	unsigned char sha_pad1[SHA1_PAD_SIZE];
79 	unsigned char sha_pad2[SHA1_PAD_SIZE];
80 };
81 static struct sha_pad *sha_pad;
82 
83 static inline void sha_pad_init(struct sha_pad *shapad)
84 {
85 	memset(shapad->sha_pad1, 0x00, sizeof(shapad->sha_pad1));
86 	memset(shapad->sha_pad2, 0xF2, sizeof(shapad->sha_pad2));
87 }
88 
89 /*
90  * State for an MPPE (de)compressor.
91  */
92 struct ppp_mppe_state {
93 	struct arc4_ctx arc4;
94 	struct shash_desc *sha1;
95 	unsigned char *sha1_digest;
96 	unsigned char master_key[MPPE_MAX_KEY_LEN];
97 	unsigned char session_key[MPPE_MAX_KEY_LEN];
98 	unsigned keylen;	/* key length in bytes             */
99 	/* NB: 128-bit == 16, 40-bit == 8! */
100 	/* If we want to support 56-bit,   */
101 	/* the unit has to change to bits  */
102 	unsigned char bits;	/* MPPE control bits */
103 	unsigned ccount;	/* 12-bit coherency count (seqno)  */
104 	unsigned stateful;	/* stateful mode flag */
105 	int discard;		/* stateful mode packet loss flag */
106 	int sanity_errors;	/* take down LCP if too many */
107 	int unit;
108 	int debug;
109 	struct compstat stats;
110 };
111 
112 /* struct ppp_mppe_state.bits definitions */
113 #define MPPE_BIT_A	0x80	/* Encryption table were (re)inititalized */
114 #define MPPE_BIT_B	0x40	/* MPPC only (not implemented) */
115 #define MPPE_BIT_C	0x20	/* MPPC only (not implemented) */
116 #define MPPE_BIT_D	0x10	/* This is an encrypted frame */
117 
118 #define MPPE_BIT_FLUSHED	MPPE_BIT_A
119 #define MPPE_BIT_ENCRYPTED	MPPE_BIT_D
120 
121 #define MPPE_BITS(p) ((p)[4] & 0xf0)
122 #define MPPE_CCOUNT(p) ((((p)[4] & 0x0f) << 8) + (p)[5])
123 #define MPPE_CCOUNT_SPACE 0x1000	/* The size of the ccount space */
124 
125 #define MPPE_OVHD	2	/* MPPE overhead/packet */
126 #define SANITY_MAX	1600	/* Max bogon factor we will tolerate */
127 
128 /*
129  * Key Derivation, from RFC 3078, RFC 3079.
130  * Equivalent to Get_Key() for MS-CHAP as described in RFC 3079.
131  */
132 static void get_new_key_from_sha(struct ppp_mppe_state * state)
133 {
134 	crypto_shash_init(state->sha1);
135 	crypto_shash_update(state->sha1, state->master_key,
136 			    state->keylen);
137 	crypto_shash_update(state->sha1, sha_pad->sha_pad1,
138 			    sizeof(sha_pad->sha_pad1));
139 	crypto_shash_update(state->sha1, state->session_key,
140 			    state->keylen);
141 	crypto_shash_update(state->sha1, sha_pad->sha_pad2,
142 			    sizeof(sha_pad->sha_pad2));
143 	crypto_shash_final(state->sha1, state->sha1_digest);
144 }
145 
146 /*
147  * Perform the MPPE rekey algorithm, from RFC 3078, sec. 7.3.
148  * Well, not what's written there, but rather what they meant.
149  */
150 static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
151 {
152 	get_new_key_from_sha(state);
153 	if (!initial_key) {
154 		arc4_setkey(&state->arc4, state->sha1_digest, state->keylen);
155 		arc4_crypt(&state->arc4, state->session_key, state->sha1_digest,
156 			   state->keylen);
157 	} else {
158 		memcpy(state->session_key, state->sha1_digest, state->keylen);
159 	}
160 	if (state->keylen == 8) {
161 		/* See RFC 3078 */
162 		state->session_key[0] = 0xd1;
163 		state->session_key[1] = 0x26;
164 		state->session_key[2] = 0x9e;
165 	}
166 	arc4_setkey(&state->arc4, state->session_key, state->keylen);
167 }
168 
169 /*
170  * Allocate space for a (de)compressor.
171  */
172 static void *mppe_alloc(unsigned char *options, int optlen)
173 {
174 	struct ppp_mppe_state *state;
175 	struct crypto_shash *shash;
176 	unsigned int digestsize;
177 
178 	if (optlen != CILEN_MPPE + sizeof(state->master_key) ||
179 	    options[0] != CI_MPPE || options[1] != CILEN_MPPE ||
180 	    fips_enabled)
181 		goto out;
182 
183 	state = kzalloc(sizeof(*state), GFP_KERNEL);
184 	if (state == NULL)
185 		goto out;
186 
187 
188 	shash = crypto_alloc_shash("sha1", 0, 0);
189 	if (IS_ERR(shash))
190 		goto out_free;
191 
192 	state->sha1 = kmalloc(sizeof(*state->sha1) +
193 				     crypto_shash_descsize(shash),
194 			      GFP_KERNEL);
195 	if (!state->sha1) {
196 		crypto_free_shash(shash);
197 		goto out_free;
198 	}
199 	state->sha1->tfm = shash;
200 
201 	digestsize = crypto_shash_digestsize(shash);
202 	if (digestsize < MPPE_MAX_KEY_LEN)
203 		goto out_free;
204 
205 	state->sha1_digest = kmalloc(digestsize, GFP_KERNEL);
206 	if (!state->sha1_digest)
207 		goto out_free;
208 
209 	/* Save keys. */
210 	memcpy(state->master_key, &options[CILEN_MPPE],
211 	       sizeof(state->master_key));
212 	memcpy(state->session_key, state->master_key,
213 	       sizeof(state->master_key));
214 
215 	/*
216 	 * We defer initial key generation until mppe_init(), as mppe_alloc()
217 	 * is called frequently during negotiation.
218 	 */
219 
220 	return (void *)state;
221 
222 out_free:
223 	kfree(state->sha1_digest);
224 	if (state->sha1) {
225 		crypto_free_shash(state->sha1->tfm);
226 		kzfree(state->sha1);
227 	}
228 	kfree(state);
229 out:
230 	return NULL;
231 }
232 
233 /*
234  * Deallocate space for a (de)compressor.
235  */
236 static void mppe_free(void *arg)
237 {
238 	struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
239 	if (state) {
240 		kfree(state->sha1_digest);
241 		crypto_free_shash(state->sha1->tfm);
242 		kzfree(state->sha1);
243 		kzfree(state);
244 	}
245 }
246 
247 /*
248  * Initialize (de)compressor state.
249  */
250 static int
251 mppe_init(void *arg, unsigned char *options, int optlen, int unit, int debug,
252 	  const char *debugstr)
253 {
254 	struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
255 	unsigned char mppe_opts;
256 
257 	if (optlen != CILEN_MPPE ||
258 	    options[0] != CI_MPPE || options[1] != CILEN_MPPE)
259 		return 0;
260 
261 	MPPE_CI_TO_OPTS(&options[2], mppe_opts);
262 	if (mppe_opts & MPPE_OPT_128)
263 		state->keylen = 16;
264 	else if (mppe_opts & MPPE_OPT_40)
265 		state->keylen = 8;
266 	else {
267 		printk(KERN_WARNING "%s[%d]: unknown key length\n", debugstr,
268 		       unit);
269 		return 0;
270 	}
271 	if (mppe_opts & MPPE_OPT_STATEFUL)
272 		state->stateful = 1;
273 
274 	/* Generate the initial session key. */
275 	mppe_rekey(state, 1);
276 
277 	if (debug) {
278 		printk(KERN_DEBUG "%s[%d]: initialized with %d-bit %s mode\n",
279 		       debugstr, unit, (state->keylen == 16) ? 128 : 40,
280 		       (state->stateful) ? "stateful" : "stateless");
281 		printk(KERN_DEBUG
282 		       "%s[%d]: keys: master: %*phN initial session: %*phN\n",
283 		       debugstr, unit,
284 		       (int)sizeof(state->master_key), state->master_key,
285 		       (int)sizeof(state->session_key), state->session_key);
286 	}
287 
288 	/*
289 	 * Initialize the coherency count.  The initial value is not specified
290 	 * in RFC 3078, but we can make a reasonable assumption that it will
291 	 * start at 0.  Setting it to the max here makes the comp/decomp code
292 	 * do the right thing (determined through experiment).
293 	 */
294 	state->ccount = MPPE_CCOUNT_SPACE - 1;
295 
296 	/*
297 	 * Note that even though we have initialized the key table, we don't
298 	 * set the FLUSHED bit.  This is contrary to RFC 3078, sec. 3.1.
299 	 */
300 	state->bits = MPPE_BIT_ENCRYPTED;
301 
302 	state->unit = unit;
303 	state->debug = debug;
304 
305 	return 1;
306 }
307 
308 static int
309 mppe_comp_init(void *arg, unsigned char *options, int optlen, int unit,
310 	       int hdrlen, int debug)
311 {
312 	/* ARGSUSED */
313 	return mppe_init(arg, options, optlen, unit, debug, "mppe_comp_init");
314 }
315 
316 /*
317  * We received a CCP Reset-Request (actually, we are sending a Reset-Ack),
318  * tell the compressor to rekey.  Note that we MUST NOT rekey for
319  * every CCP Reset-Request; we only rekey on the next xmit packet.
320  * We might get multiple CCP Reset-Requests if our CCP Reset-Ack is lost.
321  * So, rekeying for every CCP Reset-Request is broken as the peer will not
322  * know how many times we've rekeyed.  (If we rekey and THEN get another
323  * CCP Reset-Request, we must rekey again.)
324  */
325 static void mppe_comp_reset(void *arg)
326 {
327 	struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
328 
329 	state->bits |= MPPE_BIT_FLUSHED;
330 }
331 
332 /*
333  * Compress (encrypt) a packet.
334  * It's strange to call this a compressor, since the output is always
335  * MPPE_OVHD + 2 bytes larger than the input.
336  */
337 static int
338 mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
339 	      int isize, int osize)
340 {
341 	struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
342 	int proto;
343 
344 	/*
345 	 * Check that the protocol is in the range we handle.
346 	 */
347 	proto = PPP_PROTOCOL(ibuf);
348 	if (proto < 0x0021 || proto > 0x00fa)
349 		return 0;
350 
351 	/* Make sure we have enough room to generate an encrypted packet. */
352 	if (osize < isize + MPPE_OVHD + 2) {
353 		/* Drop the packet if we should encrypt it, but can't. */
354 		printk(KERN_DEBUG "mppe_compress[%d]: osize too small! "
355 		       "(have: %d need: %d)\n", state->unit,
356 		       osize, osize + MPPE_OVHD + 2);
357 		return -1;
358 	}
359 
360 	osize = isize + MPPE_OVHD + 2;
361 
362 	/*
363 	 * Copy over the PPP header and set control bits.
364 	 */
365 	obuf[0] = PPP_ADDRESS(ibuf);
366 	obuf[1] = PPP_CONTROL(ibuf);
367 	put_unaligned_be16(PPP_COMP, obuf + 2);
368 	obuf += PPP_HDRLEN;
369 
370 	state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
371 	if (state->debug >= 7)
372 		printk(KERN_DEBUG "mppe_compress[%d]: ccount %d\n", state->unit,
373 		       state->ccount);
374 	put_unaligned_be16(state->ccount, obuf);
375 
376 	if (!state->stateful ||	/* stateless mode     */
377 	    ((state->ccount & 0xff) == 0xff) ||	/* "flag" packet      */
378 	    (state->bits & MPPE_BIT_FLUSHED)) {	/* CCP Reset-Request  */
379 		/* We must rekey */
380 		if (state->debug && state->stateful)
381 			printk(KERN_DEBUG "mppe_compress[%d]: rekeying\n",
382 			       state->unit);
383 		mppe_rekey(state, 0);
384 		state->bits |= MPPE_BIT_FLUSHED;
385 	}
386 	obuf[0] |= state->bits;
387 	state->bits &= ~MPPE_BIT_FLUSHED;	/* reset for next xmit */
388 
389 	obuf += MPPE_OVHD;
390 	ibuf += 2;		/* skip to proto field */
391 	isize -= 2;
392 
393 	arc4_crypt(&state->arc4, obuf, ibuf, isize);
394 
395 	state->stats.unc_bytes += isize;
396 	state->stats.unc_packets++;
397 	state->stats.comp_bytes += osize;
398 	state->stats.comp_packets++;
399 
400 	return osize;
401 }
402 
403 /*
404  * Since every frame grows by MPPE_OVHD + 2 bytes, this is always going
405  * to look bad ... and the longer the link is up the worse it will get.
406  */
407 static void mppe_comp_stats(void *arg, struct compstat *stats)
408 {
409 	struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
410 
411 	*stats = state->stats;
412 }
413 
414 static int
415 mppe_decomp_init(void *arg, unsigned char *options, int optlen, int unit,
416 		 int hdrlen, int mru, int debug)
417 {
418 	/* ARGSUSED */
419 	return mppe_init(arg, options, optlen, unit, debug, "mppe_decomp_init");
420 }
421 
422 /*
423  * We received a CCP Reset-Ack.  Just ignore it.
424  */
425 static void mppe_decomp_reset(void *arg)
426 {
427 	/* ARGSUSED */
428 	return;
429 }
430 
431 /*
432  * Decompress (decrypt) an MPPE packet.
433  */
434 static int
435 mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
436 		int osize)
437 {
438 	struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
439 	unsigned ccount;
440 	int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED;
441 
442 	if (isize <= PPP_HDRLEN + MPPE_OVHD) {
443 		if (state->debug)
444 			printk(KERN_DEBUG
445 			       "mppe_decompress[%d]: short pkt (%d)\n",
446 			       state->unit, isize);
447 		return DECOMP_ERROR;
448 	}
449 
450 	/*
451 	 * Make sure we have enough room to decrypt the packet.
452 	 * Note that for our test we only subtract 1 byte whereas in
453 	 * mppe_compress() we added 2 bytes (+MPPE_OVHD);
454 	 * this is to account for possible PFC.
455 	 */
456 	if (osize < isize - MPPE_OVHD - 1) {
457 		printk(KERN_DEBUG "mppe_decompress[%d]: osize too small! "
458 		       "(have: %d need: %d)\n", state->unit,
459 		       osize, isize - MPPE_OVHD - 1);
460 		return DECOMP_ERROR;
461 	}
462 	osize = isize - MPPE_OVHD - 2;	/* assume no PFC */
463 
464 	ccount = MPPE_CCOUNT(ibuf);
465 	if (state->debug >= 7)
466 		printk(KERN_DEBUG "mppe_decompress[%d]: ccount %d\n",
467 		       state->unit, ccount);
468 
469 	/* sanity checks -- terminate with extreme prejudice */
470 	if (!(MPPE_BITS(ibuf) & MPPE_BIT_ENCRYPTED)) {
471 		printk(KERN_DEBUG
472 		       "mppe_decompress[%d]: ENCRYPTED bit not set!\n",
473 		       state->unit);
474 		state->sanity_errors += 100;
475 		goto sanity_error;
476 	}
477 	if (!state->stateful && !flushed) {
478 		printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set in "
479 		       "stateless mode!\n", state->unit);
480 		state->sanity_errors += 100;
481 		goto sanity_error;
482 	}
483 	if (state->stateful && ((ccount & 0xff) == 0xff) && !flushed) {
484 		printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set on "
485 		       "flag packet!\n", state->unit);
486 		state->sanity_errors += 100;
487 		goto sanity_error;
488 	}
489 
490 	/*
491 	 * Check the coherency count.
492 	 */
493 
494 	if (!state->stateful) {
495 		/* Discard late packet */
496 		if ((ccount - state->ccount) % MPPE_CCOUNT_SPACE
497 						> MPPE_CCOUNT_SPACE / 2) {
498 			state->sanity_errors++;
499 			goto sanity_error;
500 		}
501 
502 		/* RFC 3078, sec 8.1.  Rekey for every packet. */
503 		while (state->ccount != ccount) {
504 			mppe_rekey(state, 0);
505 			state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
506 		}
507 	} else {
508 		/* RFC 3078, sec 8.2. */
509 		if (!state->discard) {
510 			/* normal state */
511 			state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
512 			if (ccount != state->ccount) {
513 				/*
514 				 * (ccount > state->ccount)
515 				 * Packet loss detected, enter the discard state.
516 				 * Signal the peer to rekey (by sending a CCP Reset-Request).
517 				 */
518 				state->discard = 1;
519 				return DECOMP_ERROR;
520 			}
521 		} else {
522 			/* discard state */
523 			if (!flushed) {
524 				/* ccp.c will be silent (no additional CCP Reset-Requests). */
525 				return DECOMP_ERROR;
526 			} else {
527 				/* Rekey for every missed "flag" packet. */
528 				while ((ccount & ~0xff) !=
529 				       (state->ccount & ~0xff)) {
530 					mppe_rekey(state, 0);
531 					state->ccount =
532 					    (state->ccount +
533 					     256) % MPPE_CCOUNT_SPACE;
534 				}
535 
536 				/* reset */
537 				state->discard = 0;
538 				state->ccount = ccount;
539 				/*
540 				 * Another problem with RFC 3078 here.  It implies that the
541 				 * peer need not send a Reset-Ack packet.  But RFC 1962
542 				 * requires it.  Hopefully, M$ does send a Reset-Ack; even
543 				 * though it isn't required for MPPE synchronization, it is
544 				 * required to reset CCP state.
545 				 */
546 			}
547 		}
548 		if (flushed)
549 			mppe_rekey(state, 0);
550 	}
551 
552 	/*
553 	 * Fill in the first part of the PPP header.  The protocol field
554 	 * comes from the decrypted data.
555 	 */
556 	obuf[0] = PPP_ADDRESS(ibuf);	/* +1 */
557 	obuf[1] = PPP_CONTROL(ibuf);	/* +1 */
558 	obuf += 2;
559 	ibuf += PPP_HDRLEN + MPPE_OVHD;
560 	isize -= PPP_HDRLEN + MPPE_OVHD;	/* -6 */
561 	/* net osize: isize-4 */
562 
563 	/*
564 	 * Decrypt the first byte in order to check if it is
565 	 * a compressed or uncompressed protocol field.
566 	 */
567 	arc4_crypt(&state->arc4, obuf, ibuf, 1);
568 
569 	/*
570 	 * Do PFC decompression.
571 	 * This would be nicer if we were given the actual sk_buff
572 	 * instead of a char *.
573 	 */
574 	if ((obuf[0] & 0x01) != 0) {
575 		obuf[1] = obuf[0];
576 		obuf[0] = 0;
577 		obuf++;
578 		osize++;
579 	}
580 
581 	/* And finally, decrypt the rest of the packet. */
582 	arc4_crypt(&state->arc4, obuf + 1, ibuf + 1, isize - 1);
583 
584 	state->stats.unc_bytes += osize;
585 	state->stats.unc_packets++;
586 	state->stats.comp_bytes += isize;
587 	state->stats.comp_packets++;
588 
589 	/* good packet credit */
590 	state->sanity_errors >>= 1;
591 
592 	return osize;
593 
594 sanity_error:
595 	if (state->sanity_errors < SANITY_MAX)
596 		return DECOMP_ERROR;
597 	else
598 		/* Take LCP down if the peer is sending too many bogons.
599 		 * We don't want to do this for a single or just a few
600 		 * instances since it could just be due to packet corruption.
601 		 */
602 		return DECOMP_FATALERROR;
603 }
604 
605 /*
606  * Incompressible data has arrived (this should never happen!).
607  * We should probably drop the link if the protocol is in the range
608  * of what should be encrypted.  At the least, we should drop this
609  * packet.  (How to do this?)
610  */
611 static void mppe_incomp(void *arg, unsigned char *ibuf, int icnt)
612 {
613 	struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
614 
615 	if (state->debug &&
616 	    (PPP_PROTOCOL(ibuf) >= 0x0021 && PPP_PROTOCOL(ibuf) <= 0x00fa))
617 		printk(KERN_DEBUG
618 		       "mppe_incomp[%d]: incompressible (unencrypted) data! "
619 		       "(proto %04x)\n", state->unit, PPP_PROTOCOL(ibuf));
620 
621 	state->stats.inc_bytes += icnt;
622 	state->stats.inc_packets++;
623 	state->stats.unc_bytes += icnt;
624 	state->stats.unc_packets++;
625 }
626 
627 /*************************************************************
628  * Module interface table
629  *************************************************************/
630 
631 /*
632  * Procedures exported to if_ppp.c.
633  */
634 static struct compressor ppp_mppe = {
635 	.compress_proto = CI_MPPE,
636 	.comp_alloc     = mppe_alloc,
637 	.comp_free      = mppe_free,
638 	.comp_init      = mppe_comp_init,
639 	.comp_reset     = mppe_comp_reset,
640 	.compress       = mppe_compress,
641 	.comp_stat      = mppe_comp_stats,
642 	.decomp_alloc   = mppe_alloc,
643 	.decomp_free    = mppe_free,
644 	.decomp_init    = mppe_decomp_init,
645 	.decomp_reset   = mppe_decomp_reset,
646 	.decompress     = mppe_decompress,
647 	.incomp         = mppe_incomp,
648 	.decomp_stat    = mppe_comp_stats,
649 	.owner          = THIS_MODULE,
650 	.comp_extra     = MPPE_PAD,
651 };
652 
653 /*
654  * ppp_mppe_init()
655  *
656  * Prior to allowing load, try to load the arc4 and sha1 crypto
657  * libraries.  The actual use will be allocated later, but
658  * this way the module will fail to insmod if they aren't available.
659  */
660 
661 static int __init ppp_mppe_init(void)
662 {
663 	int answer;
664 	if (fips_enabled || !crypto_has_ahash("sha1", 0, CRYPTO_ALG_ASYNC))
665 		return -ENODEV;
666 
667 	sha_pad = kmalloc(sizeof(struct sha_pad), GFP_KERNEL);
668 	if (!sha_pad)
669 		return -ENOMEM;
670 	sha_pad_init(sha_pad);
671 
672 	answer = ppp_register_compressor(&ppp_mppe);
673 
674 	if (answer == 0)
675 		printk(KERN_INFO "PPP MPPE Compression module registered\n");
676 	else
677 		kfree(sha_pad);
678 
679 	return answer;
680 }
681 
682 static void __exit ppp_mppe_cleanup(void)
683 {
684 	ppp_unregister_compressor(&ppp_mppe);
685 	kfree(sha_pad);
686 }
687 
688 module_init(ppp_mppe_init);
689 module_exit(ppp_mppe_cleanup);
690