Lines Matching refs:state
136 static void get_new_key_from_sha(struct ppp_mppe_state * state) in get_new_key_from_sha() argument
144 nbytes = setup_sg(&sg[0], state->master_key, state->keylen); in get_new_key_from_sha()
147 nbytes += setup_sg(&sg[2], state->session_key, state->keylen); in get_new_key_from_sha()
151 desc.tfm = state->sha1; in get_new_key_from_sha()
154 crypto_hash_digest(&desc, sg, nbytes, state->sha1_digest); in get_new_key_from_sha()
161 static void mppe_rekey(struct ppp_mppe_state * state, int initial_key) in mppe_rekey() argument
164 struct blkcipher_desc desc = { .tfm = state->arc4 }; in mppe_rekey()
166 get_new_key_from_sha(state); in mppe_rekey()
168 crypto_blkcipher_setkey(state->arc4, state->sha1_digest, in mppe_rekey()
169 state->keylen); in mppe_rekey()
172 setup_sg(sg_in, state->sha1_digest, state->keylen); in mppe_rekey()
173 setup_sg(sg_out, state->session_key, state->keylen); in mppe_rekey()
175 state->keylen) != 0) { in mppe_rekey()
179 memcpy(state->session_key, state->sha1_digest, state->keylen); in mppe_rekey()
181 if (state->keylen == 8) { in mppe_rekey()
183 state->session_key[0] = 0xd1; in mppe_rekey()
184 state->session_key[1] = 0x26; in mppe_rekey()
185 state->session_key[2] = 0x9e; in mppe_rekey()
187 crypto_blkcipher_setkey(state->arc4, state->session_key, state->keylen); in mppe_rekey()
195 struct ppp_mppe_state *state; in mppe_alloc() local
198 if (optlen != CILEN_MPPE + sizeof(state->master_key) || in mppe_alloc()
202 state = kzalloc(sizeof(*state), GFP_KERNEL); in mppe_alloc()
203 if (state == NULL) in mppe_alloc()
207 state->arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); in mppe_alloc()
208 if (IS_ERR(state->arc4)) { in mppe_alloc()
209 state->arc4 = NULL; in mppe_alloc()
213 state->sha1 = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC); in mppe_alloc()
214 if (IS_ERR(state->sha1)) { in mppe_alloc()
215 state->sha1 = NULL; in mppe_alloc()
219 digestsize = crypto_hash_digestsize(state->sha1); in mppe_alloc()
223 state->sha1_digest = kmalloc(digestsize, GFP_KERNEL); in mppe_alloc()
224 if (!state->sha1_digest) in mppe_alloc()
228 memcpy(state->master_key, &options[CILEN_MPPE], in mppe_alloc()
229 sizeof(state->master_key)); in mppe_alloc()
230 memcpy(state->session_key, state->master_key, in mppe_alloc()
231 sizeof(state->master_key)); in mppe_alloc()
238 return (void *)state; in mppe_alloc()
241 if (state->sha1_digest) in mppe_alloc()
242 kfree(state->sha1_digest); in mppe_alloc()
243 if (state->sha1) in mppe_alloc()
244 crypto_free_hash(state->sha1); in mppe_alloc()
245 if (state->arc4) in mppe_alloc()
246 crypto_free_blkcipher(state->arc4); in mppe_alloc()
247 kfree(state); in mppe_alloc()
257 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; in mppe_free() local
258 if (state) { in mppe_free()
259 if (state->sha1_digest) in mppe_free()
260 kfree(state->sha1_digest); in mppe_free()
261 if (state->sha1) in mppe_free()
262 crypto_free_hash(state->sha1); in mppe_free()
263 if (state->arc4) in mppe_free()
264 crypto_free_blkcipher(state->arc4); in mppe_free()
265 kfree(state); in mppe_free()
276 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; in mppe_init() local
285 state->keylen = 16; in mppe_init()
287 state->keylen = 8; in mppe_init()
294 state->stateful = 1; in mppe_init()
297 mppe_rekey(state, 1); in mppe_init()
301 char mkey[sizeof(state->master_key) * 2 + 1]; in mppe_init()
302 char skey[sizeof(state->session_key) * 2 + 1]; in mppe_init()
305 debugstr, unit, (state->keylen == 16) ? 128 : 40, in mppe_init()
306 (state->stateful) ? "stateful" : "stateless"); in mppe_init()
308 for (i = 0; i < sizeof(state->master_key); i++) in mppe_init()
309 sprintf(mkey + i * 2, "%02x", state->master_key[i]); in mppe_init()
310 for (i = 0; i < sizeof(state->session_key); i++) in mppe_init()
311 sprintf(skey + i * 2, "%02x", state->session_key[i]); in mppe_init()
323 state->ccount = MPPE_CCOUNT_SPACE - 1; in mppe_init()
329 state->bits = MPPE_BIT_ENCRYPTED; in mppe_init()
331 state->unit = unit; in mppe_init()
332 state->debug = debug; in mppe_init()
356 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; in mppe_comp_reset() local
358 state->bits |= MPPE_BIT_FLUSHED; in mppe_comp_reset()
370 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; in mppe_compress() local
371 struct blkcipher_desc desc = { .tfm = state->arc4 }; in mppe_compress()
386 "(have: %d need: %d)\n", state->unit, in mppe_compress()
401 state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE; in mppe_compress()
402 if (state->debug >= 7) in mppe_compress()
403 printk(KERN_DEBUG "mppe_compress[%d]: ccount %d\n", state->unit, in mppe_compress()
404 state->ccount); in mppe_compress()
405 put_unaligned_be16(state->ccount, obuf); in mppe_compress()
407 if (!state->stateful || /* stateless mode */ in mppe_compress()
408 ((state->ccount & 0xff) == 0xff) || /* "flag" packet */ in mppe_compress()
409 (state->bits & MPPE_BIT_FLUSHED)) { /* CCP Reset-Request */ in mppe_compress()
411 if (state->debug && state->stateful) in mppe_compress()
413 state->unit); in mppe_compress()
414 mppe_rekey(state, 0); in mppe_compress()
415 state->bits |= MPPE_BIT_FLUSHED; in mppe_compress()
417 obuf[0] |= state->bits; in mppe_compress()
418 state->bits &= ~MPPE_BIT_FLUSHED; /* reset for next xmit */ in mppe_compress()
434 state->stats.unc_bytes += isize; in mppe_compress()
435 state->stats.unc_packets++; in mppe_compress()
436 state->stats.comp_bytes += osize; in mppe_compress()
437 state->stats.comp_packets++; in mppe_compress()
448 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; in mppe_comp_stats() local
450 *stats = state->stats; in mppe_comp_stats()
477 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; in mppe_decompress() local
478 struct blkcipher_desc desc = { .tfm = state->arc4 }; in mppe_decompress()
484 if (state->debug) in mppe_decompress()
487 state->unit, isize); in mppe_decompress()
499 "(have: %d need: %d)\n", state->unit, in mppe_decompress()
506 if (state->debug >= 7) in mppe_decompress()
508 state->unit, ccount); in mppe_decompress()
514 state->unit); in mppe_decompress()
515 state->sanity_errors += 100; in mppe_decompress()
518 if (!state->stateful && !flushed) { in mppe_decompress()
520 "stateless mode!\n", state->unit); in mppe_decompress()
521 state->sanity_errors += 100; in mppe_decompress()
524 if (state->stateful && ((ccount & 0xff) == 0xff) && !flushed) { in mppe_decompress()
526 "flag packet!\n", state->unit); in mppe_decompress()
527 state->sanity_errors += 100; in mppe_decompress()
535 if (!state->stateful) { in mppe_decompress()
537 if ((ccount - state->ccount) % MPPE_CCOUNT_SPACE in mppe_decompress()
539 state->sanity_errors++; in mppe_decompress()
544 while (state->ccount != ccount) { in mppe_decompress()
545 mppe_rekey(state, 0); in mppe_decompress()
546 state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE; in mppe_decompress()
550 if (!state->discard) { in mppe_decompress()
552 state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE; in mppe_decompress()
553 if (ccount != state->ccount) { in mppe_decompress()
559 state->discard = 1; in mppe_decompress()
570 (state->ccount & ~0xff)) { in mppe_decompress()
571 mppe_rekey(state, 0); in mppe_decompress()
572 state->ccount = in mppe_decompress()
573 (state->ccount + in mppe_decompress()
578 state->discard = 0; in mppe_decompress()
579 state->ccount = ccount; in mppe_decompress()
590 mppe_rekey(state, 0); in mppe_decompress()
637 state->stats.unc_bytes += osize; in mppe_decompress()
638 state->stats.unc_packets++; in mppe_decompress()
639 state->stats.comp_bytes += isize; in mppe_decompress()
640 state->stats.comp_packets++; in mppe_decompress()
643 state->sanity_errors >>= 1; in mppe_decompress()
648 if (state->sanity_errors < SANITY_MAX) in mppe_decompress()
666 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; in mppe_incomp() local
668 if (state->debug && in mppe_incomp()
672 "(proto %04x)\n", state->unit, PPP_PROTOCOL(ibuf)); in mppe_incomp()
674 state->stats.inc_bytes += icnt; in mppe_incomp()
675 state->stats.inc_packets++; in mppe_incomp()
676 state->stats.unc_bytes += icnt; in mppe_incomp()
677 state->stats.unc_packets++; in mppe_incomp()