47 #include <linux/module.h>
48 #include <linux/kernel.h>
50 #include <linux/types.h>
51 #include <linux/slab.h>
52 #include <linux/string.h>
55 #include <linux/ppp_defs.h>
56 #include <linux/ppp-comp.h>
58 #include <asm/unaligned.h>
63 MODULE_DESCRIPTION(
"Point-to-Point Protocol Microsoft Point-to-Point Encryption support");
71 sg_set_buf(sg, address, length);
75 #define SHA1_PAD_SIZE 40
88 static inline void sha_pad_init(
struct sha_pad *shapad)
118 #define MPPE_BIT_A 0x80
119 #define MPPE_BIT_B 0x40
120 #define MPPE_BIT_C 0x20
121 #define MPPE_BIT_D 0x10
123 #define MPPE_BIT_FLUSHED MPPE_BIT_A
124 #define MPPE_BIT_ENCRYPTED MPPE_BIT_D
126 #define MPPE_BITS(p) ((p)[4] & 0xf0)
127 #define MPPE_CCOUNT(p) ((((p)[4] & 0x0f) << 8) + (p)[5])
128 #define MPPE_CCOUNT_SPACE 0x1000
131 #define SANITY_MAX 1600
146 nbytes += setup_sg(&sg[1], sha_pad->
sha_pad1,
149 nbytes += setup_sg(&sg[3], sha_pad->
sha_pad2,
155 crypto_hash_digest(&desc, sg, nbytes, state->
sha1_digest);
167 get_new_key_from_sha(state);
175 if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
194 static void *mppe_alloc(
unsigned char *
options,
int optlen)
197 unsigned int digestsize;
209 if (IS_ERR(state->
arc4)) {
215 if (IS_ERR(state->
sha1)) {
220 digestsize = crypto_hash_digestsize(state->
sha1);
239 return (
void *)
state;
245 crypto_free_hash(state->
sha1);
247 crypto_free_blkcipher(state->
arc4);
256 static void mppe_free(
void *
arg)
263 crypto_free_hash(state->
sha1);
265 crypto_free_blkcipher(state->
arc4);
274 mppe_init(
void *arg,
unsigned char *options,
int optlen,
int unit,
int debug,
275 const char *debugstr)
278 unsigned char mppe_opts;
298 mppe_rekey(state, 1);
306 debugstr, unit, (state->
keylen == 16) ? 128 : 40,
307 (state->
stateful) ?
"stateful" :
"stateless");
309 for (i = 0; i <
sizeof(state->
master_key); i++)
314 "%s[%d]: keys: master: %s initial session: %s\n",
315 debugstr, unit,
mkey, skey);
339 mppe_comp_init(
void *arg,
unsigned char *options,
int optlen,
int unit,
343 return mppe_init(arg, options, optlen, unit, debug,
"mppe_comp_init");
355 static void mppe_comp_reset(
void *arg)
368 mppe_compress(
void *arg,
unsigned char *ibuf,
unsigned char *obuf,
369 int isize,
int osize)
387 "(have: %d need: %d)\n", state->
unit,
399 put_unaligned_be16(
PPP_COMP, obuf + 2);
403 if (state->
debug >= 7)
406 put_unaligned_be16(state->
ccount, obuf);
409 ((state->
ccount & 0xff) == 0xff) ||
415 mppe_rekey(state, 0);
418 obuf[0] |= state->
bits;
428 setup_sg(sg_in, ibuf, isize);
429 setup_sg(sg_out, obuf, osize);
430 if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in, isize) != 0) {
435 state->
stats.unc_bytes += isize;
436 state->
stats.unc_packets++;
437 state->
stats.comp_bytes += osize;
438 state->
stats.comp_packets++;
447 static void mppe_comp_stats(
void *arg,
struct compstat *
stats)
451 *stats = state->
stats;
455 mppe_decomp_init(
void *arg,
unsigned char *options,
int optlen,
int unit,
456 int hdrlen,
int mru,
int debug)
459 return mppe_init(arg, options, optlen, unit, debug,
"mppe_decomp_init");
465 static void mppe_decomp_reset(
void *arg)
475 mppe_decompress(
void *arg,
unsigned char *ibuf,
int isize,
unsigned char *obuf,
488 "mppe_decompress[%d]: short pkt (%d)\n",
499 if (osize < isize - MPPE_OVHD - 1) {
501 "(have: %d need: %d)\n", state->
unit,
502 osize, isize - MPPE_OVHD - 1);
505 osize = isize - MPPE_OVHD - 2;
508 if (state->
debug >= 7)
510 state->
unit, ccount);
515 "mppe_decompress[%d]: ENCRYPTED bit not set!\n",
522 "stateless mode!\n", state->
unit);
526 if (state->
stateful && ((ccount & 0xff) == 0xff) && !flushed) {
528 "flag packet!\n", state->
unit);
551 while (state->
ccount != ccount) {
552 mppe_rekey(state, 0);
560 if (ccount != state->
ccount) {
576 while ((ccount & ~0xff) !=
577 (state->
ccount & ~0xff)) {
578 mppe_rekey(state, 0);
597 mppe_rekey(state, 0);
617 setup_sg(sg_in, ibuf, 1);
618 setup_sg(sg_out, obuf, 1);
619 if (crypto_blkcipher_decrypt(&desc, sg_out, sg_in, 1) != 0) {
629 if ((obuf[0] & 0x01) != 0) {
637 setup_sg(sg_in, ibuf + 1, isize - 1);
638 setup_sg(sg_out, obuf + 1, osize - 1);
639 if (crypto_blkcipher_decrypt(&desc, sg_out, sg_in, isize - 1)) {
644 state->
stats.unc_bytes += osize;
645 state->
stats.unc_packets++;
646 state->
stats.comp_bytes += isize;
647 state->
stats.comp_packets++;
661 static void mppe_incomp(
void *arg,
unsigned char *ibuf,
int icnt)
668 "mppe_incomp[%d]: incompressible (unencrypted) data! "
672 state->
stats.inc_packets++;
674 state->
stats.unc_packets++;
686 .comp_alloc = mppe_alloc,
687 .comp_free = mppe_free,
688 .comp_init = mppe_comp_init,
689 .comp_reset = mppe_comp_reset,
690 .compress = mppe_compress,
691 .comp_stat = mppe_comp_stats,
692 .decomp_alloc = mppe_alloc,
693 .decomp_free = mppe_free,
694 .decomp_init = mppe_decomp_init,
695 .decomp_reset = mppe_decomp_reset,
696 .decompress = mppe_decompress,
697 .incomp = mppe_incomp,
698 .decomp_stat = mppe_comp_stats,
711 static int __init ppp_mppe_init(
void)
721 sha_pad_init(sha_pad);
733 static void __exit ppp_mppe_cleanup(
void)