1 diff -urN linux-2.4.18.org/drivers/net/arcfour.c linux-2.4.18/drivers/net/arcfour.c
2 --- linux-2.4.18.org/drivers/net/arcfour.c Thu Jan 1 01:00:00 1970
3 +++ linux-2.4.18/drivers/net/arcfour.c Tue Apr 2 16:01:37 2002
7 + * by Frank Cusack <frank@google.com>
10 + * Implemented from the description in _Applied Cryptography_, 2nd ed.
12 + * ** Distribution ** of this software is unlimited and unrestricted.
14 + * ** Use ** of this software is almost certainly legal; however, refer
15 + * to <http://theory.lcs.mit.edu/~rivest/faq.html>.
22 + unsigned char t = b; \
28 + * Initialize arcfour from a key.
31 +arcfour_setkey(arcfour_context *context, const unsigned char *key,
35 + unsigned char K[256];
37 + context->i = context->j = 0;
39 + for (i = 0; i < 256; i++) {
41 + K[i] = key[i % keylen];
45 + for (i = 0; i < 256; i++) {
46 + j = (j + context->S[i] + K[i]) % 256;
47 + swap(context->S[i], context->S[j]);
50 + memset(K, 0, sizeof(K));
54 + * plaintext -> ciphertext (or vice versa)
57 +arcfour_encrypt(arcfour_context *context, const unsigned char *in, unsigned len,
60 + unsigned i = context->i;
61 + unsigned j = context->j;
62 + unsigned char *S = context->S;
67 + j = (j + S[i]) % 256;
69 + K = S[(S[i] + S[j]) % 256];
77 diff -urN linux-2.4.18.org/drivers/net/arcfour.h linux-2.4.18/drivers/net/arcfour.h
78 --- linux-2.4.18.org/drivers/net/arcfour.h Thu Jan 1 01:00:00 1970
79 +++ linux-2.4.18/drivers/net/arcfour.h Tue Apr 2 16:01:37 2002
89 + unsigned char S[256];
92 +extern void arcfour_setkey(arcfour_context *, const unsigned char *, unsigned);
93 +extern void arcfour_encrypt(arcfour_context *, const unsigned char *, unsigned,
95 +#define arcfour_decrypt arcfour_encrypt
97 +#endif /* _ARCFOUR_H */
98 diff -urN linux-2.4.18.org/drivers/net/ppp_mppe_compress.c linux-2.4.18/drivers/net/ppp_mppe_compress.c
99 --- linux-2.4.18.org/drivers/net/ppp_mppe_compress.c Thu Jan 1 01:00:00 1970
100 +++ linux-2.4.18/drivers/net/ppp_mppe_compress.c Tue Apr 2 16:12:48 2002
103 + * ==FILEVERSION 20020320==
105 + * ppp_mppe_compress.c - interface MPPE to the PPP code.
106 + * This version is for use with Linux kernel 2.2.19+ and 2.4.x.
108 + * By Frank Cusack <frank@google.com>.
109 + * Copyright (c) 2002 Google, Inc.
110 + * All rights reserved.
112 + * Permission to use, copy, modify, and distribute this software and its
113 + * documentation is hereby granted, provided that the above copyright
114 + * notice appears in all copies. This software is provided without any
115 + * warranty, express or implied.
119 +#include <linux/module.h>
120 +#include <linux/kernel.h>
121 +#include <linux/init.h>
122 +#include <linux/types.h>
123 +#include <linux/slab.h>
124 +#include <linux/string.h>
126 +#include <linux/ppp_defs.h>
127 +#include <linux/ppp-comp.h>
129 +#include "arcfour.h"
133 + * State for an MPPE (de)compressor.
135 +typedef struct ppp_mppe_state {
136 + unsigned char master_key[MPPE_MAX_KEY_LEN];
137 + unsigned char session_key[MPPE_MAX_KEY_LEN];
138 + arcfour_context arcfour_context; /* encryption state */
139 + unsigned keylen; /* key length in bytes */
140 + /* NB: 128-bit == 16, 40-bit == 8! */
141 + /* If we want to support 56-bit, */
142 + /* the unit has to change to bits */
143 + unsigned char bits; /* MPPE control bits */
144 + unsigned ccount; /* 12-bit coherency count (seqno) */
145 + unsigned stateful; /* stateful mode flag */
146 + int discard; /* stateful mode packet loss flag */
147 + int sanity_errors; /* take down LCP if too many */
150 + struct compstat stats;
153 +/* ppp_mppe_state.bits definitions */
154 +#define MPPE_BIT_A 0x80 /* Encryption table were (re)inititalized */
155 +#define MPPE_BIT_B 0x40 /* MPPC only (not implemented) */
156 +#define MPPE_BIT_C 0x20 /* MPPC only (not implemented) */
157 +#define MPPE_BIT_D 0x10 /* This is an encrypted frame */
159 +#define MPPE_BIT_FLUSHED MPPE_BIT_A
160 +#define MPPE_BIT_ENCRYPTED MPPE_BIT_D
162 +#define MPPE_BITS(p) ((p)[4] & 0xf0)
163 +#define MPPE_CCOUNT(p) ((((p)[4] & 0x0f) << 8) + (p)[5])
164 +#define MPPE_CCOUNT_SPACE 0x1000 /* The size of the ccount space */
167 + * MPPE overhead/packet.
168 + * Note that we use this differently than other compressors.
170 +#define MPPE_OVHD 2 /* MPPE overhead/packet */
171 +/* Max bogon factor we will tolerate */
172 +#define SANITY_MAX 1600
174 +static void GetNewKeyFromSHA __P((unsigned char *StartKey,
175 + unsigned char *SessionKey,
176 + unsigned SessionKeyLength,
177 + unsigned char *InterimKey));
178 +static void mppe_rekey __P((ppp_mppe_state *state, int));
179 +static void *mppe_alloc __P((unsigned char *options, int optlen));
180 +static void mppe_free __P((void *state));
181 +static int mppe_init __P((void *state, unsigned char *options,
182 + int optlen, int unit, int debug, const char *));
183 +static int mppe_comp_init __P((void *state, unsigned char *options,
185 + int unit, int hdrlen, int debug));
186 +static int mppe_decomp_init __P((void *state, unsigned char *options,
187 + int optlen, int unit,
188 + int hdrlen, int mru, int debug));
189 +static int mppe_compress __P((void *state, unsigned char *ibuf,
190 + unsigned char *obuf,
191 + int isize, int osize));
192 +static void mppe_incomp __P((void *state, unsigned char *ibuf, int icnt));
193 +static int mppe_decompress __P((void *state, unsigned char *ibuf,
194 + int isize, unsigned char *obuf,int osize));
195 +static void mppe_comp_reset __P((void *state));
196 +static void mppe_decomp_reset __P((void *state));
197 +static void mppe_comp_stats __P((void *state, struct compstat *stats));
201 + * Key Derivation, from RFC 3078, RFC 3079.
202 + * Equivalent to Get_Key() for MS-CHAP as described in RFC 3079.
205 +GetNewKeyFromSHA(unsigned char *MasterKey, unsigned char *SessionKey,
206 + unsigned SessionKeyLength, unsigned char *InterimKey)
209 + unsigned char Digest[SHA1_SIGNATURE_SIZE];
211 + unsigned char SHApad1[40] =
212 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
213 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
214 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
215 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
216 + unsigned char SHApad2[40] =
217 + { 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
218 + 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
219 + 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
220 + 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2 };
222 + /* assert(SessionKeyLength <= SHA1_SIGNATURE_SIZE); */
224 + SHA1_Init(&Context);
225 + SHA1_Update(&Context, MasterKey, SessionKeyLength);
226 + SHA1_Update(&Context, SHApad1, sizeof(SHApad1));
227 + SHA1_Update(&Context, SessionKey, SessionKeyLength);
228 + SHA1_Update(&Context, SHApad2, sizeof(SHApad2));
229 + SHA1_Final(Digest, &Context);
231 + memcpy(InterimKey, Digest, SessionKeyLength);
235 + * Perform the MPPE rekey algorithm, from RFC 3078, sec. 7.3.
236 + * Well, not what's written there, but rather what they meant.
239 +mppe_rekey(ppp_mppe_state *state, int initial_key)
241 + unsigned char InterimKey[MPPE_MAX_KEY_LEN];
243 + GetNewKeyFromSHA(state->master_key, state->session_key,
244 + state->keylen, InterimKey);
245 + if (!initial_key) {
246 + arcfour_setkey(&state->arcfour_context, InterimKey, state->keylen);
247 + arcfour_encrypt(&state->arcfour_context, InterimKey, state->keylen,
248 + state->session_key);
250 + memcpy(state->session_key, InterimKey, state->keylen);
252 + if (state->keylen == 8) {
254 + state->session_key[0] = 0xd1;
255 + state->session_key[1] = 0x26;
256 + state->session_key[2] = 0x9e;
258 + arcfour_setkey(&state->arcfour_context, state->session_key, state->keylen);
263 + * Allocate space for a (de)compressor.
266 +mppe_alloc(unsigned char *options, int optlen)
268 + ppp_mppe_state *state;
270 + if (optlen != CILEN_MPPE + sizeof(state->master_key)
271 + || options[0] != CI_MPPE
272 + || options[1] != CILEN_MPPE)
275 + state = (ppp_mppe_state *) kmalloc(sizeof(*state), GFP_KERNEL);
280 + memset(state, 0, sizeof(*state));
283 + memcpy(state->master_key, &options[CILEN_MPPE], sizeof(state->master_key));
284 + memcpy(state->session_key, state->master_key, sizeof(state->master_key));
286 + * We defer initial key generation until mppe_init(), as mppe_alloc()
287 + * is called frequently during negotiation.
290 + return (void *) state;
294 + * Deallocate space for a (de)compressor.
297 +mppe_free(void *arg)
299 + ppp_mppe_state *state = (ppp_mppe_state *) arg;
309 + * Initialize (de)compressor state.
312 +mppe_init(void *arg, unsigned char *options, int optlen, int unit, int debug,
313 + const char *debugstr)
315 + ppp_mppe_state *state = (ppp_mppe_state *) arg;
316 + unsigned char mppe_opts;
318 + if (optlen != CILEN_MPPE
319 + || options[0] != CI_MPPE
320 + || options[1] != CILEN_MPPE)
323 + MPPE_CI_TO_OPTS(&options[2], mppe_opts);
324 + if (mppe_opts & MPPE_OPT_128)
325 + state->keylen = 16;
326 + else if (mppe_opts & MPPE_OPT_40)
329 + printk(KERN_WARNING "%s[%d]: unknown key length\n", debugstr, unit);
332 + if (mppe_opts & MPPE_OPT_STATEFUL)
333 + state->stateful = 1;
335 + /* Generate the initial session key. */
336 + mppe_rekey(state, 1);
340 + char mkey[sizeof(state->master_key) * 3 + 1];
341 + char skey[sizeof(state->session_key) * 3 + 1];
343 + printk(KERN_DEBUG "%s[%d]: initialized with %d-bit %s mode\n", debugstr,
344 + unit, (state->keylen == 16)? 128: 40,
345 + (state->stateful)? "stateful": "stateless");
347 + for (i = 0; i < sizeof(state->master_key); i++)
348 + sprintf(mkey + i * 2, "%.2x ", state->master_key[i]);
349 + for (i = 0; i < sizeof(state->session_key); i++)
350 + sprintf(skey + i * 2, "%.2x ", state->session_key[i]);
351 + printk(KERN_DEBUG "%s[%d]: keys: master: %s initial session: %s\n",
352 + debugstr, unit, mkey, skey);
356 + * Initialize the coherency count. The initial value is not specified
357 + * in RFC 3078, but we can make a reasonable assumption that it will
358 + * start at 0. Setting it to the max here makes the comp/decomp code
359 + * do the right thing (determined through experiment).
361 + state->ccount = MPPE_CCOUNT_SPACE - 1;
364 + * Note that even though we have initialized the key table, we don't
365 + * set the FLUSHED bit. This is contrary to RFC 3078, sec. 3.1.
367 + state->bits = MPPE_BIT_ENCRYPTED;
369 + state->unit = unit;
370 + state->debug = debug;
378 +mppe_comp_init(void *arg, unsigned char *options, int optlen, int unit,
379 + int hdrlen, int debug)
382 + return mppe_init(arg, options, optlen, unit, debug, "mppe_comp_init");
386 + * We received a CCP Reset-Request (actually, we are sending a Reset-Ack),
387 + * tell the compressor to rekey. Note that we MUST NOT rekey for
388 + * every CCP Reset-Request; we only rekey on the next xmit packet.
389 + * We might get multiple CCP Reset-Requests if our CCP Reset-Ack is lost.
390 + * So, rekeying for every CCP Reset-Request is broken as the peer will not
391 + * know how many times we've rekeyed. (If we rekey and THEN get another
392 + * CCP Reset-Request, we must rekey again.)
395 +mppe_comp_reset(void *arg)
397 + ppp_mppe_state *state = (ppp_mppe_state *) arg;
399 + state->bits |= MPPE_BIT_FLUSHED;
403 + * Compress (encrypt) a packet.
404 + * It's strange to call this a compressor, since the output is always
405 + * MPPE_OVHD + 2 bytes larger than the input.
408 +mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
409 + int isize, int osize)
411 + ppp_mppe_state *state = (ppp_mppe_state *) arg;
415 + * Check that the protocol is in the range we handle.
417 + proto = PPP_PROTOCOL(ibuf);
418 + if (proto < 0x0021 || proto > 0x00fa)
421 + /* Make sure we have enough room to generate an encrypted packet. */
422 + if (osize < isize + MPPE_OVHD + 2) {
423 + /* Drop the packet if we should encrypt it, but can't. */
424 + printk(KERN_DEBUG "mppe_compress[%d]: osize too small! "
425 + "(have: %d need: %d)\n", state->unit,
426 + osize, osize + MPPE_OVHD + 2);
430 + osize = isize + MPPE_OVHD + 2;
433 + * Copy over the PPP header and set control bits.
435 + obuf[0] = PPP_ADDRESS(ibuf);
436 + obuf[1] = PPP_CONTROL(ibuf);
437 + obuf[2] = PPP_COMP >> 8; /* isize + MPPE_OVHD + 1 */
438 + obuf[3] = PPP_COMP; /* isize + MPPE_OVHD + 2 */
439 + obuf += PPP_HDRLEN;
441 + state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
442 + obuf[0] = state->ccount >> 8;
443 + obuf[1] = state->ccount & 0xff;
445 + if (!state->stateful || /* stateless mode */
446 + ((state->ccount & 0xff) == 0xff) || /* "flag" packet */
447 + (state->bits & MPPE_BIT_FLUSHED)) { /* CCP Reset-Request */
448 + /* We must rekey */
449 + if (state->debug && state->stateful)
450 + printk(KERN_DEBUG "mppe_compress[%d]: rekeying\n", state->unit);
451 + mppe_rekey(state, 0);
452 + state->bits |= MPPE_BIT_FLUSHED;
454 + obuf[0] |= state->bits;
455 + state->bits &= ~MPPE_BIT_FLUSHED; /* reset for next xmit */
458 + ibuf += 2; /* skip to proto field */
461 + /* Encrypt packet */
462 + arcfour_encrypt(&state->arcfour_context, ibuf, isize, obuf);
464 + state->stats.unc_bytes += isize;
465 + state->stats.unc_packets++;
466 + state->stats.comp_bytes += osize;
467 + state->stats.comp_packets++;
473 + * Since every frame grows by MPPE_OVHD + 2 bytes, this is always going
474 + * to look bad ... and the longer the link is up the worse it will get.
477 +mppe_comp_stats(void *arg, struct compstat *stats)
479 + ppp_mppe_state *state = (ppp_mppe_state *) arg;
481 + *stats = state->stats;
486 +mppe_decomp_init(void *arg, unsigned char *options, int optlen, int unit,
487 + int hdrlen, int mru, int debug)
490 + return mppe_init(arg, options, optlen, unit, debug, "mppe_decomp_init");
494 + * We received a CCP Reset-Ack. Just ignore it.
497 +mppe_decomp_reset(void *arg)
504 + * Decompress (decrypt) an MPPE packet.
507 +mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
510 + ppp_mppe_state *state = (ppp_mppe_state *) arg;
512 + int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED;
515 + if (isize <= PPP_HDRLEN + MPPE_OVHD) {
517 + printk(KERN_DEBUG "mppe_decompress[%d]: short pkt (%d)\n",
518 + state->unit, isize);
519 + return DECOMP_ERROR;
521 + /* Strange ... our output size is always LESS than the input size. */
522 + /* assert(osize >= isize - MPPE_OVHD - 2); */
524 + osize = isize - MPPE_OVHD - 2;
526 + ccount = MPPE_CCOUNT(ibuf);
528 + /* sanity checks -- terminate with extreme prejudice */
529 + if (!(MPPE_BITS(ibuf) & MPPE_BIT_ENCRYPTED)) {
530 + printk(KERN_DEBUG "mppe_decompress[%d]: ENCRYPTED bit not set!\n",
532 + state->sanity_errors += 100;
535 + if (!state->stateful && !flushed) {
536 + printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set in "
537 + "stateless mode!\n", state->unit);
538 + state->sanity_errors += 100;
541 + if (state->stateful && ((ccount & 0xff) == 0xff) && !flushed) {
542 + printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set on "
543 + "flag packet!\n", state->unit);
544 + state->sanity_errors += 100;
549 + if (state->sanity_errors < SANITY_MAX)
550 + return DECOMP_ERROR;
553 + * Take LCP down if the peer is sending too many bogons.
554 + * We don't want to do this for a single or just a few
555 + * instances since it could just be due to packet corruption.
557 + return DECOMP_FATALERROR;
561 + * Check the coherency count.
564 + if (!state->stateful) {
565 + /* RFC 3078, sec 8.1. Rekey for every packet. */
566 + while (state->ccount != ccount) {
567 + mppe_rekey(state, 0);
568 + state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
571 + /* RFC 3078, sec 8.2. */
572 + if (!state->discard) {
574 + state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
575 + if (ccount != state->ccount) {
577 + * (ccount > state->ccount)
578 + * Packet loss detected, enter the discard state.
579 + * Signal the peer to rekey (by sending a CCP Reset-Request).
581 + state->discard = 1;
582 + return DECOMP_ERROR;
585 + /* discard state */
587 + /* ccp.c will be silent (no additional CCP Reset-Requests). */
588 + return DECOMP_ERROR;
590 + /* Rekey for every missed "flag" packet. */
591 + while ((ccount & ~0xff) != (state->ccount & ~0xff)) {
592 + mppe_rekey(state, 0);
593 + state->ccount = (state->ccount + 256) % MPPE_CCOUNT_SPACE;
597 + state->discard = 0;
598 + state->ccount = ccount;
600 + * Another problem with RFC 3078 here. It implies that the
601 + * peer need not send a Reset-Ack packet. But RFC 1962
602 + * requires it. Hopefully, M$ does send a Reset-Ack; even
603 + * though it isn't required for MPPE synchronization, it is
604 + * required to reset CCP state.
609 + mppe_rekey(state, 0);
613 + * Fill in the first part of the PPP header. The protocol field
614 + * comes from the decrypted data.
616 + obuf[0] = PPP_ADDRESS(ibuf); /* +1 */
617 + obuf[1] = PPP_CONTROL(ibuf); /* +2 */
619 + ibuf += PPP_HDRLEN + MPPE_OVHD;
620 + isize -= PPP_HDRLEN + MPPE_OVHD; /* -6 */
623 + /* And finally, decrypt the packet. */
624 + arcfour_decrypt(&state->arcfour_context, ibuf, isize, obuf);
626 + state->stats.unc_bytes += osize;
627 + state->stats.unc_packets++;
628 + state->stats.comp_bytes += isize;
629 + state->stats.comp_packets++;
631 + /* good packet credit */
632 + state->sanity_errors >>= 1;
638 + * Incompressible data has arrived (this should never happen!).
639 + * We should probably drop the link if the protocol is in the range
640 + * of what should be encrypted. At the least, we should drop this
641 + * packet. (How to do this?)
644 +mppe_incomp(void *arg, unsigned char *ibuf, int icnt)
646 + ppp_mppe_state *state = (ppp_mppe_state *) arg;
648 + if (state->debug &&
649 + (PPP_PROTOCOL(ibuf) >= 0x0021 && PPP_PROTOCOL(ibuf) <= 0x00fa))
650 + printk(KERN_DEBUG "mppe_incomp[%d]: incompressible (unencrypted) data! "
651 + "(proto %04x)\n", state->unit, PPP_PROTOCOL(ibuf));
653 + state->stats.inc_bytes += icnt;
654 + state->stats.inc_packets++;
655 + state->stats.unc_bytes += icnt;
656 + state->stats.unc_packets++;
659 +/*************************************************************
660 + * Module interface table
661 + *************************************************************/
663 +/* These are in ppp.c (2.2.x) or ppp_generic.c (2.4.x) */
664 +extern int ppp_register_compressor (struct compressor *cp);
665 +extern void ppp_unregister_compressor (struct compressor *cp);
668 + * Procedures exported to if_ppp.c.
670 +struct compressor ppp_mppe = {
671 + CI_MPPE, /* compress_proto */
672 + mppe_alloc, /* comp_alloc */
673 + mppe_free, /* comp_free */
674 + mppe_comp_init, /* comp_init */
675 + mppe_comp_reset, /* comp_reset */
676 + mppe_compress, /* compress */
677 + mppe_comp_stats, /* comp_stat */
678 + mppe_alloc, /* decomp_alloc */
679 + mppe_free, /* decomp_free */
680 + mppe_decomp_init, /* decomp_init */
681 + mppe_decomp_reset, /* decomp_reset */
682 + mppe_decompress, /* decompress */
683 + mppe_incomp, /* incomp */
684 + mppe_comp_stats, /* decomp_stat */
687 +/* 2.2 compatibility defines */
694 +#ifndef MODULE_LICENSE
695 +#define MODULE_LICENSE(license)
701 + int answer = ppp_register_compressor(&ppp_mppe);
704 + printk(KERN_INFO "PPP MPPE Compression module registered\n");
709 +ppp_mppe_cleanup(void)
711 + ppp_unregister_compressor(&ppp_mppe);
714 +module_init(ppp_mppe_init);
715 +module_exit(ppp_mppe_cleanup);
716 +MODULE_LICENSE("BSD without advertisement clause");
717 diff -urN linux-2.4.18.org/drivers/net/sha1.c linux-2.4.18/drivers/net/sha1.c
718 --- linux-2.4.18.org/drivers/net/sha1.c Thu Jan 1 01:00:00 1970
719 +++ linux-2.4.18/drivers/net/sha1.c Tue Apr 2 16:01:37 2002
722 + * ftp://ftp.funet.fi/pub/crypt/hash/sha/sha1.c
725 + * By Steve Reid <steve@edmweb.com>
726 + * 100% Public Domain
728 + * Test Vectors (from FIPS PUB 180-1)
730 + * A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
731 + * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
732 + * 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
733 + * A million repetitions of "a"
734 + * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
737 +/* #define SHA1HANDSOFF * Copies data before messing with it. */
739 +#if defined(__linux__)
740 +#include <asm/byteorder.h>
741 +#include <linux/string.h>
742 +#else if defined(__solaris__)
743 +#include <sys/isa_defs.h>
744 +#include <sys/ddi.h>
745 +#include <sys/sunddi.h>
746 +#define memcpy(d, s, c) bcopy(s, d, c)
747 +#define memset(d, b, c) bzero(d, c)
752 +static void SHA1_Transform(unsigned long[5], const unsigned char[64]);
754 +#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
756 +/* blk0() and blk() perform the initial expand. */
757 +/* I got the idea of expanding during the round function from SSLeay */
758 +#if defined(__LITTLE_ENDIAN) || defined(_LITTLE_ENDIAN)
759 +#define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
760 + |(rol(block->l[i],8)&0x00FF00FF))
761 +#elif defined(__BIG_ENDIAN) || defined(_BIG_ENDIAN)
762 +#define blk0(i) block->l[i]
764 +#error Endianness not defined
766 +#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
767 + ^block->l[(i+2)&15]^block->l[i&15],1))
769 +/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
770 +#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
771 +#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
772 +#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
773 +#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
774 +#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
777 +/* Hash a single 512-bit block. This is the core of the algorithm. */
780 +SHA1_Transform(unsigned long state[5], const unsigned char buffer[64])
782 + unsigned long a, b, c, d, e;
784 + unsigned char c[64];
785 + unsigned long l[16];
787 + CHAR64LONG16 *block;
790 + static unsigned char workspace[64];
791 + block = (CHAR64LONG16 *) workspace;
792 + memcpy(block, buffer, 64);
794 + block = (CHAR64LONG16 *) buffer;
796 + /* Copy context->state[] to working vars */
802 + /* 4 rounds of 20 operations each. Loop unrolled. */
803 + R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
804 + R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
805 + R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
806 + R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
807 + R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
808 + R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
809 + R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
810 + R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
811 + R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
812 + R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
813 + R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
814 + R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
815 + R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
816 + R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
817 + R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
818 + R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
819 + R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
820 + R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
821 + R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
822 + R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
823 + /* Add the working vars back into context.state[] */
829 + /* Wipe variables */
830 + a = b = c = d = e = 0;
834 +/* SHA1Init - Initialize new context */
837 +SHA1_Init(SHA1_CTX *context)
839 + /* SHA1 initialization constants */
840 + context->state[0] = 0x67452301;
841 + context->state[1] = 0xEFCDAB89;
842 + context->state[2] = 0x98BADCFE;
843 + context->state[3] = 0x10325476;
844 + context->state[4] = 0xC3D2E1F0;
845 + context->count[0] = context->count[1] = 0;
849 +/* Run your data through this. */
852 +SHA1_Update(SHA1_CTX *context, const unsigned char *data, unsigned int len)
856 + j = (context->count[0] >> 3) & 63;
857 + if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++;
858 + context->count[1] += (len >> 29);
859 + if ((j + len) > 63) {
860 + memcpy(&context->buffer[j], data, (i = 64-j));
861 + SHA1_Transform(context->state, context->buffer);
862 + for ( ; i + 63 < len; i += 64) {
863 + SHA1_Transform(context->state, &data[i]);
870 + memcpy(&context->buffer[j], &data[i], len - i);
874 +/* Add padding and return the message digest. */
877 +SHA1_Final(unsigned char digest[20], SHA1_CTX *context)
879 + unsigned long i, j;
880 + unsigned char finalcount[8];
882 + for (i = 0; i < 8; i++) {
883 + finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
884 + >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
886 + SHA1_Update(context, (unsigned char *) "\200", 1);
887 + while ((context->count[0] & 504) != 448) {
888 + SHA1_Update(context, (unsigned char *) "\0", 1);
890 + SHA1_Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
891 + for (i = 0; i < 20; i++) {
892 + digest[i] = (unsigned char)
893 + ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
895 + /* Wipe variables */
897 + memset(context->buffer, 0, 64);
898 + memset(context->state, 0, 20);
899 + memset(context->count, 0, 8);
900 + memset(&finalcount, 0, 8);
901 +#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */
902 + SHA1Transform(context->state, context->buffer);
906 diff -urN linux-2.4.18.org/drivers/net/sha1.h linux-2.4.18/drivers/net/sha1.h
907 --- linux-2.4.18.org/drivers/net/sha1.h Thu Jan 1 01:00:00 1970
908 +++ linux-2.4.18/drivers/net/sha1.h Tue Apr 2 16:01:37 2002
916 + unsigned long state[5];
917 + unsigned long count[2];
918 + unsigned char buffer[64];
921 +#define SHA1_SIGNATURE_SIZE 20
923 +extern void SHA1_Init(SHA1_CTX *);
924 +extern void SHA1_Update(SHA1_CTX *, const unsigned char *, unsigned int);
925 +extern void SHA1_Final(unsigned char[SHA1_SIGNATURE_SIZE], SHA1_CTX *);
927 +#endif /* _SHA1_H */
928 --- linux/include/linux/ppp-comp.h.orig Fri Aug 6 10:44:11 1999
929 +++ linux/include/linux/ppp-comp.h Mon Mar 25 09:11:33 2002
930 @@ -187,6 +187,100 @@
931 #define DEFLATE_CHK_SEQUENCE 0
934 + * Definitions for MPPE.
937 +#define CI_MPPE 18 /* config option for MPPE */
938 +#define CILEN_MPPE 6 /* length of config option */
940 +#define MPPE_PAD 4 /* MPPE growth per frame */
941 +#define MPPE_MAX_KEY_LEN 16 /* largest key length (128-bit) */
943 +/* option bits for ccp_options.mppe */
944 +#define MPPE_OPT_40 0x01 /* 40 bit */
945 +#define MPPE_OPT_128 0x02 /* 128 bit */
946 +#define MPPE_OPT_STATEFUL 0x04 /* stateful mode */
947 +/* unsupported opts */
948 +#define MPPE_OPT_56 0x08 /* 56 bit */
949 +#define MPPE_OPT_MPPC 0x10 /* MPPC compression */
950 +#define MPPE_OPT_D 0x20 /* Unknown */
951 +#define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D)
952 +#define MPPE_OPT_UNKNOWN 0x40 /* Bits !defined in RFC 3078 were set */
955 + * This is not nice ... the alternative is a bitfield struct though.
956 + * And unfortunately, we cannot share the same bits for the option
957 + * names above since C and H are the same bit. We could do a u_int32
958 + * but then we have to do a htonl() all the time and/or we still need
959 + * to know which octet is which.
961 +#define MPPE_C_BIT 0x01 /* MPPC */
962 +#define MPPE_D_BIT 0x10 /* Obsolete, usage unknown */
963 +#define MPPE_L_BIT 0x20 /* 40-bit */
964 +#define MPPE_S_BIT 0x40 /* 128-bit */
965 +#define MPPE_M_BIT 0x80 /* 56-bit, not supported */
966 +#define MPPE_H_BIT 0x01 /* Stateless (in a different byte) */
968 +/* Does not include H bit; used for least significant octet only. */
969 +#define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT)
971 +/* Build a CI from mppe opts (see RFC 3078) */
972 +#define MPPE_OPTS_TO_CI(opts, ci) \
974 + u_char *ptr = ci; /* u_char[4] */ \
977 + if (opts & MPPE_OPT_STATEFUL) \
980 + *ptr++ = MPPE_H_BIT; \
986 + if (opts & MPPE_OPT_128) \
987 + *ptr |= MPPE_S_BIT; \
988 + if (opts & MPPE_OPT_40) \
989 + *ptr |= MPPE_L_BIT; \
990 + /* M,D,C bits not supported */ \
991 + } while (/* CONSTCOND */ 0)
993 +/* The reverse of the above */
994 +#define MPPE_CI_TO_OPTS(ci, opts) \
996 + u_char *ptr = ci; /* u_char[4] */ \
1001 + if (!(ptr[0] & MPPE_H_BIT)) \
1002 + opts |= MPPE_OPT_STATEFUL; \
1005 + if (ptr[3] & MPPE_S_BIT) \
1006 + opts |= MPPE_OPT_128; \
1007 + if (ptr[3] & MPPE_L_BIT) \
1008 + opts |= MPPE_OPT_40; \
1010 + /* M,D,C bits */ \
1011 + if (ptr[3] & MPPE_M_BIT) \
1012 + opts |= MPPE_OPT_56; \
1013 + if (ptr[3] & MPPE_D_BIT) \
1014 + opts |= MPPE_OPT_D; \
1015 + if (ptr[3] & MPPE_C_BIT) \
1016 + opts |= MPPE_OPT_MPPC; \
1018 + /* Other bits */ \
1019 + if (ptr[0] & ~MPPE_H_BIT) \
1020 + opts |= MPPE_OPT_UNKNOWN; \
1021 + if (ptr[1] || ptr[2]) \
1022 + opts |= MPPE_OPT_UNKNOWN; \
1023 + if (ptr[3] & ~MPPE_ALL_BITS) \
1024 + opts |= MPPE_OPT_UNKNOWN; \
1025 + } while (/* CONSTCOND */ 0)
1028 * Definitions for other, as yet unsupported, compression methods.
1031 --- linux/drivers/net/Config.in.orig Mon Mar 25 09:07:26 2002
1032 +++ linux/drivers/net/Config.in Mon Mar 25 11:18:03 2002
1034 dep_tristate ' PPP support for sync tty ports' CONFIG_PPP_SYNC_TTY $CONFIG_PPP
1035 dep_tristate ' PPP Deflate compression' CONFIG_PPP_DEFLATE $CONFIG_PPP
1036 dep_tristate ' PPP BSD-Compress compression' CONFIG_PPP_BSDCOMP $CONFIG_PPP
1037 + dep_tristate ' PPP MPPE compression (encryption)' CONFIG_PPP_MPPE $CONFIG_PPP
1038 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
1039 dep_tristate ' PPP over Ethernet (EXPERIMENTAL)' CONFIG_PPPOE $CONFIG_PPP
1041 --- linux/drivers/net/Makefile.orig Mon Mar 25 09:07:26 2002
1042 +++ linux/drivers/net/Makefile Mon Mar 25 11:58:11 2002
1044 export-objs := 8390.o arlan.o aironet4500_core.o aironet4500_card.o \
1045 ppp_async.o ppp_generic.o slhc.o pppox.o auto_irq.o \
1047 -list-multi := rcpci.o
1048 +list-multi := rcpci.o ppp_mppe.o
1049 rcpci-objs := rcpci45.o rclanmtl.o
1050 +ppp_mppe-objs := ppp_mppe_compress.o sha1.o arcfour.o
1052 ifeq ($(CONFIG_TULIP),y)
1053 obj-y += tulip/tulip.o
1054 @@ -139,6 +140,14 @@
1055 obj-$(CONFIG_PPP_BSDCOMP) += bsd_comp.o
1056 obj-$(CONFIG_PPPOE) += pppox.o pppoe.o
1058 +ifeq ($(CONFIG_PPP_MPPE),y)
1059 + obj-y += $(ppp_mppe-objs)
1061 + ifeq ($(CONFIG_PPP_MPPE),m)
1062 + obj-m += ppp_mppe.o
1066 obj-$(CONFIG_SLIP) += slip.o
1067 ifeq ($(CONFIG_SLIP_COMPRESSED),y)
1068 obj-$(CONFIG_SLIP) += slhc.o
1070 rcpci.o: $(rcpci-objs)
1071 $(LD) -r -o $@ $(rcpci-objs)
1073 +ppp_mppe.o: $(ppp_mppe-objs)
1074 + $(LD) -r -o $@ $(ppp_mppe-objs)
1075 --- linux/drivers/net/ppp_generic.c.orig Mon Feb 25 11:37:59 2002
1076 +++ linux/drivers/net/ppp_generic.c Mon Mar 25 10:19:53 2002
1077 @@ -1006,8 +1006,15 @@
1078 /* try to do packet compression */
1079 if ((ppp->xstate & SC_COMP_RUN) && ppp->xc_state != 0
1080 && proto != PPP_LCP && proto != PPP_CCP) {
1081 - new_skb = alloc_skb(ppp->dev->mtu + ppp->dev->hard_header_len,
1083 + int new_skb_size = ppp->dev->mtu + ppp->dev->hard_header_len;
1084 + int compressor_skb_size = ppp->dev->mtu + PPP_HDRLEN;
1086 + if (ppp->xcomp->compress_proto == CI_MPPE) {
1087 + /* CCP [must have] reduced MTU by MPPE_PAD. */
1088 + new_skb_size += MPPE_PAD;
1089 + compressor_skb_size += MPPE_PAD;
1091 + new_skb = alloc_skb(new_skb_size, GFP_ATOMIC);
1093 printk(KERN_ERR "PPP: no memory (comp pkt)\n");
1095 @@ -1019,15 +1026,27 @@
1096 /* compressor still expects A/C bytes in hdr */
1097 len = ppp->xcomp->compress(ppp->xc_state, skb->data - 2,
1098 new_skb->data, skb->len + 2,
1099 - ppp->dev->mtu + PPP_HDRLEN);
1100 + compressor_skb_size);
1101 if (len > 0 && (ppp->flags & SC_CCP_UP)) {
1105 skb_pull(skb, 2); /* pull off A/C bytes */
1107 + } else if (len == 0) {
1108 /* didn't compress, or CCP not up yet */
1113 + * MPPE requires that we do not send unencrypted
1114 + * frames. The compressor will return -1 if we
1115 + * should drop the frame. We cannot simply test
1116 + * the compress_proto because MPPE and MPPC share
1117 + * the same number.
1119 + printk(KERN_ERR "ppp: compressor dropped pkt\n");
1120 + kfree_skb(new_skb);
1125 @@ -1515,7 +1534,7 @@
1128 if (proto == PPP_COMP) {
1129 - ns = dev_alloc_skb(ppp->mru + PPP_HDRLEN);
1130 + ns = dev_alloc_skb(ppp->mru + 128 + PPP_HDRLEN);
1132 printk(KERN_ERR "ppp_decompress_frame: no memory\n");