36 #include "netif/ppp/ppp_opts.h" 37 #if PPP_SUPPORT && MPPE_SUPPORT 42 #include "netif/ppp/pppcrypt.h" 45 #define MPPE_MAX_KEY_LEN 16 48 #define MPPE_OPT_40 0x01 49 #define MPPE_OPT_128 0x02 50 #define MPPE_OPT_STATEFUL 0x04 52 #define MPPE_OPT_56 0x08 53 #define MPPE_OPT_MPPC 0x10 54 #define MPPE_OPT_D 0x20 55 #define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D) 56 #define MPPE_OPT_UNKNOWN 0x40 65 #define MPPE_C_BIT 0x01 66 #define MPPE_D_BIT 0x10 67 #define MPPE_L_BIT 0x20 68 #define MPPE_S_BIT 0x40 69 #define MPPE_M_BIT 0x80 70 #define MPPE_H_BIT 0x01 73 #define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT) 76 #define MPPE_OPTS_TO_CI(opts, ci) \ 81 if (opts & MPPE_OPT_STATEFUL) \ 84 *ptr++ = MPPE_H_BIT; \ 90 if (opts & MPPE_OPT_128) \ 92 if (opts & MPPE_OPT_40) \ 98 #define MPPE_CI_TO_OPTS(ci, opts) \ 100 const u_char *ptr = ci; \ 105 if (!(ptr[0] & MPPE_H_BIT)) \ 106 opts |= MPPE_OPT_STATEFUL; \ 109 if (ptr[3] & MPPE_S_BIT) \ 110 opts |= MPPE_OPT_128; \ 111 if (ptr[3] & MPPE_L_BIT) \ 112 opts |= MPPE_OPT_40; \ 115 if (ptr[3] & MPPE_M_BIT) \ 116 opts |= MPPE_OPT_56; \ 117 if (ptr[3] & MPPE_D_BIT) \ 118 opts |= MPPE_OPT_D; \ 119 if (ptr[3] & MPPE_C_BIT) \ 120 opts |= MPPE_OPT_MPPC; \ 123 if (ptr[0] & ~MPPE_H_BIT) \ 124 opts |= MPPE_OPT_UNKNOWN; \ 125 if (ptr[1] || ptr[2]) \ 126 opts |= MPPE_OPT_UNKNOWN; \ 127 if (ptr[3] & ~MPPE_ALL_BITS) \ 128 opts |= MPPE_OPT_UNKNOWN; \ 132 #define SHA1_PAD_SIZE 40 134 static const u8_t mppe_sha1_pad1[SHA1_PAD_SIZE] = {
135 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
137 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
138 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
140 static const u8_t mppe_sha1_pad2[SHA1_PAD_SIZE] = {
141 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
142 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
143 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
144 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2
150 typedef struct ppp_mppe_state {
151 lwip_arc4_context arc4;
152 u8_t master_key[MPPE_MAX_KEY_LEN];
153 u8_t session_key[MPPE_MAX_KEY_LEN];
161 unsigned int stateful :1;
162 unsigned int discard :1;
165 void mppe_set_key(ppp_pcb *pcb, ppp_mppe_state *state, u8_t *key);
166 void mppe_init(ppp_pcb *pcb, ppp_mppe_state *state, u8_t options);
167 void mppe_comp_reset(ppp_pcb *pcb, ppp_mppe_state *state);
168 err_t mppe_compress(ppp_pcb *pcb, ppp_mppe_state *state,
struct pbuf **pb, u16_t protocol);
169 void mppe_decomp_reset(ppp_pcb *pcb, ppp_mppe_state *state);
170 err_t mppe_decompress(ppp_pcb *pcb, ppp_mppe_state *state,
struct pbuf **pb);