Lines Matching defs:state

61 static void mppe_rekey(ppp_mppe_state * state, int initial_key)
72 lwip_sha1_update(&sha1_ctx, state->master_key, state->keylen);
74 lwip_sha1_update(&sha1_ctx, state->session_key, state->keylen);
78 MEMCPY(state->session_key, sha1_digest, state->keylen);
81 lwip_arc4_init(&state->arc4);
82 lwip_arc4_setup(&state->arc4, sha1_digest, state->keylen);
83 lwip_arc4_crypt(&state->arc4, state->session_key, state->keylen);
84 lwip_arc4_free(&state->arc4);
86 if (state->keylen == 8) {
88 state->session_key[0] = 0xd1;
89 state->session_key[1] = 0x26;
90 state->session_key[2] = 0x9e;
92 lwip_arc4_init(&state->arc4);
93 lwip_arc4_setup(&state->arc4, state->session_key, state->keylen);
100 void mppe_set_key(ppp_pcb *pcb, ppp_mppe_state *state, u8_t *key) {
102 MEMCPY(state->master_key, key, MPPE_MAX_KEY_LEN);
106 * Initialize (de)compressor state.
109 mppe_init(ppp_pcb *pcb, ppp_mppe_state *state, u8_t options)
113 if (&pcb->mppe_decomp == state) {
119 MEMCPY(state->session_key, state->master_key, sizeof(state->master_key));
122 state->keylen = 16;
124 state->keylen = 8;
132 state->stateful = 1;
135 mppe_rekey(state, 1);
140 char mkey[sizeof(state->master_key) * 2 + 1];
141 char skey[sizeof(state->session_key) * 2 + 1];
144 debugstr, pcb->netif->num, (state->keylen == 16) ? 128 : 40,
145 (state->stateful) ? "stateful" : "stateless"));
147 for (i = 0; i < (int)sizeof(state->master_key); i++)
148 sprintf(mkey + i * 2, "%02x", state->master_key[i]);
149 for (i = 0; i < (int)sizeof(state->session_key); i++)
150 sprintf(skey + i * 2, "%02x", state->session_key[i]);
163 state->ccount = MPPE_CCOUNT_SPACE - 1;
169 state->bits = MPPE_BIT_ENCRYPTED;
181 void mppe_comp_reset(ppp_pcb *pcb, ppp_mppe_state *state)
184 state->bits |= MPPE_BIT_FLUSHED;
193 mppe_compress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb, u16_t protocol)
223 state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
224 PPPDEBUG(LOG_DEBUG, ("mppe_compress[%d]: ccount %d\n", pcb->netif->num, state->ccount));
226 pl[0] = state->ccount>>8;
227 pl[1] = state->ccount;
229 if (!state->stateful || /* stateless mode */
230 ((state->ccount & 0xff) == 0xff) || /* "flag" packet */
231 (state->bits & MPPE_BIT_FLUSHED)) { /* CCP Reset-Request */
233 if (state->stateful) {
236 mppe_rekey(state, 0);
237 state->bits |= MPPE_BIT_FLUSHED;
239 pl[0] |= state->bits;
240 state->bits &= ~MPPE_BIT_FLUSHED; /* reset for next xmit */
253 lwip_arc4_crypt(&state->arc4, (u8_t*)n->payload, n->len);
268 void mppe_decomp_reset(ppp_pcb *pcb, ppp_mppe_state *state)
271 LWIP_UNUSED_ARG(state);
279 mppe_decompress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb)
291 state->sanity_errors += 100;
306 state->sanity_errors += 100;
309 if (!state->stateful && !flushed) {
312 state->sanity_errors += 100;
315 if (state->stateful && ((ccount & 0xff) == 0xff) && !flushed) {
318 state->sanity_errors += 100;
326 if (!state->stateful) {
328 if ((ccount - state->ccount) % MPPE_CCOUNT_SPACE > MPPE_CCOUNT_SPACE / 2) {
329 state->sanity_errors++;
334 while (state->ccount != ccount) {
335 mppe_rekey(state, 0);
336 state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
340 if (!state->discard) {
341 /* normal state */
342 state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
343 if (ccount != state->ccount) {
345 * (ccount > state->ccount)
346 * Packet loss detected, enter the discard state.
349 state->discard = 1;
354 /* discard state */
361 (state->ccount & ~0xff)) {
362 mppe_rekey(state, 0);
363 state->ccount =
364 (state->ccount +
369 state->discard = 0;
370 state->ccount = ccount;
376 * required to reset CCP state.
381 mppe_rekey(state, 0);
389 lwip_arc4_crypt(&state->arc4, (u8_t*)n->payload, n->len);
396 state->sanity_errors >>= 1;
401 if (state->sanity_errors >= SANITY_MAX) {