ppp_mppe.c 19 KB

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