37#if PPP_SUPPORT && MPPE_SUPPORT
49#define MPPE_MAX_KEY_LEN 16
52#define MPPE_OPT_40 0x01
53#define MPPE_OPT_128 0x02
54#define MPPE_OPT_STATEFUL 0x04
56#define MPPE_OPT_56 0x08
57#define MPPE_OPT_MPPC 0x10
58#define MPPE_OPT_D 0x20
59#define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D)
60#define MPPE_OPT_UNKNOWN 0x40
69#define MPPE_C_BIT 0x01
70#define MPPE_D_BIT 0x10
71#define MPPE_L_BIT 0x20
72#define MPPE_S_BIT 0x40
73#define MPPE_M_BIT 0x80
74#define MPPE_H_BIT 0x01
77#define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT)
80#define MPPE_OPTS_TO_CI(opts, ci) \
85 if (opts & MPPE_OPT_STATEFUL) \
88 *ptr++ = MPPE_H_BIT; \
94 if (opts & MPPE_OPT_128) \
96 if (opts & MPPE_OPT_40) \
102#define MPPE_CI_TO_OPTS(ci, opts) \
104 const u_char *ptr = ci; \
109 if (!(ptr[0] & MPPE_H_BIT)) \
110 opts |= MPPE_OPT_STATEFUL; \
113 if (ptr[3] & MPPE_S_BIT) \
114 opts |= MPPE_OPT_128; \
115 if (ptr[3] & MPPE_L_BIT) \
116 opts |= MPPE_OPT_40; \
119 if (ptr[3] & MPPE_M_BIT) \
120 opts |= MPPE_OPT_56; \
121 if (ptr[3] & MPPE_D_BIT) \
122 opts |= MPPE_OPT_D; \
123 if (ptr[3] & MPPE_C_BIT) \
124 opts |= MPPE_OPT_MPPC; \
127 if (ptr[0] & ~MPPE_H_BIT) \
128 opts |= MPPE_OPT_UNKNOWN; \
129 if (ptr[1] || ptr[2]) \
130 opts |= MPPE_OPT_UNKNOWN; \
131 if (ptr[3] & ~MPPE_ALL_BITS) \
132 opts |= MPPE_OPT_UNKNOWN; \
136#define SHA1_PAD_SIZE 40
138static const u8_t mppe_sha1_pad1[SHA1_PAD_SIZE] = {
139 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
141 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
142 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
144static const u8_t mppe_sha1_pad2[SHA1_PAD_SIZE] = {
145 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
146 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
147 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
148 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2
154typedef struct ppp_mppe_state {
155 ppp_arc4_context arc4;
156 u8_t master_key[MPPE_MAX_KEY_LEN];
157 u8_t session_key[MPPE_MAX_KEY_LEN];
165 unsigned int stateful :1;
166 unsigned int discard :1;
169void mppe_set_key(ppp_pcb *pcb, ppp_mppe_state *state, u8_t *key);
170void mppe_init(ppp_pcb *pcb, ppp_mppe_state *state, u8_t options);
171void mppe_comp_reset(ppp_pcb *pcb, ppp_mppe_state *state);
172err_t mppe_compress(ppp_pcb *pcb, ppp_mppe_state *state,
struct pbuf **pb, u16_t protocol);
173void mppe_decomp_reset(ppp_pcb *pcb, ppp_mppe_state *state);
174err_t mppe_decompress(ppp_pcb *pcb, ppp_mppe_state *state,
struct pbuf **pb);