linux-omap 2.6.37: replace various patch with upstream versions and rediff
[openembedded.git] / recipes / linux / linux-mtx-1-2.4.27 / 39-mppe-mpc.patch
blob28ce19d46761a7c06a6b05ed950efbef479374e5
1 diff -ruN linux.orig/Documentation/Configure.help linux/Documentation/Configure.help
2 --- linux.orig/Documentation/Configure.help 2004-08-08 12:14:49.000000000 +0200
3 +++ linux/Documentation/Configure.help 2004-08-15 09:22:18.000000000 +0200
4 @@ -9905,6 +9905,28 @@
5 module; it is called bsd_comp.o and will show up in the directory
6 modules once you have said "make modules". If unsure, say N.
8 +Microsoft PPP compression/encryption (MPPC/MPPE)
9 +CONFIG_PPP_MPPE_MPPC
10 + Support for the Microsoft Point-To-Point Compression (RFC2118) and
11 + Microsoft Point-To-Point Encryption (RFC3078). These protocols are
12 + supported by Microsoft Windows and wide range of "hardware" access
13 + servers. MPPE is common protocol in Virtual Private Networks. According
14 + to RFC3078, MPPE supports 40, 56 and 128-bit key lengths. Depending on
15 + PPP daemon configuration on both ends of the link, following scenarios
16 + are possible:
17 + - only compression (MPPC) is used,
18 + - only encryption (MPPE) is used,
19 + - compression and encryption (MPPC+MPPE) are used.
21 + Please note that Hi/Fn (http://www.hifn.com) holds patent on MPPC so
22 + you should check if this patent is valid in your country in order to
23 + avoid legal problems.
25 + For more information please visit http://free.polbox.pl/h/hs001
27 + To compile this driver as a module, choose M here. The module will
28 + be called ppp_mppe_mppc.o.
30 PPP over Ethernet
31 CONFIG_PPPOE
32 Support for PPP over Ethernet.
33 diff -ruN linux.orig/crypto/Config.in linux/crypto/Config.in
34 --- linux.orig/crypto/Config.in 2004-08-08 12:14:50.000000000 +0200
35 +++ linux/crypto/Config.in 2004-08-15 11:36:18.000000000 +0200
36 @@ -11,7 +11,9 @@
37 "$CONFIG_INET6_AH" = "y" -o \
38 "$CONFIG_INET6_AH" = "m" -o \
39 "$CONFIG_INET6_ESP" = "y" -o \
40 - "$CONFIG_INET6_ESP" = "m" ]; then
41 + "$CONFIG_INET6_ESP" = "m" -o \
42 + "$CONFIG_PPP_MPPE_MPPC" = "y" -o \
43 + "$CONFIG_PPP_MPPE_MPPC" = "m" ]; then
44 define_bool CONFIG_CRYPTO y
45 else
46 bool 'Cryptographic API' CONFIG_CRYPTO
47 @@ -44,6 +46,7 @@
48 else
49 tristate ' MD5 digest algorithm' CONFIG_CRYPTO_MD5
52 if [ "$CONFIG_INET_AH" = "y" -o \
53 "$CONFIG_INET_AH" = "m" -o \
54 "$CONFIG_INET_ESP" = "y" -o \
55 @@ -51,11 +54,24 @@
56 "$CONFIG_INET6_AH" = "y" -o \
57 "$CONFIG_INET6_AH" = "m" -o \
58 "$CONFIG_INET6_ESP" = "y" -o \
59 - "$CONFIG_INET6_ESP" = "m" ]; then
60 - define_bool CONFIG_CRYPTO_SHA1 y
61 - else
62 - tristate ' SHA1 digest algorithm' CONFIG_CRYPTO_SHA1
63 + "$CONFIG_INET6_ESP" = "m" -o \
64 + "$CONFIG_PPP_MPPE_MPPC" = "y" -o \
65 + "$CONFIG_PPP_MPPE_MPPC" = "m" ]; then
66 + if [ "$CONFIG_INET_AH" = "y" -o \
67 + "$CONFIG_INET_ESP" = "y" -o \
68 + "$CONFIG_INET6_AH" = "y" -o \
69 + "$CONFIG_INET6_ESP" = "y" -o \
70 + "$CONFIG_PPP_MPPE_MPPC" = "y" ]; then
71 + define_tristate CONFIG_CRYPTO_SHA1 y
72 + else
73 + if [ "$CONFIG_CRYPTO_SHA1" != "y" -a \
74 + "$CONFIG_CRYPTO_SHA1" != "m" ]; then
75 + define_tristate CONFIG_CRYPTO_SHA1 m
76 + fi
77 + fi
79 + tristate ' SHA1 digest algorithm' CONFIG_CRYPTO_SHA1
81 tristate ' SHA256 digest algorithm' CONFIG_CRYPTO_SHA256
82 tristate ' SHA384 and SHA512 digest algorithms' CONFIG_CRYPTO_SHA512
83 if [ "$CONFIG_INET_ESP" = "y" -o \
84 @@ -73,7 +89,20 @@
85 tristate ' CAST5 (CAST-128) cipher algorithm' CONFIG_CRYPTO_CAST5
86 tristate ' CAST6 (CAST-256) cipher algorithm' CONFIG_CRYPTO_CAST6
87 tristate ' TEA and XTEA cipher algorithms' CONFIG_CRYPTO_TEA
89 + if [ "$CONFIG_PPP_MPPE_MPPC" = "y" -o \
90 + "$CONFIG_PPP_MPPE_MPPC" = "m" ]; then
91 + if [ "$CONFIG_PPP_MPPE_MPPC" = "y" ]; then
92 + define_tristate CONFIG_CRYPTO_ARC4 y
93 + else
94 + if [ "$CONFIG_CRYPTO_ARC4" != "y" -a \
95 + "$CONFIG_CRYPTO_ARC4" != "m" ]; then
96 + define_tristate CONFIG_CRYPTO_ARC4 m
97 + fi
98 + fi
99 + fi
100 tristate ' ARC4 cipher algorithm' CONFIG_CRYPTO_ARC4
102 if [ "$CONFIG_INET_IPCOMP" = "y" -o \
103 "$CONFIG_INET_IPCOMP" = "m" -o \
104 "$CONFIG_INET6_IPCOMP" = "y" -o \
105 diff -ruN linux.orig/drivers/net/Config.in linux/drivers/net/Config.in
106 --- linux.orig/drivers/net/Config.in 2004-08-08 12:14:52.000000000 +0200
107 +++ linux/drivers/net/Config.in 2004-08-08 12:17:43.000000000 +0200
108 @@ -325,6 +325,7 @@
109 dep_tristate ' PPP support for sync tty ports' CONFIG_PPP_SYNC_TTY $CONFIG_PPP
110 dep_tristate ' PPP Deflate compression' CONFIG_PPP_DEFLATE $CONFIG_PPP
111 dep_tristate ' PPP BSD-Compress compression' CONFIG_PPP_BSDCOMP $CONFIG_PPP
112 + dep_tristate ' Microsoft PPP compression/encryption (MPPC/MPPE)' CONFIG_PPP_MPPE_MPPC $CONFIG_PPP
113 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
114 dep_tristate ' PPP over Ethernet (EXPERIMENTAL)' CONFIG_PPPOE $CONFIG_PPP
116 diff -ruN linux.orig/drivers/net/Makefile linux/drivers/net/Makefile
117 --- linux.orig/drivers/net/Makefile 2004-08-08 12:14:52.000000000 +0200
118 +++ linux/drivers/net/Makefile 2004-08-08 12:17:43.000000000 +0200
119 @@ -161,6 +161,7 @@
120 obj-$(CONFIG_PPP_SYNC_TTY) += ppp_synctty.o
121 obj-$(CONFIG_PPP_DEFLATE) += ppp_deflate.o
122 obj-$(CONFIG_PPP_BSDCOMP) += bsd_comp.o
123 +obj-$(CONFIG_PPP_MPPE_MPPC) += ppp_mppe_mppc.o
124 obj-$(CONFIG_PPPOE) += pppox.o pppoe.o
126 obj-$(CONFIG_SLIP) += slip.o
127 diff -ruN linux.orig/drivers/net/ppp_generic.c linux/drivers/net/ppp_generic.c
128 --- linux.orig/drivers/net/ppp_generic.c 2003-08-25 13:44:42.000000000 +0200
129 +++ linux/drivers/net/ppp_generic.c 2004-08-08 12:17:43.000000000 +0200
130 @@ -19,7 +19,7 @@
131 * PPP driver, written by Michael Callahan and Al Longyear, and
132 * subsequently hacked by Paul Mackerras.
134 - * ==FILEVERSION 20020217==
135 + * ==FILEVERSION 20040509==
138 #include <linux/config.h>
139 @@ -102,6 +102,7 @@
140 spinlock_t rlock; /* lock for receive side 58 */
141 spinlock_t wlock; /* lock for transmit side 5c */
142 int mru; /* max receive unit 60 */
143 + int mru_alloc; /* MAX(1500,MRU) for dev_alloc_skb() */
144 unsigned int flags; /* control bits 64 */
145 unsigned int xstate; /* transmit state bits 68 */
146 unsigned int rstate; /* receive state bits 6c */
147 @@ -552,7 +553,9 @@
148 case PPPIOCSMRU:
149 if (get_user(val, (int *) arg))
150 break;
151 - ppp->mru = val;
152 + ppp->mru_alloc = ppp->mru = val;
153 + if (ppp->mru_alloc < PPP_MRU)
154 + ppp->mru_alloc = PPP_MRU; /* increase for broken peers */
155 err = 0;
156 break;
158 @@ -1025,14 +1028,37 @@
159 case PPP_CCP:
160 /* peek at outbound CCP frames */
161 ppp_ccp_peek(ppp, skb, 0);
162 + /*
163 + * When LZS or MPPE/MPPC has been negotiated we don't send
164 + * CCP_RESETACK after receiving CCP_RESETREQ; in fact pppd
165 + * sends such a packet but we silently discard it here
166 + */
167 + if (CCP_CODE(skb->data+2) == CCP_RESETACK
168 + && (ppp->xcomp->compress_proto == CI_MPPE
169 + || ppp->xcomp->compress_proto == CI_LZS)) {
170 + --ppp->stats.tx_packets;
171 + ppp->stats.tx_bytes -= skb->len - 2;
172 + kfree_skb(skb);
173 + return;
175 break;
178 /* try to do packet compression */
179 if ((ppp->xstate & SC_COMP_RUN) && ppp->xc_state != 0
180 && proto != PPP_LCP && proto != PPP_CCP) {
181 - new_skb = alloc_skb(ppp->dev->mtu + ppp->dev->hard_header_len,
182 - GFP_ATOMIC);
183 + int comp_ovhd = 0;
184 + /*
185 + * because of possible data expansion when MPPC or LZS
186 + * is used, allocate compressor's buffer 12.5% bigger
187 + * than MTU
188 + */
189 + if (ppp->xcomp->compress_proto == CI_MPPE)
190 + comp_ovhd = ((ppp->dev->mtu * 9) / 8) + 1 + MPPE_OVHD;
191 + else if (ppp->xcomp->compress_proto == CI_LZS)
192 + comp_ovhd = ((ppp->dev->mtu * 9) / 8) + 1 + LZS_OVHD;
193 + new_skb = alloc_skb(ppp->dev->mtu + ppp->dev->hard_header_len
194 + + comp_ovhd, GFP_ATOMIC);
195 if (new_skb == 0) {
196 printk(KERN_ERR "PPP: no memory (comp pkt)\n");
197 goto drop;
198 @@ -1050,9 +1076,21 @@
199 skb = new_skb;
200 skb_put(skb, len);
201 skb_pull(skb, 2); /* pull off A/C bytes */
202 - } else {
203 + } else if (len == 0) {
204 /* didn't compress, or CCP not up yet */
205 kfree_skb(new_skb);
206 + } else {
207 + /*
208 + * (len < 0)
209 + * MPPE requires that we do not send unencrypted
210 + * frames. The compressor will return -1 if we
211 + * should drop the frame. We cannot simply test
212 + * the compress_proto because MPPE and MPPC share
213 + * the same number.
214 + */
215 + printk(KERN_ERR "ppp: compressor dropped pkt\n");
216 + kfree_skb(new_skb);
217 + goto drop;
221 @@ -1540,14 +1578,15 @@
222 int len;
224 if (proto == PPP_COMP) {
225 - ns = dev_alloc_skb(ppp->mru + PPP_HDRLEN);
226 + ns = dev_alloc_skb(ppp->mru_alloc + PPP_HDRLEN);
227 if (ns == 0) {
228 printk(KERN_ERR "ppp_decompress_frame: no memory\n");
229 goto err;
231 /* the decompressor still expects the A/C bytes in the hdr */
232 len = ppp->rcomp->decompress(ppp->rc_state, skb->data - 2,
233 - skb->len + 2, ns->data, ppp->mru + PPP_HDRLEN);
234 + skb->len + 2, ns->data,
235 + ppp->mru_alloc + PPP_HDRLEN);
236 if (len < 0) {
237 /* Pass the compressed frame to pppd as an
238 error indication. */
239 @@ -1573,7 +1612,14 @@
240 return skb;
242 err:
243 - ppp->rstate |= SC_DC_ERROR;
244 + if (ppp->rcomp->compress_proto != CI_MPPE
245 + && ppp->rcomp->compress_proto != CI_LZS) {
246 + /*
247 + * If decompression protocol isn't MPPE/MPPC or LZS, we set
248 + * SC_DC_ERROR flag and wait for CCP_RESETACK
249 + */
250 + ppp->rstate |= SC_DC_ERROR;
252 ppp_receive_error(ppp);
253 return skb;
255 @@ -2253,6 +2299,7 @@
256 /* Initialize the new ppp unit */
257 ppp->file.index = unit;
258 ppp->mru = PPP_MRU;
259 + ppp->mru_alloc = PPP_MRU;
260 init_ppp_file(&ppp->file, INTERFACE);
261 ppp->file.hdrlen = PPP_HDRLEN - 2; /* don't count proto bytes */
262 for (i = 0; i < NUM_NP; ++i)
263 diff -ruN linux.orig/drivers/net/ppp_mppe_mppc.c linux/drivers/net/ppp_mppe_mppc.c
264 --- linux.orig/drivers/net/ppp_mppe_mppc.c 1970-01-01 01:00:00.000000000 +0100
265 +++ linux/drivers/net/ppp_mppe_mppc.c 2004-08-15 10:12:23.000000000 +0200
266 @@ -0,0 +1,1269 @@
268 + * ppp_mppe_mppc.c - MPPC/MPPE "compressor/decompressor" module.
270 + * Copyright (c) 1994 Árpád Magosányi <mag@bunuel.tii.matav.hu>
271 + * Copyright (c) 1999 Tim Hockin, Cobalt Networks Inc. <thockin@cobaltnet.com>
272 + * Copyright (c) 2002-2004 Jan Dubiec <jdx@slackware.pl>
273 + *
274 + * Permission to use, copy, modify, and distribute this software and its
275 + * documentation is hereby granted, provided that the above copyright
276 + * notice appears in all copies. This software is provided without any
277 + * warranty, express or implied.
279 + * The code is based on MPPE kernel module written by Árpád Magosányi and
280 + * Tim Hockin which can be found on http://planetmirror.com/pub/mppe/.
281 + * I have added MPPC and 56 bit session keys support in MPPE.
283 + * WARNING! Although this is open source code, its usage in some countries
284 + * (in particular in the USA) may violate Stac Inc. patent for MPPC.
286 + * ==FILEVERSION 20040815==
288 + */
290 +#include <linux/init.h>
291 +#include <linux/module.h>
292 +#include <linux/mm.h>
293 +#include <linux/slab.h>
294 +#include <asm/scatterlist.h>
295 +#include <linux/vmalloc.h>
296 +#include <linux/crypto.h>
298 +#include <linux/ppp_defs.h>
299 +#include <linux/ppp-comp.h>
302 + * In 2.4.x kernels macro offset_in_page() is not defined in linux/mm.h so
303 + * we define it here; PAGE_MASK is defined in asm/page.h which is included
304 + * by linux/mm.h.
305 + */
306 +#define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK)
309 + * State for a mppc/mppe "(de)compressor".
310 + */
311 +struct ppp_mppe_state {
312 + struct crypto_tfm *arc4_tfm;
313 + struct crypto_tfm *sha1_tfm;
314 + u8 master_key[MPPE_MAX_KEY_LEN];
315 + u8 session_key[MPPE_MAX_KEY_LEN];
316 + u8 mppc; /* do we use compression (MPPC)? */
317 + u8 mppe; /* do we use encryption (MPPE)? */
318 + u8 keylen; /* key length in bytes */
319 + u8 bitkeylen; /* key length in bits */
320 + u16 ccount; /* coherency counter */
321 + u16 bits; /* MPPC/MPPE control bits */
322 + u8 stateless; /* do we use stateless mode? */
323 + u8 nextflushed; /* set A bit in the next outgoing packet;
324 + used only by compressor*/
325 + u8 flushexpected; /* drop packets until A bit is received;
326 + used only by decompressor*/
327 + u8 *hist; /* MPPC history */
328 + u16 *hash; /* Hash table; used only by compressor */
329 + u16 histptr; /* history "cursor" */
330 + int unit;
331 + int debug;
332 + int mru;
333 + struct compstat stats;
336 +#define MPPE_HIST_LEN 8192 /* MPPC history size */
337 +#define MPPE_MAX_CCOUNT 0x0FFF /* max. coherency counter value */
339 +#define MPPE_BIT_FLUSHED 0x80 /* bit A */
340 +#define MPPE_BIT_RESET 0x40 /* bit B */
341 +#define MPPE_BIT_COMP 0x20 /* bit C */
342 +#define MPPE_BIT_ENCRYPTED 0x10 /* bit D */
344 +#define MPPE_SALT0 0xD1 /* values used in MPPE key derivation */
345 +#define MPPE_SALT1 0x26 /* according to RFC3079 */
346 +#define MPPE_SALT2 0x9E
348 +#define MPPE_CCOUNT(x) ((((x)[4] & 0x0f) << 8) + (x)[5])
349 +#define MPPE_BITS(x) ((x)[4] & 0xf0)
350 +#define MPPE_CTRLHI(x) ((((x)->ccount & 0xf00)>>8)|((x)->bits))
351 +#define MPPE_CTRLLO(x) ((x)->ccount & 0xff)
353 +static inline void
354 +setup_sg(struct scatterlist *sg, const void *address, unsigned int length)
356 + sg[0].page = virt_to_page(address);
357 + sg[0].offset = offset_in_page(address);
358 + sg[0].length = length;
361 +static inline void
362 +arc4_setkey(struct ppp_mppe_state *state, const unsigned char *key,
363 + const unsigned int keylen)
365 + crypto_cipher_setkey(state->arc4_tfm, key, keylen);
368 +static inline void
369 +arc4_encrypt(struct ppp_mppe_state *state, const unsigned char *in,
370 + const unsigned int len, unsigned char *out)
372 + struct scatterlist sgin[4], sgout[4];
374 + setup_sg(sgin, in, len);
375 + setup_sg(sgout, out, len);
376 + crypto_cipher_encrypt(state->arc4_tfm, sgout, sgin, len);
379 +#define arc4_decrypt arc4_encrypt
382 + * Key Derivation, from RFC 3078, RFC 3079.
383 + * Equivalent to Get_Key() for MS-CHAP as described in RFC 3079.
384 + */
385 +static void
386 +GetNewKeyFromSHA(struct ppp_mppe_state *state, unsigned char *MasterKey,
387 + unsigned char *SessionKey, unsigned long SessionKeyLength,
388 + unsigned char *InterimKey)
390 + /*Pads used in key derivation */
391 + static const unsigned char SHAPad1[40] = {
392 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
393 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
394 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
395 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
396 + };
398 + static const unsigned char SHAPad2[40] = {
399 + 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
400 + 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
401 + 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
402 + 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2
403 + };
405 + unsigned char Digest[20]; /* SHA1_DIGEST_SIZE = 20 */
406 + struct scatterlist sg[2];
408 + crypto_digest_init(state->sha1_tfm);
410 + setup_sg(sg, MasterKey, SessionKeyLength);
411 + crypto_digest_update(state->sha1_tfm, sg, 1);
413 + setup_sg(sg, SHAPad1, sizeof(SHAPad1));
414 + crypto_digest_update(state->sha1_tfm, sg, 1);
416 + setup_sg(sg, SessionKey, SessionKeyLength);
417 + crypto_digest_update(state->sha1_tfm, sg, 1);
419 + setup_sg(sg, SHAPad2, sizeof(SHAPad2));
420 + crypto_digest_update(state->sha1_tfm, sg, 1);
422 + crypto_digest_final(state->sha1_tfm, Digest);
424 + memcpy(InterimKey, Digest, SessionKeyLength);
427 +static void
428 +mppe_change_key(struct ppp_mppe_state *state, int initialize)
430 + unsigned char InterimKey[MPPE_MAX_KEY_LEN];
432 + GetNewKeyFromSHA(state, state->master_key, state->session_key,
433 + state->keylen, InterimKey);
434 + if (initialize) {
435 + memcpy(state->session_key, InterimKey, state->keylen);
436 + } else {
437 + arc4_setkey(state, InterimKey, state->keylen);
438 + arc4_encrypt(state, InterimKey, state->keylen, state->session_key);
440 + if (state->keylen == 8) {
441 + if (state->bitkeylen == 40) {
442 + state->session_key[0] = MPPE_SALT0;
443 + state->session_key[1] = MPPE_SALT1;
444 + state->session_key[2] = MPPE_SALT2;
445 + } else {
446 + state->session_key[0] = MPPE_SALT0;
449 + arc4_setkey(state, state->session_key, state->keylen);
452 +/* increase 12-bit coherency counter */
453 +static inline void
454 +mppe_increase_ccount(struct ppp_mppe_state *state)
456 + state->ccount = (state->ccount + 1) & MPPE_MAX_CCOUNT;
457 + if (state->mppe) {
458 + if (state->stateless) {
459 + mppe_change_key(state, 0);
460 + state->nextflushed = 1;
461 + } else {
462 + if ((state->ccount & 0xff) == 0xff) {
463 + mppe_change_key(state, 0);
469 +/* allocate space for a MPPE/MPPC (de)compressor. */
470 +/* comp != 0 -> init compressor */
471 +/* comp = 0 -> init decompressor */
472 +static void *
473 +mppe_alloc(unsigned char *options, int opt_len, int comp)
475 + struct ppp_mppe_state *state;
476 + u8* fname;
478 + fname = comp ? "mppe_comp_alloc" : "mppe_decomp_alloc";
480 + /*
481 + * Hack warning - additionally to the standard MPPC/MPPE configuration
482 + * options, pppd passes to the (de)copressor 8 or 16 byte session key.
483 + * Therefore options[1] contains MPPC/MPPE configuration option length
484 + * (CILEN_MPPE = 6), but the real options length, depending on the key
485 + * length, is 6+8 or 6+16.
486 + */
487 + if (opt_len < CILEN_MPPE) {
488 + printk(KERN_WARNING "%s: wrong options length: %u\n", fname, opt_len);
489 + return NULL;
492 + if (options[0] != CI_MPPE || options[1] != CILEN_MPPE ||
493 + (options[2] & ~MPPE_STATELESS) != 0 ||
494 + options[3] != 0 || options[4] != 0 ||
495 + (options[5] & ~(MPPE_128BIT|MPPE_56BIT|MPPE_40BIT|MPPE_MPPC)) != 0 ||
496 + (options[5] & (MPPE_128BIT|MPPE_56BIT|MPPE_40BIT|MPPE_MPPC)) == 0) {
497 + printk(KERN_WARNING "%s: options rejected: o[0]=%02x, o[1]=%02x, "
498 + "o[2]=%02x, o[3]=%02x, o[4]=%02x, o[5]=%02x\n", fname, options[0],
499 + options[1], options[2], options[3], options[4], options[5]);
500 + return NULL;
503 + state = (struct ppp_mppe_state *)kmalloc(sizeof(*state), GFP_KERNEL);
504 + if (state == NULL) {
505 + printk(KERN_ERR "%s: cannot allocate space for %scompressor\n", fname,
506 + comp ? "" : "de");
507 + return NULL;
509 + memset(state, 0, sizeof(struct ppp_mppe_state));
511 + state->mppc = options[5] & MPPE_MPPC; /* Do we use MPPC? */
512 + state->mppe = options[5] & (MPPE_128BIT | MPPE_56BIT |
513 + MPPE_40BIT); /* Do we use MPPE? */
515 + if (state->mppc) {
516 + /* allocate MPPC history */
517 + state->hist = (u8*)vmalloc(2*MPPE_HIST_LEN*sizeof(u8));
518 + if (state->hist == NULL) {
519 + kfree(state);
520 + printk(KERN_ERR "%s: cannot allocate space for MPPC history\n",
521 + fname);
522 + return NULL;
525 + /* allocate hashtable for MPPC compressor */
526 + if (comp) {
527 + state->hash = (u16*)vmalloc(MPPE_HIST_LEN*sizeof(u16));
528 + if (state->hash == NULL) {
529 + vfree(state->hist);
530 + kfree(state);
531 + printk(KERN_ERR "%s: cannot allocate space for MPPC history\n",
532 + fname);
533 + return NULL;
538 + if (state->mppe) { /* specific for MPPE */
539 + /* Load SHA1 algorithm */
540 + state->sha1_tfm = crypto_alloc_tfm("sha1", 0);
541 + if (state->sha1_tfm == NULL) {
542 + vfree(state->hash);
543 + vfree(state->hist);
544 + kfree(state);
545 + printk(KERN_ERR "%s: cannot load SHA1 module\n", fname);
546 + return NULL;
549 + /* Load ARC4 algorithm */
550 + state->arc4_tfm = crypto_alloc_tfm("arc4", 0);
551 + if (state->arc4_tfm == NULL) {
552 + crypto_free_tfm(state->sha1_tfm);
553 + vfree(state->hash);
554 + vfree(state->hist);
555 + kfree(state);
556 + printk(KERN_ERR "%s: cannot load ARC4 module\n", fname);
557 + return NULL;
560 + memcpy(state->master_key, options+CILEN_MPPE, MPPE_MAX_KEY_LEN);
561 + memcpy(state->session_key, state->master_key, MPPE_MAX_KEY_LEN);
562 + /* initial key generation is done in mppe_init() */
565 + MOD_INC_USE_COUNT;
567 + return (void *) state;
570 +static void *
571 +mppe_comp_alloc(unsigned char *options, int opt_len)
573 + return mppe_alloc(options, opt_len, 1);
576 +static void *
577 +mppe_decomp_alloc(unsigned char *options, int opt_len)
579 + return mppe_alloc(options, opt_len, 0);
582 +/* cleanup the (de)compressor */
583 +static void
584 +mppe_comp_free(void *arg)
586 + struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
588 + if (state != NULL) {
589 + if (state->mppe) {
590 + if (state->sha1_tfm != NULL)
591 + crypto_free_tfm(state->sha1_tfm);
592 + if (state->arc4_tfm != NULL)
593 + crypto_free_tfm(state->arc4_tfm);
595 + if (state->hist != NULL)
596 + vfree(state->hist);
597 + if (state->hash != NULL)
598 + vfree(state->hash);
599 + kfree(state);
602 + MOD_DEC_USE_COUNT;
605 +/* init MPPC/MPPE (de)compresor */
606 +/* comp != 0 -> init compressor */
607 +/* comp = 0 -> init decompressor */
608 +static int
609 +mppe_init(void *arg, unsigned char *options, int opt_len, int unit,
610 + int hdrlen, int mru, int debug, int comp)
612 + struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
613 + u8* fname;
615 + fname = comp ? "mppe_comp_init" : "mppe_decomp_init";
617 + if (opt_len < CILEN_MPPE) {
618 + if (debug)
619 + printk(KERN_WARNING "%s: wrong options length: %u\n",
620 + fname, opt_len);
621 + return 0;
624 + if (options[0] != CI_MPPE || options[1] != CILEN_MPPE ||
625 + (options[2] & ~MPPE_STATELESS) != 0 ||
626 + options[3] != 0 || options[4] != 0 ||
627 + (options[5] & ~(MPPE_56BIT|MPPE_128BIT|MPPE_40BIT|MPPE_MPPC)) != 0 ||
628 + (options[5] & (MPPE_56BIT|MPPE_128BIT|MPPE_40BIT|MPPE_MPPC)) == 0) {
629 + if (debug)
630 + printk(KERN_WARNING "%s: options rejected: o[0]=%02x, o[1]=%02x, "
631 + "o[2]=%02x, o[3]=%02x, o[4]=%02x, o[5]=%02x\n", fname,
632 + options[0], options[1], options[2], options[3], options[4],
633 + options[5]);
634 + return 0;
637 + if ((options[5] & ~MPPE_MPPC) != MPPE_128BIT &&
638 + (options[5] & ~MPPE_MPPC) != MPPE_56BIT &&
639 + (options[5] & ~MPPE_MPPC) != MPPE_40BIT &&
640 + (options[5] & MPPE_MPPC) != MPPE_MPPC) {
641 + if (debug)
642 + printk(KERN_WARNING "%s: don't know what to do: o[5]=%02x\n",
643 + fname, options[5]);
644 + return 0;
647 + state->mppc = options[5] & MPPE_MPPC; /* Do we use MPPC? */
648 + state->mppe = options[5] & (MPPE_128BIT | MPPE_56BIT |
649 + MPPE_40BIT); /* Do we use MPPE? */
650 + state->stateless = options[2] & MPPE_STATELESS; /* Do we use stateless mode? */
652 + switch (state->mppe) {
653 + case MPPE_40BIT: /* 40 bit key */
654 + state->keylen = 8;
655 + state->bitkeylen = 40;
656 + break;
657 + case MPPE_56BIT: /* 56 bit key */
658 + state->keylen = 8;
659 + state->bitkeylen = 56;
660 + break;
661 + case MPPE_128BIT: /* 128 bit key */
662 + state->keylen = 16;
663 + state->bitkeylen = 128;
664 + break;
665 + default:
666 + state->keylen = 0;
667 + state->bitkeylen = 0;
670 + state->ccount = MPPE_MAX_CCOUNT;
671 + state->bits = 0;
672 + state->unit = unit;
673 + state->debug = debug;
674 + state->histptr = MPPE_HIST_LEN;
675 + if (state->mppc) { /* reset history if MPPC was negotiated */
676 + memset(state->hist, 0, 2*MPPE_HIST_LEN*sizeof(u8));
679 + if (state->mppe) { /* generate initial session keys */
680 + mppe_change_key(state, 1);
683 + if (comp) { /* specific for compressor */
684 + state->nextflushed = 1;
685 + } else { /* specific for decompressor */
686 + state->mru = mru;
687 + state->flushexpected = 1;
690 + return 1;
693 +static int
694 +mppe_comp_init(void *arg, unsigned char *options, int opt_len, int unit,
695 + int hdrlen, int debug)
697 + return mppe_init(arg, options, opt_len, unit, hdrlen, 0, debug, 1);
701 +static int
702 +mppe_decomp_init(void *arg, unsigned char *options, int opt_len, int unit,
703 + int hdrlen, int mru, int debug)
705 + return mppe_init(arg, options, opt_len, unit, hdrlen, mru, debug, 0);
708 +static void
709 +mppe_comp_reset(void *arg)
711 + struct ppp_mppe_state *state = (struct ppp_mppe_state *)arg;
713 + if (state->debug)
714 + printk(KERN_DEBUG "%s%d: resetting MPPC/MPPE compressor\n",
715 + __FUNCTION__, state->unit);
717 + state->nextflushed = 1;
718 + if (state->mppe)
719 + arc4_setkey(state, state->session_key, state->keylen);
722 +static void
723 +mppe_decomp_reset(void *arg)
725 + /* When MPPC/MPPE is in use, we shouldn't receive any CCP Reset-Ack.
726 + But when we receive such a packet, we just ignore it. */
727 + return;
730 +static void
731 +mppe_stats(void *arg, struct compstat *stats)
733 + struct ppp_mppe_state *state = (struct ppp_mppe_state *)arg;
735 + *stats = state->stats;
738 +/***************************/
739 +/**** Compression stuff ****/
740 +/***************************/
741 +/* inserts 1 to 8 bits into the output buffer */
742 +static inline void putbits8(u8 *buf, u32 val, const u32 n, u32 *i, u32 *l)
744 + buf += *i;
745 + if (*l >= n) {
746 + *l = (*l) - n;
747 + val <<= *l;
748 + *buf = *buf | (val & 0xff);
749 + if (*l == 0) {
750 + *l = 8;
751 + (*i)++;
752 + *(++buf) = 0;
754 + } else {
755 + (*i)++;
756 + *l = 8 - n + (*l);
757 + val <<= *l;
758 + *buf = *buf | ((val >> 8) & 0xff);
759 + *(++buf) = val & 0xff;
763 +/* inserts 9 to 16 bits into the output buffer */
764 +static inline void putbits16(u8 *buf, u32 val, const u32 n, u32 *i, u32 *l)
766 + buf += *i;
767 + if (*l >= n - 8) {
768 + (*i)++;
769 + *l = 8 - n + (*l);
770 + val <<= *l;
771 + *buf = *buf | ((val >> 8) & 0xff);
772 + *(++buf) = val & 0xff;
773 + if (*l == 0) {
774 + *l = 8;
775 + (*i)++;
776 + *(++buf) = 0;
778 + } else {
779 + (*i)++; (*i)++;
780 + *l = 16 - n + (*l);
781 + val <<= *l;
782 + *buf = *buf | ((val >> 16) & 0xff);
783 + *(++buf) = (val >> 8) & 0xff;
784 + *(++buf) = val & 0xff;
788 +/* inserts 17 to 24 bits into the output buffer */
789 +static inline void putbits24(u8 *buf, u32 val, const u32 n, u32 *i, u32 *l)
791 + buf += *i;
792 + if (*l >= n - 16) {
793 + (*i)++; (*i)++;
794 + *l = 16 - n + (*l);
795 + val <<= *l;
796 + *buf = *buf | ((val >> 16) & 0xff);
797 + *(++buf) = (val >> 8) & 0xff;
798 + *(++buf) = val & 0xff;
799 + if (*l == 0) {
800 + *l = 8;
801 + (*i)++;
802 + *(++buf) = 0;
804 + } else {
805 + (*i)++; (*i)++; (*i)++;
806 + *l = 24 - n + (*l);
807 + val <<= *l;
808 + *buf = *buf | ((val >> 24) & 0xff);
809 + *(++buf) = (val >> 16) & 0xff;
810 + *(++buf) = (val >> 8) & 0xff;
811 + *(++buf) = val & 0xff;
815 +static int
816 +mppc_compress(struct ppp_mppe_state *state, unsigned char *ibuf,
817 + unsigned char *obuf, int isize, int osize)
819 + u32 olen, off, len, idx, i, l;
820 + u8 *hist, *sbuf, *p, *q, *r, *s;
822 + /*
823 + At this point, to avoid possible buffer overflow caused by packet
824 + expansion during/after compression, we should make sure that
825 + osize >= (((isize*9)/8)+1)+2, but we don't do that because in
826 + ppp_generic.c we simply allocate bigger obuf.
828 + Maximum MPPC packet expansion is 12.5%. This is the worst case when
829 + all octets in the input buffer are >= 0x80 and we cannot find any
830 + repeated tokens. Additionally we have to reserve 2 bytes for MPPE/MPPC
831 + status bits and coherency counter.
832 + */
834 + hist = state->hist + MPPE_HIST_LEN;
835 + /* check if there is enough room at the end of the history */
836 + if (state->histptr + isize >= 2*MPPE_HIST_LEN) {
837 + state->bits |= MPPE_BIT_RESET;
838 + state->histptr = MPPE_HIST_LEN;
839 + memcpy(state->hist, hist, MPPE_HIST_LEN);
841 + /* add packet to the history; isize must be <= MPPE_HIST_LEN */
842 + sbuf = state->hist + state->histptr;
843 + memcpy(sbuf, ibuf, isize);
844 + state->histptr += isize;
846 + /* compress data */
847 + r = sbuf + isize;
848 + *obuf = olen = i = 0;
849 + l = 8;
850 + while (i < isize - 2) {
851 + s = q = sbuf + i;
852 + idx = ((40543*((((s[0]<<4)^s[1])<<4)^s[2]))>>4) & 0x1fff;
853 + p = hist + state->hash[idx];
854 + state->hash[idx] = (u16) (s - hist);
855 + off = s - p;
856 + if (off > MPPE_HIST_LEN - 1 || off < 1 || *p++ != *s++ || *p++ != *s++ ||
857 + *p++ != *s++) {
858 + /* no match found; encode literal byte */
859 + if (ibuf[i] < 0x80) { /* literal byte < 0x80 */
860 + putbits8(obuf, (u32) ibuf[i], 8, &olen, &l);
861 + } else { /* literal byte >= 0x80 */
862 + putbits16(obuf, (u32) (0x100|(ibuf[i]&0x7f)), 9, &olen, &l);
864 + ++i;
865 + continue;
867 + if (r - q >= 64) {
868 + *p++ != *s++ || *p++ != *s++ || *p++ != *s++ || *p++ != *s++ ||
869 + *p++ != *s++ || *p++ != *s++ || *p++ != *s++ || *p++ != *s++ ||
870 + *p++ != *s++ || *p++ != *s++ || *p++ != *s++ || *p++ != *s++ ||
871 + *p++ != *s++ || *p++ != *s++ || *p++ != *s++ || *p++ != *s++ ||
872 + *p++ != *s++ || *p++ != *s++ || *p++ != *s++ || *p++ != *s++ ||
873 + *p++ != *s++ || *p++ != *s++ || *p++ != *s++ || *p++ != *s++ ||
874 + *p++ != *s++ || *p++ != *s++ || *p++ != *s++ || *p++ != *s++ ||
875 + *p++ != *s++ || *p++ != *s++ || *p++ != *s++ || *p++ != *s++ ||
876 + *p++ != *s++ || *p++ != *s++ || *p++ != *s++ || *p++ != *s++ ||
877 + *p++ != *s++ || *p++ != *s++ || *p++ != *s++ || *p++ != *s++ ||
878 + *p++ != *s++ || *p++ != *s++ || *p++ != *s++ || *p++ != *s++ ||
879 + *p++ != *s++ || *p++ != *s++ || *p++ != *s++ || *p++ != *s++ ||
880 + *p++ != *s++ || *p++ != *s++ || *p++ != *s++ || *p++ != *s++ ||
881 + *p++ != *s++ || *p++ != *s++ || *p++ != *s++ || *p++ != *s++ ||
882 + *p++ != *s++ || *p++ != *s++ || *p++ != *s++ || *p++ != *s++ ||
883 + *p++ != *s++;
884 + if (s - q == 64) {
885 + p--; s--;
886 + while((*p++ == *s++) && (s < r) && (p < q));
888 + } else {
889 + while((*p++ == *s++) && (s < r) && (p < q));
891 + len = s - q - 1;
892 + i += len;
894 + /* at least 3 character match found; code data */
895 + /* encode offset */
896 + if (off < 64) { /* 10-bit offset; 0 <= offset < 64 */
897 + putbits16(obuf, 0x3c0|off, 10, &olen, &l);
898 + } else if (off < 320) { /* 12-bit offset; 64 <= offset < 320 */
899 + putbits16(obuf, 0xe00|(off-64), 12, &olen, &l);
900 + } else if (off < 8192) { /* 16-bit offset; 320 <= offset < 8192 */
901 + putbits16(obuf, 0xc000|(off-320), 16, &olen, &l);
902 + } else {
903 + /* This shouldn't happen; we return 0 what means "packet expands",
904 + and we send packet uncompressed. */
905 + if (state->debug)
906 + printk(KERN_DEBUG "%s%d: wrong offset value: %d\n",
907 + __FUNCTION__, state->unit, off);
908 + return 0;
910 + /* encode length of match */
911 + if (len < 4) { /* length = 3 */
912 + putbits8(obuf, 0, 1, &olen, &l);
913 + } else if (len < 8) { /* 4 <= length < 8 */
914 + putbits8(obuf, 0x08|(len&0x03), 4, &olen, &l);
915 + } else if (len < 16) { /* 8 <= length < 16 */
916 + putbits8(obuf, 0x30|(len&0x07), 6, &olen, &l);
917 + } else if (len < 32) { /* 16 <= length < 32 */
918 + putbits8(obuf, 0xe0|(len&0x0f), 8, &olen, &l);
919 + } else if (len < 64) { /* 32 <= length < 64 */
920 + putbits16(obuf, 0x3c0|(len&0x1f), 10, &olen, &l);
921 + } else if (len < 128) { /* 64 <= length < 128 */
922 + putbits16(obuf, 0xf80|(len&0x3f), 12, &olen, &l);
923 + } else if (len < 256) { /* 128 <= length < 256 */
924 + putbits16(obuf, 0x3f00|(len&0x7f), 14, &olen, &l);
925 + } else if (len < 512) { /* 256 <= length < 512 */
926 + putbits16(obuf, 0xfe00|(len&0xff), 16, &olen, &l);
927 + } else if (len < 1024) { /* 512 <= length < 1024 */
928 + putbits24(obuf, 0x3fc00|(len&0x1ff), 18, &olen, &l);
929 + } else if (len < 2048) { /* 1024 <= length < 2048 */
930 + putbits24(obuf, 0xff800|(len&0x3ff), 20, &olen, &l);
931 + } else if (len < 4096) { /* 2048 <= length < 4096 */
932 + putbits24(obuf, 0x3ff000|(len&0x7ff), 22, &olen, &l);
933 + } else if (len < 8192) { /* 4096 <= length < 8192 */
934 + putbits24(obuf, 0xffe000|(len&0xfff), 24, &olen, &l);
935 + } else {
936 + /* This shouldn't happen; we return 0 what means "packet expands",
937 + and send packet uncompressed. */
938 + if (state->debug)
939 + printk(KERN_DEBUG "%s%d: wrong length of match value: %d\n",
940 + __FUNCTION__, state->unit, len);
941 + return 0;
945 + /* Add remaining octets to the output */
946 + while(isize - i > 0) {
947 + if (ibuf[i] < 0x80) { /* literal byte < 0x80 */
948 + putbits8(obuf, (u32) ibuf[i++], 8, &olen, &l);
949 + } else { /* literal byte >= 0x80 */
950 + putbits16(obuf, (u32) (0x100|(ibuf[i++]&0x7f)), 9, &olen, &l);
953 + /* Reset unused bits of the last output octet */
954 + if ((l != 0) && (l != 8)) {
955 + putbits8(obuf, 0, l, &olen, &l);
958 + return (int) olen;
961 +int
962 +mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
963 + int isize, int osize)
965 + struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
966 + int proto, olen, complen, off;
967 + unsigned char *wptr;
969 + /* Check that the protocol is in the range we handle. */
970 + proto = PPP_PROTOCOL(ibuf);
971 + if (proto < 0x0021 || proto > 0x00fa)
972 + return 0;
974 + wptr = obuf;
975 + /* Copy over the PPP header */
976 + wptr[0] = PPP_ADDRESS(ibuf);
977 + wptr[1] = PPP_CONTROL(ibuf);
978 + wptr[2] = PPP_COMP >> 8;
979 + wptr[3] = PPP_COMP;
980 + wptr += PPP_HDRLEN + (MPPE_OVHD / 2); /* Leave two octets for MPPE/MPPC bits */
982 + /*
983 + * In ver. 0.99 protocol field was compressed. Deflate and BSD compress
984 + * do PFC before actual compression, RCF2118 and RFC3078 are not precise
985 + * on this topic so I decided to do PFC. Unfortunately this change caused
986 + * incompatibility with older/other MPPE/MPPC modules. I have received
987 + * a lot of complaints from unexperienced users so I have decided to revert
988 + * to previous state, i.e. the protocol field is sent uncompressed now.
989 + * Although this may be changed in the future.
991 + * Receiving side (mppe_decompress()) still accepts packets with compressed
992 + * and uncompressed protocol field so you shouldn't get "Unsupported protocol
993 + * 0x2145 received" messages anymore.
994 + */
995 + //off = (proto > 0xff) ? 2 : 3; /* PFC - skip first protocol byte if 0 */
996 + off = 2;
998 + ibuf += off;
1000 + mppe_increase_ccount(state);
1002 + if (state->nextflushed) {
1003 + state->bits |= MPPE_BIT_FLUSHED;
1004 + state->nextflushed = 0;
1005 + if (state->mppe && !state->stateless) {
1006 + /*
1007 + * If this is the flag packet, the key has been already changed in
1008 + * mppe_increase_ccount() so we dont't do it once again.
1009 + */
1010 + if ((state->ccount & 0xff) != 0xff) {
1011 + arc4_setkey(state, state->session_key, state->keylen);
1014 + if (state->mppc) { /* reset history */
1015 + state->bits |= MPPE_BIT_RESET;
1016 + state->histptr = MPPE_HIST_LEN;
1017 + memset(state->hist + MPPE_HIST_LEN, 0, MPPE_HIST_LEN*sizeof(u8));
1021 + if (state->mppc && !state->mppe) { /* Do only compression */
1022 + complen = mppc_compress(state, ibuf, wptr, isize - off,
1023 + osize - PPP_HDRLEN - (MPPE_OVHD / 2));
1024 + /*
1025 + * TODO: Implement an heuristics to handle packet expansion in a smart
1026 + * way. Now, when a packet expands, we send it as uncompressed and
1027 + * when next packet is sent we have to reset compressor's history.
1028 + * Maybe it would be better to send such packet as compressed in order
1029 + * to keep history's continuity.
1030 + */
1031 + if ((complen > isize) || (complen > osize - PPP_HDRLEN) ||
1032 + (complen == 0)) {
1033 + /* packet expands */
1034 + state->nextflushed = 1;
1035 + memcpy(wptr, ibuf, isize - off);
1036 + olen = isize - (off - 2) + MPPE_OVHD;
1037 + (state->stats).inc_bytes += olen;
1038 + (state->stats).inc_packets++;
1039 + } else {
1040 + state->bits |= MPPE_BIT_COMP;
1041 + olen = complen + PPP_HDRLEN + (MPPE_OVHD / 2);
1042 + (state->stats).comp_bytes += olen;
1043 + (state->stats).comp_packets++;
1045 + } else { /* Do encryption with or without compression */
1046 + state->bits |= MPPE_BIT_ENCRYPTED;
1047 + if (!state->mppc && state->mppe) { /* Do only encryption */
1048 + /* read from ibuf, write to wptr, adjust for PPP_HDRLEN */
1049 + arc4_encrypt(state, ibuf, isize - off, wptr);
1050 + olen = isize - (off - 2) + MPPE_OVHD;
1051 + (state->stats).inc_bytes += olen;
1052 + (state->stats).inc_packets++;
1053 + } else { /* Do compression and then encryption - RFC3078 */
1054 + complen = mppc_compress(state, ibuf, wptr, isize - off,
1055 + osize - PPP_HDRLEN - (MPPE_OVHD / 2));
1056 + /*
1057 + * TODO: Implement an heuristics to handle packet expansion in a smart
1058 + * way. Now, when a packet expands, we send it as uncompressed and
1059 + * when next packet is sent we have to reset compressor's history.
1060 + * Maybe it would be good to send such packet as compressed in order
1061 + * to keep history's continuity.
1062 + */
1063 + if ((complen > isize) || (complen > osize - PPP_HDRLEN) ||
1064 + (complen == 0)) {
1065 + /* packet expands */
1066 + state->nextflushed = 1;
1067 + arc4_encrypt(state, ibuf, isize - off, wptr);
1068 + olen = isize - (off - 2) + MPPE_OVHD;
1069 + (state->stats).inc_bytes += olen;
1070 + (state->stats).inc_packets++;
1071 + } else {
1072 + state->bits |= MPPE_BIT_COMP;
1073 + /* Hack warning !!! RC4 implementation which we use does
1074 + encryption "in place" - it means that input and output
1075 + buffers can be *the same* memory area. Therefore we don't
1076 + need to use a temporary buffer. But be careful - other
1077 + implementations don't have to be so nice.
1078 + I used to use ibuf as temporary buffer here, but it led
1079 + packet sniffers into error. Thanks to Wilfried Weissmann
1080 + for pointing that. */
1081 + arc4_encrypt(state, wptr, complen, wptr);
1082 + olen = complen + PPP_HDRLEN + (MPPE_OVHD / 2);
1083 + (state->stats).comp_bytes += olen;
1084 + (state->stats).comp_packets++;
1089 + /* write status bits and coherency counter into the output buffer */
1090 + wptr = obuf + PPP_HDRLEN;
1091 + wptr[0] = MPPE_CTRLHI(state);
1092 + wptr[1] = MPPE_CTRLLO(state);
1094 + state->bits = 0;
1096 + (state->stats).unc_bytes += isize;
1097 + (state->stats).unc_packets++;
1099 + return olen;
1102 +/***************************/
1103 +/*** Decompression stuff ***/
1104 +/***************************/
1105 +static inline u32 getbits(const u8 *buf, const u32 n, u32 *i, u32 *l)
1107 + static const u32 m[] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
1108 + u32 res, ol;
1110 + ol = *l;
1111 + if (*l >= n) {
1112 + *l = (*l) - n;
1113 + res = (buf[*i] & m[ol]) >> (*l);
1114 + if (*l == 0) {
1115 + *l = 8;
1116 + (*i)++;
1118 + } else {
1119 + *l = 8 - n + (*l);
1120 + res = (buf[(*i)++] & m[ol]) << 8;
1121 + res = (res | buf[*i]) >> (*l);
1124 + return res;
1127 +static inline u32 getbyte(const u8 *buf, const u32 i, const u32 l)
1129 + if (l == 8) {
1130 + return buf[i];
1131 + } else {
1132 + return (((buf[i] << 8) | buf[i+1]) >> l) & 0xff;
1136 +static inline void lamecopy(u8 *dst, u8 *src, u32 len)
1138 + while (len--)
1139 + *dst++ = *src++;
1142 +static int
1143 +mppc_decompress(struct ppp_mppe_state *state, unsigned char *ibuf,
1144 + unsigned char *obuf, int isize, int osize)
1146 + u32 olen, off, len, bits, val, sig, i, l;
1147 + u8 *history, *s;
1149 + history = state->hist + state->histptr;
1150 + olen = len = i = 0;
1151 + l = 8;
1152 + bits = isize * 8;
1153 + while (bits >= 8) {
1154 + val = getbyte(ibuf, i++, l);
1155 + if (val < 0x80) { /* literal byte < 0x80 */
1156 + if (state->histptr < 2*MPPE_HIST_LEN) {
1157 + /* copy uncompressed byte to the history */
1158 + (state->hist)[(state->histptr)++] = (u8) val;
1159 + } else {
1160 + /* buffer overflow; drop packet */
1161 + if (state->debug)
1162 + printk(KERN_ERR "%s%d: trying to write outside history "
1163 + "buffer\n", __FUNCTION__, state->unit);
1164 + return DECOMP_ERROR;
1166 + olen++;
1167 + bits -= 8;
1168 + continue;
1171 + sig = val & 0xc0;
1172 + if (sig == 0x80) { /* literal byte >= 0x80 */
1173 + if (state->histptr < 2*MPPE_HIST_LEN) {
1174 + /* copy uncompressed byte to the history */
1175 + (state->hist)[(state->histptr)++] =
1176 + (u8) (0x80|((val&0x3f)<<1)|getbits(ibuf, 1 , &i ,&l));
1177 + } else {
1178 + /* buffer overflow; drop packet */
1179 + if (state->debug)
1180 + printk(KERN_ERR "%s%d: trying to write outside history "
1181 + "buffer\n", __FUNCTION__, state->unit);
1182 + return DECOMP_ERROR;
1184 + olen++;
1185 + bits -= 9;
1186 + continue;
1189 + /* Not a literal byte so it must be an (offset,length) pair */
1190 + /* decode offset */
1191 + sig = val & 0xf0;
1192 + if (sig == 0xf0) { /* 10-bit offset; 0 <= offset < 64 */
1193 + off = (((val&0x0f)<<2)|getbits(ibuf, 2 , &i ,&l));
1194 + bits -= 10;
1195 + } else {
1196 + if (sig == 0xe0) { /* 12-bit offset; 64 <= offset < 320 */
1197 + off = ((((val&0x0f)<<4)|getbits(ibuf, 4 , &i ,&l))+64);
1198 + bits -= 12;
1199 + } else {
1200 + if ((sig&0xe0) == 0xc0) {/* 16-bit offset; 320 <= offset < 8192 */
1201 + off = ((((val&0x1f)<<8)|getbyte(ibuf, i++, l))+320);
1202 + bits -= 16;
1203 + if (off > MPPE_HIST_LEN - 1) {
1204 + if (state->debug)
1205 + printk(KERN_DEBUG "%s%d: too big offset value: %d\n",
1206 + __FUNCTION__, state->unit, off);
1207 + return DECOMP_ERROR;
1209 + } else { /* this shouldn't happen */
1210 + if (state->debug)
1211 + printk(KERN_DEBUG "%s%d: cannot decode offset value\n",
1212 + __FUNCTION__, state->unit);
1213 + return DECOMP_ERROR;
1217 + /* decode length of match */
1218 + val = getbyte(ibuf, i, l);
1219 + if ((val & 0x80) == 0x00) { /* len = 3 */
1220 + len = 3;
1221 + bits--;
1222 + getbits(ibuf, 1 , &i ,&l);
1223 + } else if ((val & 0xc0) == 0x80) { /* 4 <= len < 8 */
1224 + len = 0x04 | ((val>>4) & 0x03);
1225 + bits -= 4;
1226 + getbits(ibuf, 4 , &i ,&l);
1227 + } else if ((val & 0xe0) == 0xc0) { /* 8 <= len < 16 */
1228 + len = 0x08 | ((val>>2) & 0x07);
1229 + bits -= 6;
1230 + getbits(ibuf, 6 , &i ,&l);
1231 + } else if ((val & 0xf0) == 0xe0) { /* 16 <= len < 32 */
1232 + len = 0x10 | (val & 0x0f);
1233 + bits -= 8;
1234 + i++;
1235 + } else {
1236 + bits -= 8;
1237 + val = (val << 8) | getbyte(ibuf, ++i, l);
1238 + if ((val & 0xf800) == 0xf000) { /* 32 <= len < 64 */
1239 + len = 0x0020 | ((val >> 6) & 0x001f);
1240 + bits -= 2;
1241 + getbits(ibuf, 2 , &i ,&l);
1242 + } else if ((val & 0xfc00) == 0xf800) { /* 64 <= len < 128 */
1243 + len = 0x0040 | ((val >> 4) & 0x003f);
1244 + bits -= 4;
1245 + getbits(ibuf, 4 , &i ,&l);
1246 + } else if ((val & 0xfe00) == 0xfc00) { /* 128 <= len < 256 */
1247 + len = 0x0080 | ((val >> 2) & 0x007f);
1248 + bits -= 6;
1249 + getbits(ibuf, 6 , &i ,&l);
1250 + } else if ((val & 0xff00) == 0xfe00) { /* 256 <= len < 512 */
1251 + len = 0x0100 | (val & 0x00ff);
1252 + bits -= 8;
1253 + i++;
1254 + } else {
1255 + bits -= 8;
1256 + val = (val << 8) | getbyte(ibuf, ++i, l);
1257 + if ((val & 0xff8000) == 0xff0000) { /* 512 <= len < 1024 */
1258 + len = 0x000200 | ((val >> 6) & 0x0001ff);
1259 + bits -= 2;
1260 + getbits(ibuf, 2 , &i ,&l);
1261 + } else if ((val & 0xffc000) == 0xff8000) {/* 1024 <= len < 2048 */
1262 + len = 0x000400 | ((val >> 4) & 0x0003ff);
1263 + bits -= 4;
1264 + getbits(ibuf, 4 , &i ,&l);
1265 + } else if ((val & 0xffe000) == 0xffc000) {/* 2048 <= len < 4096 */
1266 + len = 0x000800 | ((val >> 2) & 0x0007ff);
1267 + bits -= 6;
1268 + getbits(ibuf, 6 , &i ,&l);
1269 + } else if ((val & 0xfff000) == 0xffe000) {/* 4096 <= len < 8192 */
1270 + len = 0x001000 | (val & 0x000fff);
1271 + bits -= 8;
1272 + i++;
1273 + } else { /* this shouldn't happen */
1274 + if (state->debug)
1275 + printk(KERN_DEBUG "%s%d: wrong length code: 0x%X\n",
1276 + __FUNCTION__, state->unit, val);
1277 + return DECOMP_ERROR;
1281 + s = state->hist + state->histptr;
1282 + state->histptr += len;
1283 + olen += len;
1284 + if (state->histptr < 2*MPPE_HIST_LEN) {
1285 + /* copy uncompressed bytes to the history */
1287 + /* In some cases len may be greater than off. It means that memory
1288 + * areas pointed by s and s-off overlap. I had used memmove() here
1289 + * because I thought that it acts as libc's version. Unfortunately,
1290 + * I was wrong. :-) I got strange errors sometimes. Wilfried suggested
1291 + * using of byte by byte copying here and strange errors disappeared.
1292 + */
1293 + lamecopy(s, s - off, len);
1294 + } else {
1295 + /* buffer overflow; drop packet */
1296 + if (state->debug)
1297 + printk(KERN_ERR "%s%d: trying to write outside history "
1298 + "buffer\n", __FUNCTION__, state->unit);
1299 + return DECOMP_ERROR;
1303 + /* Do PFC decompression */
1304 + len = olen;
1305 + if ((history[0] & 0x01) != 0) {
1306 + obuf[0] = 0;
1307 + obuf++;
1308 + len++;
1311 + if (len <= osize) {
1312 + /* copy uncompressed packet to the output buffer */
1313 + memcpy(obuf, history, olen);
1314 + } else {
1315 + /* buffer overflow; drop packet */
1316 + if (state->debug)
1317 + printk(KERN_ERR "%s%d: too big uncompressed packet: %d\n",
1318 + __FUNCTION__, state->unit, len + (PPP_HDRLEN / 2));
1319 + return DECOMP_ERROR;
1322 + return (int) len;
1325 +int
1326 +mppe_decompress(void *arg, unsigned char *ibuf, int isize,
1327 + unsigned char *obuf, int osize)
1329 + struct ppp_mppe_state *state = (struct ppp_mppe_state *)arg;
1330 + int seq, bits, uncomplen;
1332 + if (isize <= PPP_HDRLEN + MPPE_OVHD) {
1333 + if (state->debug) {
1334 + printk(KERN_DEBUG "%s%d: short packet (len=%d)\n", __FUNCTION__,
1335 + state->unit, isize);
1337 + return DECOMP_ERROR;
1340 + /* Get coherency counter and control bits from input buffer */
1341 + seq = MPPE_CCOUNT(ibuf);
1342 + bits = MPPE_BITS(ibuf);
1344 + if (state->stateless) {
1345 + /* RFC 3078, sec 8.1. */
1346 + mppe_increase_ccount(state);
1347 + if ((seq != state->ccount) && state->debug)
1348 + printk(KERN_DEBUG "%s%d: bad sequence number: %d, expected: %d\n",
1349 + __FUNCTION__, state->unit, seq, state->ccount);
1350 + while (seq != state->ccount)
1351 + mppe_increase_ccount(state);
1352 + } else {
1353 + /* RFC 3078, sec 8.2. */
1354 + if (state->flushexpected) { /* discard state */
1355 + if ((bits & MPPE_BIT_FLUSHED)) { /* we received expected FLUSH bit */
1356 + while (seq != state->ccount)
1357 + mppe_increase_ccount(state);
1358 + state->flushexpected = 0;
1359 + } else /* drop packet*/
1360 + return DECOMP_ERROR;
1361 + } else { /* normal state */
1362 + mppe_increase_ccount(state);
1363 + if (seq != state->ccount) {
1364 + /* Packet loss detected, enter the discard state. */
1365 + if (state->debug)
1366 + printk(KERN_DEBUG "%s%d: bad sequence number: %d, expected: %d\n",
1367 + __FUNCTION__, state->unit, seq, state->ccount);
1368 + state->flushexpected = 1;
1369 + return DECOMP_ERROR;
1372 + if (state->mppe && (bits & MPPE_BIT_FLUSHED)) {
1373 + arc4_setkey(state, state->session_key, state->keylen);
1377 + if (state->mppc && (bits & (MPPE_BIT_FLUSHED | MPPE_BIT_RESET))) {
1378 + state->histptr = MPPE_HIST_LEN;
1379 + if ((bits & MPPE_BIT_FLUSHED)) {
1380 + memset(state->hist + MPPE_HIST_LEN, 0, MPPE_HIST_LEN*sizeof(u8));
1381 + } else
1382 + if ((bits & MPPE_BIT_RESET)) {
1383 + memcpy(state->hist, state->hist + MPPE_HIST_LEN, MPPE_HIST_LEN);
1387 + /* Fill in the first part of the PPP header. The protocol field
1388 + comes from the decompressed data. */
1389 + obuf[0] = PPP_ADDRESS(ibuf);
1390 + obuf[1] = PPP_CONTROL(ibuf);
1391 + obuf += PPP_HDRLEN / 2;
1393 + if (state->mppe) { /* process encrypted packet */
1394 + if ((bits & MPPE_BIT_ENCRYPTED)) {
1395 + /* OK, packet encrypted, so decrypt it */
1396 + if (state->mppc && (bits & MPPE_BIT_COMP)) {
1397 + /* Hack warning !!! RC4 implementation which we use does
1398 + decryption "in place" - it means that input and output
1399 + buffers can be *the same* memory area. Therefore we don't
1400 + need to use a temporary buffer. But be careful - other
1401 + implementations don't have to be so nice. */
1402 + arc4_decrypt(state, ibuf + PPP_HDRLEN + (MPPE_OVHD / 2), isize -
1403 + PPP_HDRLEN - (MPPE_OVHD / 2), ibuf + PPP_HDRLEN +
1404 + (MPPE_OVHD / 2));
1405 + uncomplen = mppc_decompress(state, ibuf + PPP_HDRLEN +
1406 + (MPPE_OVHD / 2), obuf, isize -
1407 + PPP_HDRLEN - (MPPE_OVHD / 2),
1408 + osize - (PPP_HDRLEN / 2));
1409 + if (uncomplen == DECOMP_ERROR) {
1410 + state->flushexpected = 1;
1411 + return DECOMP_ERROR;
1413 + uncomplen += PPP_HDRLEN / 2;
1414 + (state->stats).comp_bytes += isize;
1415 + (state->stats).comp_packets++;
1416 + } else {
1417 + uncomplen = isize - MPPE_OVHD;
1418 + /* Decrypt the first byte in order to check if it is
1419 + compressed or uncompressed protocol field */
1420 + arc4_decrypt(state, ibuf + PPP_HDRLEN + (MPPE_OVHD / 2), 1, obuf);
1421 + /* Do PFC decompression */
1422 + if ((obuf[0] & 0x01) != 0) {
1423 + obuf[1] = obuf[0];
1424 + obuf[0] = 0;
1425 + obuf++;
1426 + uncomplen++;
1428 + /* And finally, decrypt the rest of the frame. */
1429 + arc4_decrypt(state, ibuf + PPP_HDRLEN + (MPPE_OVHD / 2) + 1,
1430 + isize - PPP_HDRLEN - (MPPE_OVHD / 2) - 1, obuf + 1);
1431 + (state->stats).inc_bytes += isize;
1432 + (state->stats).inc_packets++;
1434 + } else { /* this shouldn't happen */
1435 + if (state->debug)
1436 + printk(KERN_ERR "%s%d: encryption negotiated but not an "
1437 + "encrypted packet received\n", __FUNCTION__, state->unit);
1438 + mppe_change_key(state, 0);
1439 + state->flushexpected = 1;
1440 + return DECOMP_ERROR;
1442 + } else {
1443 + if (state->mppc) { /* no MPPE, only MPPC */
1444 + if ((bits & MPPE_BIT_COMP)) {
1445 + uncomplen = mppc_decompress(state, ibuf + PPP_HDRLEN +
1446 + (MPPE_OVHD / 2), obuf, isize -
1447 + PPP_HDRLEN - (MPPE_OVHD / 2),
1448 + osize - (PPP_HDRLEN / 2));
1449 + if (uncomplen == DECOMP_ERROR) {
1450 + state->flushexpected = 1;
1451 + return DECOMP_ERROR;
1453 + uncomplen += PPP_HDRLEN / 2;
1454 + (state->stats).comp_bytes += isize;
1455 + (state->stats).comp_packets++;
1456 + } else {
1457 + memcpy(obuf, ibuf + PPP_HDRLEN + (MPPE_OVHD / 2), isize -
1458 + PPP_HDRLEN - (MPPE_OVHD / 2));
1459 + uncomplen = isize - MPPE_OVHD;
1460 + (state->stats).inc_bytes += isize;
1461 + (state->stats).inc_packets++;
1463 + } else { /* this shouldn't happen */
1464 + if (state->debug)
1465 + printk(KERN_ERR "%s%d: error - not an MPPC or MPPE frame "
1466 + "received\n", __FUNCTION__, state->unit);
1467 + state->flushexpected = 1;
1468 + return DECOMP_ERROR;
1472 + (state->stats).unc_bytes += uncomplen;
1473 + (state->stats).unc_packets++;
1475 + return uncomplen;
1479 +/************************************************************
1480 + * Module interface table
1481 + ************************************************************/
1483 +/* These are in ppp_generic.c */
1484 +extern int ppp_register_compressor (struct compressor *cp);
1485 +extern void ppp_unregister_compressor (struct compressor *cp);
1488 + * Functions exported to ppp_generic.c.
1490 + * In case of MPPC/MPPE there is no need to process incompressible data
1491 + * because such a data is sent in MPPC/MPPE frame. Therefore the (*incomp)
1492 + * callback function isn't needed.
1493 + */
1494 +struct compressor ppp_mppe = {
1495 + CI_MPPE, /* compress_proto */
1496 + mppe_comp_alloc, /* comp_alloc */
1497 + mppe_comp_free, /* comp_free */
1498 + mppe_comp_init, /* comp_init */
1499 + mppe_comp_reset, /* comp_reset */
1500 + mppe_compress, /* compress */
1501 + mppe_stats, /* comp_stat */
1502 + mppe_decomp_alloc, /* decomp_alloc */
1503 + mppe_comp_free, /* decomp_free */
1504 + mppe_decomp_init, /* decomp_init */
1505 + mppe_decomp_reset, /* decomp_reset */
1506 + mppe_decompress, /* decompress */
1507 + NULL, /* incomp */
1508 + mppe_stats, /* decomp_stat */
1511 +/************************************************************
1512 + * Module support routines
1513 + ************************************************************/
1515 +int __init mppe_module_init(void)
1517 + int answer = ppp_register_compressor(&ppp_mppe);
1518 + if (answer == 0) {
1519 + printk(KERN_INFO "MPPE/MPPC encryption/compression module registered\n");
1521 + return answer;
1524 +void __exit mppe_module_cleanup(void)
1526 + ppp_unregister_compressor(&ppp_mppe);
1527 + printk(KERN_INFO "MPPE/MPPC encryption/compression module unregistered\n");
1530 +module_init(mppe_module_init);
1531 +module_exit(mppe_module_cleanup);
1533 +MODULE_AUTHOR("Jan Dubiec <jdx@slackware.pl>");
1534 +MODULE_DESCRIPTION("MPPE/MPPC encryption/compression module for Linux");
1535 +MODULE_LICENSE("Dual BSD/GPL");
1536 diff -ruN linux.orig/include/linux/ppp-comp.h linux/include/linux/ppp-comp.h
1537 --- linux.orig/include/linux/ppp-comp.h 1999-08-06 19:44:11.000000000 +0200
1538 +++ linux/include/linux/ppp-comp.h 2004-08-08 12:17:43.000000000 +0200
1539 @@ -1,34 +1,42 @@
1541 * ppp-comp.h - Definitions for doing PPP packet compression.
1543 - * Copyright (c) 1994 The Australian National University.
1544 - * All rights reserved.
1545 + * Copyright (c) 1984 Paul Mackerras. All rights reserved.
1547 - * Permission to use, copy, modify, and distribute this software and its
1548 - * documentation is hereby granted, provided that the above copyright
1549 - * notice appears in all copies. This software is provided without any
1550 - * warranty, express or implied. The Australian National University
1551 - * makes no representations about the suitability of this software for
1552 - * any purpose.
1554 - * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
1555 - * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
1556 - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
1557 - * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
1558 - * OF SUCH DAMAGE.
1560 - * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
1561 - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
1562 - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
1563 - * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
1564 - * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
1565 - * OR MODIFICATIONS.
1566 + * Redistribution and use in source and binary forms, with or without
1567 + * modification, are permitted provided that the following conditions
1568 + * are met:
1570 - * $Id: ppp-comp.h,v 1.6 1997/11/27 06:04:44 paulus Exp $
1571 + * 1. Redistributions of source code must retain the above copyright
1572 + * notice, this list of conditions and the following disclaimer.
1574 + * 2. Redistributions in binary form must reproduce the above copyright
1575 + * notice, this list of conditions and the following disclaimer in
1576 + * the documentation and/or other materials provided with the
1577 + * distribution.
1579 + * 3. The name(s) of the authors of this software must not be used to
1580 + * endorse or promote products derived from this software without
1581 + * prior written permission.
1583 + * 4. Redistributions of any form whatsoever must retain the following
1584 + * acknowledgment:
1585 + * "This product includes software developed by Paul Mackerras
1586 + * <paulus@samba.org>".
1588 + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
1589 + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1590 + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
1591 + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1592 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
1593 + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
1594 + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1596 + * $Id: ppp-comp.h,v 1.10 2002/12/06 09:49:15 paulus Exp $
1600 - * ==FILEVERSION 980319==
1601 + * ==FILEVERSION 20040509==
1603 * NOTE TO MAINTAINERS:
1604 * If you modify this file at all, please set the above date.
1605 @@ -78,7 +86,7 @@
1607 /* Compress a packet */
1608 int (*compress) (void *state, unsigned char *rptr,
1609 - unsigned char *obuf, int isize, int osize);
1610 + unsigned char *obuf, int isize, int osize);
1612 /* Return compression statistics */
1613 void (*comp_stat) (void *state, struct compstat *stats);
1614 @@ -99,7 +107,7 @@
1616 /* Decompress a packet. */
1617 int (*decompress) (void *state, unsigned char *ibuf, int isize,
1618 - unsigned char *obuf, int osize);
1619 + unsigned char *obuf, int osize);
1621 /* Update state for an incompressible packet received */
1622 void (*incomp) (void *state, unsigned char *ibuf, int icnt);
1623 @@ -187,6 +195,42 @@
1624 #define DEFLATE_CHK_SEQUENCE 0
1627 + * Definitions for MPPE/MPPC.
1628 + */
1630 +#define CI_MPPE 18 /* config option for MPPE */
1631 +#define CILEN_MPPE 6 /* length of config option */
1633 +#define MPPE_OVHD 4 /* MPPE overhead */
1634 +#define MPPE_MAX_KEY_LEN 16 /* largest key length (128-bit) */
1636 +#define MPPE_STATELESS 0x01 /* configuration bit H */
1637 +#define MPPE_40BIT 0x20 /* configuration bit L */
1638 +#define MPPE_56BIT 0x80 /* configuration bit M */
1639 +#define MPPE_128BIT 0x40 /* configuration bit S */
1640 +#define MPPE_MPPC 0x01 /* configuration bit C */
1643 + * Definitions for Stac LZS.
1644 + */
1646 +#define CI_LZS 17 /* config option for Stac LZS */
1647 +#define CILEN_LZS 5 /* length of config option */
1649 +#define LZS_OVHD 4 /* max. LZS overhead */
1650 +#define LZS_HIST_LEN 2048 /* LZS history size */
1651 +#define LZS_MAX_CCOUNT 0x0FFF /* max. coherency counter value */
1653 +#define LZS_MODE_NONE 0
1654 +#define LZS_MODE_LCB 1
1655 +#define LZS_MODE_CRC 2
1656 +#define LZS_MODE_SEQ 3
1657 +#define LZS_MODE_EXT 4
1659 +#define LZS_EXT_BIT_FLUSHED 0x80 /* bit A */
1660 +#define LZS_EXT_BIT_COMP 0x20 /* bit C */
1663 * Definitions for other, as yet unsupported, compression methods.