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 #ifdef __cplusplus 45*10465441SEvalZero extern "C" { 46*10465441SEvalZero #endif 47*10465441SEvalZero 48*10465441SEvalZero #define MPPE_PAD 4 /* MPPE growth per frame */ 49*10465441SEvalZero #define MPPE_MAX_KEY_LEN 16 /* largest key length (128-bit) */ 50*10465441SEvalZero 51*10465441SEvalZero /* option bits for ccp_options.mppe */ 52*10465441SEvalZero #define MPPE_OPT_40 0x01 /* 40 bit */ 53*10465441SEvalZero #define MPPE_OPT_128 0x02 /* 128 bit */ 54*10465441SEvalZero #define MPPE_OPT_STATEFUL 0x04 /* stateful mode */ 55*10465441SEvalZero /* unsupported opts */ 56*10465441SEvalZero #define MPPE_OPT_56 0x08 /* 56 bit */ 57*10465441SEvalZero #define MPPE_OPT_MPPC 0x10 /* MPPC compression */ 58*10465441SEvalZero #define MPPE_OPT_D 0x20 /* Unknown */ 59*10465441SEvalZero #define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D) 60*10465441SEvalZero #define MPPE_OPT_UNKNOWN 0x40 /* Bits !defined in RFC 3078 were set */ 61*10465441SEvalZero 62*10465441SEvalZero /* 63*10465441SEvalZero * This is not nice ... the alternative is a bitfield struct though. 64*10465441SEvalZero * And unfortunately, we cannot share the same bits for the option 65*10465441SEvalZero * names above since C and H are the same bit. We could do a u_int32 66*10465441SEvalZero * but then we have to do a lwip_htonl() all the time and/or we still need 67*10465441SEvalZero * to know which octet is which. 68*10465441SEvalZero */ 69*10465441SEvalZero #define MPPE_C_BIT 0x01 /* MPPC */ 70*10465441SEvalZero #define MPPE_D_BIT 0x10 /* Obsolete, usage unknown */ 71*10465441SEvalZero #define MPPE_L_BIT 0x20 /* 40-bit */ 72*10465441SEvalZero #define MPPE_S_BIT 0x40 /* 128-bit */ 73*10465441SEvalZero #define MPPE_M_BIT 0x80 /* 56-bit, not supported */ 74*10465441SEvalZero #define MPPE_H_BIT 0x01 /* Stateless (in a different byte) */ 75*10465441SEvalZero 76*10465441SEvalZero /* Does not include H bit; used for least significant octet only. */ 77*10465441SEvalZero #define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT) 78*10465441SEvalZero 79*10465441SEvalZero /* Build a CI from mppe opts (see RFC 3078) */ 80*10465441SEvalZero #define MPPE_OPTS_TO_CI(opts, ci) \ 81*10465441SEvalZero do { \ 82*10465441SEvalZero u_char *ptr = ci; /* u_char[4] */ \ 83*10465441SEvalZero \ 84*10465441SEvalZero /* H bit */ \ 85*10465441SEvalZero if (opts & MPPE_OPT_STATEFUL) \ 86*10465441SEvalZero *ptr++ = 0x0; \ 87*10465441SEvalZero else \ 88*10465441SEvalZero *ptr++ = MPPE_H_BIT; \ 89*10465441SEvalZero *ptr++ = 0; \ 90*10465441SEvalZero *ptr++ = 0; \ 91*10465441SEvalZero \ 92*10465441SEvalZero /* S,L bits */ \ 93*10465441SEvalZero *ptr = 0; \ 94*10465441SEvalZero if (opts & MPPE_OPT_128) \ 95*10465441SEvalZero *ptr |= MPPE_S_BIT; \ 96*10465441SEvalZero if (opts & MPPE_OPT_40) \ 97*10465441SEvalZero *ptr |= MPPE_L_BIT; \ 98*10465441SEvalZero /* M,D,C bits not supported */ \ 99*10465441SEvalZero } while (/* CONSTCOND */ 0) 100*10465441SEvalZero 101*10465441SEvalZero /* The reverse of the above */ 102*10465441SEvalZero #define MPPE_CI_TO_OPTS(ci, opts) \ 103*10465441SEvalZero do { \ 104*10465441SEvalZero const u_char *ptr = ci; /* u_char[4] */ \ 105*10465441SEvalZero \ 106*10465441SEvalZero opts = 0; \ 107*10465441SEvalZero \ 108*10465441SEvalZero /* H bit */ \ 109*10465441SEvalZero if (!(ptr[0] & MPPE_H_BIT)) \ 110*10465441SEvalZero opts |= MPPE_OPT_STATEFUL; \ 111*10465441SEvalZero \ 112*10465441SEvalZero /* S,L bits */ \ 113*10465441SEvalZero if (ptr[3] & MPPE_S_BIT) \ 114*10465441SEvalZero opts |= MPPE_OPT_128; \ 115*10465441SEvalZero if (ptr[3] & MPPE_L_BIT) \ 116*10465441SEvalZero opts |= MPPE_OPT_40; \ 117*10465441SEvalZero \ 118*10465441SEvalZero /* M,D,C bits */ \ 119*10465441SEvalZero if (ptr[3] & MPPE_M_BIT) \ 120*10465441SEvalZero opts |= MPPE_OPT_56; \ 121*10465441SEvalZero if (ptr[3] & MPPE_D_BIT) \ 122*10465441SEvalZero opts |= MPPE_OPT_D; \ 123*10465441SEvalZero if (ptr[3] & MPPE_C_BIT) \ 124*10465441SEvalZero opts |= MPPE_OPT_MPPC; \ 125*10465441SEvalZero \ 126*10465441SEvalZero /* Other bits */ \ 127*10465441SEvalZero if (ptr[0] & ~MPPE_H_BIT) \ 128*10465441SEvalZero opts |= MPPE_OPT_UNKNOWN; \ 129*10465441SEvalZero if (ptr[1] || ptr[2]) \ 130*10465441SEvalZero opts |= MPPE_OPT_UNKNOWN; \ 131*10465441SEvalZero if (ptr[3] & ~MPPE_ALL_BITS) \ 132*10465441SEvalZero opts |= MPPE_OPT_UNKNOWN; \ 133*10465441SEvalZero } while (/* CONSTCOND */ 0) 134*10465441SEvalZero 135*10465441SEvalZero /* Shared MPPE padding between MSCHAP and MPPE */ 136*10465441SEvalZero #define SHA1_PAD_SIZE 40 137*10465441SEvalZero 138*10465441SEvalZero static const u8_t mppe_sha1_pad1[SHA1_PAD_SIZE] = { 139*10465441SEvalZero 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 140*10465441SEvalZero 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 141*10465441SEvalZero 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 142*10465441SEvalZero 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 143*10465441SEvalZero }; 144*10465441SEvalZero static const u8_t mppe_sha1_pad2[SHA1_PAD_SIZE] = { 145*10465441SEvalZero 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 146*10465441SEvalZero 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 147*10465441SEvalZero 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 148*10465441SEvalZero 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2 149*10465441SEvalZero }; 150*10465441SEvalZero 151*10465441SEvalZero /* 152*10465441SEvalZero * State for an MPPE (de)compressor. 153*10465441SEvalZero */ 154*10465441SEvalZero typedef struct ppp_mppe_state { 155*10465441SEvalZero lwip_arc4_context arc4; 156*10465441SEvalZero u8_t master_key[MPPE_MAX_KEY_LEN]; 157*10465441SEvalZero u8_t session_key[MPPE_MAX_KEY_LEN]; 158*10465441SEvalZero u8_t keylen; /* key length in bytes */ 159*10465441SEvalZero /* NB: 128-bit == 16, 40-bit == 8! 160*10465441SEvalZero * If we want to support 56-bit, the unit has to change to bits 161*10465441SEvalZero */ 162*10465441SEvalZero u8_t bits; /* MPPE control bits */ 163*10465441SEvalZero u16_t ccount; /* 12-bit coherency count (seqno) */ 164*10465441SEvalZero u16_t sanity_errors; /* take down LCP if too many */ 165*10465441SEvalZero unsigned int stateful :1; /* stateful mode flag */ 166*10465441SEvalZero unsigned int discard :1; /* stateful mode packet loss flag */ 167*10465441SEvalZero } ppp_mppe_state; 168*10465441SEvalZero 169*10465441SEvalZero void mppe_set_key(ppp_pcb *pcb, ppp_mppe_state *state, u8_t *key); 170*10465441SEvalZero void mppe_init(ppp_pcb *pcb, ppp_mppe_state *state, u8_t options); 171*10465441SEvalZero void mppe_comp_reset(ppp_pcb *pcb, ppp_mppe_state *state); 172*10465441SEvalZero err_t mppe_compress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb, u16_t protocol); 173*10465441SEvalZero void mppe_decomp_reset(ppp_pcb *pcb, ppp_mppe_state *state); 174*10465441SEvalZero err_t mppe_decompress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb); 175*10465441SEvalZero 176*10465441SEvalZero #ifdef __cplusplus 177*10465441SEvalZero } 178*10465441SEvalZero #endif 179*10465441SEvalZero 180*10465441SEvalZero #endif /* MPPE_H */ 181*10465441SEvalZero #endif /* PPP_SUPPORT && MPPE_SUPPORT */ 182