1*10465441SEvalZero /* 2*10465441SEvalZero * mppe.h - Definitions for MPPE 3*10465441SEvalZero * 4*10465441SEvalZero * Copyright (c) 2008 Paul Mackerras. All rights reserved. 5*10465441SEvalZero * 6*10465441SEvalZero * Redistribution and use in source and binary forms, with or without 7*10465441SEvalZero * modification, are permitted provided that the following conditions 8*10465441SEvalZero * are met: 9*10465441SEvalZero * 10*10465441SEvalZero * 1. Redistributions of source code must retain the above copyright 11*10465441SEvalZero * notice, this list of conditions and the following disclaimer. 12*10465441SEvalZero * 13*10465441SEvalZero * 2. Redistributions in binary form must reproduce the above copyright 14*10465441SEvalZero * notice, this list of conditions and the following disclaimer in 15*10465441SEvalZero * the documentation and/or other materials provided with the 16*10465441SEvalZero * distribution. 17*10465441SEvalZero * 18*10465441SEvalZero * 3. The name(s) of the authors of this software must not be used to 19*10465441SEvalZero * endorse or promote products derived from this software without 20*10465441SEvalZero * prior written permission. 21*10465441SEvalZero * 22*10465441SEvalZero * 4. Redistributions of any form whatsoever must retain the following 23*10465441SEvalZero * acknowledgment: 24*10465441SEvalZero * "This product includes software developed by Paul Mackerras 25*10465441SEvalZero * <[email protected]>". 26*10465441SEvalZero * 27*10465441SEvalZero * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO 28*10465441SEvalZero * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 29*10465441SEvalZero * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 30*10465441SEvalZero * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 31*10465441SEvalZero * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 32*10465441SEvalZero * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 33*10465441SEvalZero * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 34*10465441SEvalZero */ 35*10465441SEvalZero 36*10465441SEvalZero #include "netif/ppp/ppp_opts.h" 37*10465441SEvalZero #if PPP_SUPPORT && MPPE_SUPPORT /* don't build if not configured for use in lwipopts.h */ 38*10465441SEvalZero 39*10465441SEvalZero #ifndef MPPE_H 40*10465441SEvalZero #define MPPE_H 41*10465441SEvalZero 42*10465441SEvalZero #include "netif/ppp/pppcrypt.h" 43*10465441SEvalZero 44*10465441SEvalZero #define MPPE_PAD 4 /* MPPE growth per frame */ 45*10465441SEvalZero #define MPPE_MAX_KEY_LEN 16 /* largest key length (128-bit) */ 46*10465441SEvalZero 47*10465441SEvalZero /* option bits for ccp_options.mppe */ 48*10465441SEvalZero #define MPPE_OPT_40 0x01 /* 40 bit */ 49*10465441SEvalZero #define MPPE_OPT_128 0x02 /* 128 bit */ 50*10465441SEvalZero #define MPPE_OPT_STATEFUL 0x04 /* stateful mode */ 51*10465441SEvalZero /* unsupported opts */ 52*10465441SEvalZero #define MPPE_OPT_56 0x08 /* 56 bit */ 53*10465441SEvalZero #define MPPE_OPT_MPPC 0x10 /* MPPC compression */ 54*10465441SEvalZero #define MPPE_OPT_D 0x20 /* Unknown */ 55*10465441SEvalZero #define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D) 56*10465441SEvalZero #define MPPE_OPT_UNKNOWN 0x40 /* Bits !defined in RFC 3078 were set */ 57*10465441SEvalZero 58*10465441SEvalZero /* 59*10465441SEvalZero * This is not nice ... the alternative is a bitfield struct though. 60*10465441SEvalZero * And unfortunately, we cannot share the same bits for the option 61*10465441SEvalZero * names above since C and H are the same bit. We could do a u_int32 62*10465441SEvalZero * but then we have to do a lwip_htonl() all the time and/or we still need 63*10465441SEvalZero * to know which octet is which. 64*10465441SEvalZero */ 65*10465441SEvalZero #define MPPE_C_BIT 0x01 /* MPPC */ 66*10465441SEvalZero #define MPPE_D_BIT 0x10 /* Obsolete, usage unknown */ 67*10465441SEvalZero #define MPPE_L_BIT 0x20 /* 40-bit */ 68*10465441SEvalZero #define MPPE_S_BIT 0x40 /* 128-bit */ 69*10465441SEvalZero #define MPPE_M_BIT 0x80 /* 56-bit, not supported */ 70*10465441SEvalZero #define MPPE_H_BIT 0x01 /* Stateless (in a different byte) */ 71*10465441SEvalZero 72*10465441SEvalZero /* Does not include H bit; used for least significant octet only. */ 73*10465441SEvalZero #define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT) 74*10465441SEvalZero 75*10465441SEvalZero /* Build a CI from mppe opts (see RFC 3078) */ 76*10465441SEvalZero #define MPPE_OPTS_TO_CI(opts, ci) \ 77*10465441SEvalZero do { \ 78*10465441SEvalZero u_char *ptr = ci; /* u_char[4] */ \ 79*10465441SEvalZero \ 80*10465441SEvalZero /* H bit */ \ 81*10465441SEvalZero if (opts & MPPE_OPT_STATEFUL) \ 82*10465441SEvalZero *ptr++ = 0x0; \ 83*10465441SEvalZero else \ 84*10465441SEvalZero *ptr++ = MPPE_H_BIT; \ 85*10465441SEvalZero *ptr++ = 0; \ 86*10465441SEvalZero *ptr++ = 0; \ 87*10465441SEvalZero \ 88*10465441SEvalZero /* S,L bits */ \ 89*10465441SEvalZero *ptr = 0; \ 90*10465441SEvalZero if (opts & MPPE_OPT_128) \ 91*10465441SEvalZero *ptr |= MPPE_S_BIT; \ 92*10465441SEvalZero if (opts & MPPE_OPT_40) \ 93*10465441SEvalZero *ptr |= MPPE_L_BIT; \ 94*10465441SEvalZero /* M,D,C bits not supported */ \ 95*10465441SEvalZero } while (/* CONSTCOND */ 0) 96*10465441SEvalZero 97*10465441SEvalZero /* The reverse of the above */ 98*10465441SEvalZero #define MPPE_CI_TO_OPTS(ci, opts) \ 99*10465441SEvalZero do { \ 100*10465441SEvalZero const u_char *ptr = ci; /* u_char[4] */ \ 101*10465441SEvalZero \ 102*10465441SEvalZero opts = 0; \ 103*10465441SEvalZero \ 104*10465441SEvalZero /* H bit */ \ 105*10465441SEvalZero if (!(ptr[0] & MPPE_H_BIT)) \ 106*10465441SEvalZero opts |= MPPE_OPT_STATEFUL; \ 107*10465441SEvalZero \ 108*10465441SEvalZero /* S,L bits */ \ 109*10465441SEvalZero if (ptr[3] & MPPE_S_BIT) \ 110*10465441SEvalZero opts |= MPPE_OPT_128; \ 111*10465441SEvalZero if (ptr[3] & MPPE_L_BIT) \ 112*10465441SEvalZero opts |= MPPE_OPT_40; \ 113*10465441SEvalZero \ 114*10465441SEvalZero /* M,D,C bits */ \ 115*10465441SEvalZero if (ptr[3] & MPPE_M_BIT) \ 116*10465441SEvalZero opts |= MPPE_OPT_56; \ 117*10465441SEvalZero if (ptr[3] & MPPE_D_BIT) \ 118*10465441SEvalZero opts |= MPPE_OPT_D; \ 119*10465441SEvalZero if (ptr[3] & MPPE_C_BIT) \ 120*10465441SEvalZero opts |= MPPE_OPT_MPPC; \ 121*10465441SEvalZero \ 122*10465441SEvalZero /* Other bits */ \ 123*10465441SEvalZero if (ptr[0] & ~MPPE_H_BIT) \ 124*10465441SEvalZero opts |= MPPE_OPT_UNKNOWN; \ 125*10465441SEvalZero if (ptr[1] || ptr[2]) \ 126*10465441SEvalZero opts |= MPPE_OPT_UNKNOWN; \ 127*10465441SEvalZero if (ptr[3] & ~MPPE_ALL_BITS) \ 128*10465441SEvalZero opts |= MPPE_OPT_UNKNOWN; \ 129*10465441SEvalZero } while (/* CONSTCOND */ 0) 130*10465441SEvalZero 131*10465441SEvalZero /* Shared MPPE padding between MSCHAP and MPPE */ 132*10465441SEvalZero #define SHA1_PAD_SIZE 40 133*10465441SEvalZero 134*10465441SEvalZero static const u8_t mppe_sha1_pad1[SHA1_PAD_SIZE] = { 135*10465441SEvalZero 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 136*10465441SEvalZero 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 137*10465441SEvalZero 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 138*10465441SEvalZero 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 139*10465441SEvalZero }; 140*10465441SEvalZero static const u8_t mppe_sha1_pad2[SHA1_PAD_SIZE] = { 141*10465441SEvalZero 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 142*10465441SEvalZero 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 143*10465441SEvalZero 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 144*10465441SEvalZero 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2 145*10465441SEvalZero }; 146*10465441SEvalZero 147*10465441SEvalZero /* 148*10465441SEvalZero * State for an MPPE (de)compressor. 149*10465441SEvalZero */ 150*10465441SEvalZero typedef struct ppp_mppe_state { 151*10465441SEvalZero lwip_arc4_context arc4; 152*10465441SEvalZero u8_t master_key[MPPE_MAX_KEY_LEN]; 153*10465441SEvalZero u8_t session_key[MPPE_MAX_KEY_LEN]; 154*10465441SEvalZero u8_t keylen; /* key length in bytes */ 155*10465441SEvalZero /* NB: 128-bit == 16, 40-bit == 8! 156*10465441SEvalZero * If we want to support 56-bit, the unit has to change to bits 157*10465441SEvalZero */ 158*10465441SEvalZero u8_t bits; /* MPPE control bits */ 159*10465441SEvalZero u16_t ccount; /* 12-bit coherency count (seqno) */ 160*10465441SEvalZero u16_t sanity_errors; /* take down LCP if too many */ 161*10465441SEvalZero unsigned int stateful :1; /* stateful mode flag */ 162*10465441SEvalZero unsigned int discard :1; /* stateful mode packet loss flag */ 163*10465441SEvalZero } ppp_mppe_state; 164*10465441SEvalZero 165*10465441SEvalZero void mppe_set_key(ppp_pcb *pcb, ppp_mppe_state *state, u8_t *key); 166*10465441SEvalZero void mppe_init(ppp_pcb *pcb, ppp_mppe_state *state, u8_t options); 167*10465441SEvalZero void mppe_comp_reset(ppp_pcb *pcb, ppp_mppe_state *state); 168*10465441SEvalZero err_t mppe_compress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb, u16_t protocol); 169*10465441SEvalZero void mppe_decomp_reset(ppp_pcb *pcb, ppp_mppe_state *state); 170*10465441SEvalZero err_t mppe_decompress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb); 171*10465441SEvalZero 172*10465441SEvalZero #endif /* MPPE_H */ 173*10465441SEvalZero #endif /* PPP_SUPPORT && MPPE_SUPPORT */ 174