Lines Matching refs:state
137 static void get_new_key_from_sha(struct ppp_mppe_state * state) in get_new_key_from_sha() argument
139 crypto_shash_init(state->sha1); in get_new_key_from_sha()
140 crypto_shash_update(state->sha1, state->master_key, in get_new_key_from_sha()
141 state->keylen); in get_new_key_from_sha()
142 crypto_shash_update(state->sha1, sha_pad->sha_pad1, in get_new_key_from_sha()
144 crypto_shash_update(state->sha1, state->session_key, in get_new_key_from_sha()
145 state->keylen); in get_new_key_from_sha()
146 crypto_shash_update(state->sha1, sha_pad->sha_pad2, in get_new_key_from_sha()
148 crypto_shash_final(state->sha1, state->sha1_digest); in get_new_key_from_sha()
155 static void mppe_rekey(struct ppp_mppe_state * state, int initial_key) in mppe_rekey() argument
158 SKCIPHER_REQUEST_ON_STACK(req, state->arc4); in mppe_rekey()
160 skcipher_request_set_tfm(req, state->arc4); in mppe_rekey()
163 get_new_key_from_sha(state); in mppe_rekey()
165 crypto_skcipher_setkey(state->arc4, state->sha1_digest, in mppe_rekey()
166 state->keylen); in mppe_rekey()
169 setup_sg(sg_in, state->sha1_digest, state->keylen); in mppe_rekey()
170 setup_sg(sg_out, state->session_key, state->keylen); in mppe_rekey()
171 skcipher_request_set_crypt(req, sg_in, sg_out, state->keylen, in mppe_rekey()
176 memcpy(state->session_key, state->sha1_digest, state->keylen); in mppe_rekey()
178 if (state->keylen == 8) { in mppe_rekey()
180 state->session_key[0] = 0xd1; in mppe_rekey()
181 state->session_key[1] = 0x26; in mppe_rekey()
182 state->session_key[2] = 0x9e; in mppe_rekey()
184 crypto_skcipher_setkey(state->arc4, state->session_key, state->keylen); in mppe_rekey()
193 struct ppp_mppe_state *state; in mppe_alloc() local
197 if (optlen != CILEN_MPPE + sizeof(state->master_key) || in mppe_alloc()
201 state = kzalloc(sizeof(*state), GFP_KERNEL); in mppe_alloc()
202 if (state == NULL) in mppe_alloc()
206 state->arc4 = crypto_alloc_skcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); in mppe_alloc()
207 if (IS_ERR(state->arc4)) { in mppe_alloc()
208 state->arc4 = NULL; in mppe_alloc()
216 state->sha1 = kmalloc(sizeof(*state->sha1) + in mppe_alloc()
219 if (!state->sha1) { in mppe_alloc()
223 state->sha1->tfm = shash; in mppe_alloc()
224 state->sha1->flags = 0; in mppe_alloc()
230 state->sha1_digest = kmalloc(digestsize, GFP_KERNEL); in mppe_alloc()
231 if (!state->sha1_digest) in mppe_alloc()
235 memcpy(state->master_key, &options[CILEN_MPPE], in mppe_alloc()
236 sizeof(state->master_key)); in mppe_alloc()
237 memcpy(state->session_key, state->master_key, in mppe_alloc()
238 sizeof(state->master_key)); in mppe_alloc()
245 return (void *)state; in mppe_alloc()
248 kfree(state->sha1_digest); in mppe_alloc()
249 if (state->sha1) { in mppe_alloc()
250 crypto_free_shash(state->sha1->tfm); in mppe_alloc()
251 kzfree(state->sha1); in mppe_alloc()
253 crypto_free_skcipher(state->arc4); in mppe_alloc()
254 kfree(state); in mppe_alloc()
264 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; in mppe_free() local
265 if (state) { in mppe_free()
266 kfree(state->sha1_digest); in mppe_free()
267 crypto_free_shash(state->sha1->tfm); in mppe_free()
268 kzfree(state->sha1); in mppe_free()
269 crypto_free_skcipher(state->arc4); in mppe_free()
270 kfree(state); in mppe_free()
281 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; in mppe_init() local
290 state->keylen = 16; in mppe_init()
292 state->keylen = 8; in mppe_init()
299 state->stateful = 1; in mppe_init()
302 mppe_rekey(state, 1); in mppe_init()
306 debugstr, unit, (state->keylen == 16) ? 128 : 40, in mppe_init()
307 (state->stateful) ? "stateful" : "stateless"); in mppe_init()
311 (int)sizeof(state->master_key), state->master_key, in mppe_init()
312 (int)sizeof(state->session_key), state->session_key); in mppe_init()
321 state->ccount = MPPE_CCOUNT_SPACE - 1; in mppe_init()
327 state->bits = MPPE_BIT_ENCRYPTED; in mppe_init()
329 state->unit = unit; in mppe_init()
330 state->debug = debug; in mppe_init()
354 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; in mppe_comp_reset() local
356 state->bits |= MPPE_BIT_FLUSHED; in mppe_comp_reset()
368 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; in mppe_compress() local
369 SKCIPHER_REQUEST_ON_STACK(req, state->arc4); in mppe_compress()
385 "(have: %d need: %d)\n", state->unit, in mppe_compress()
400 state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE; in mppe_compress()
401 if (state->debug >= 7) in mppe_compress()
402 printk(KERN_DEBUG "mppe_compress[%d]: ccount %d\n", state->unit, in mppe_compress()
403 state->ccount); in mppe_compress()
404 put_unaligned_be16(state->ccount, obuf); in mppe_compress()
406 if (!state->stateful || /* stateless mode */ in mppe_compress()
407 ((state->ccount & 0xff) == 0xff) || /* "flag" packet */ in mppe_compress()
408 (state->bits & MPPE_BIT_FLUSHED)) { /* CCP Reset-Request */ in mppe_compress()
410 if (state->debug && state->stateful) in mppe_compress()
412 state->unit); in mppe_compress()
413 mppe_rekey(state, 0); in mppe_compress()
414 state->bits |= MPPE_BIT_FLUSHED; in mppe_compress()
416 obuf[0] |= state->bits; in mppe_compress()
417 state->bits &= ~MPPE_BIT_FLUSHED; /* reset for next xmit */ in mppe_compress()
429 skcipher_request_set_tfm(req, state->arc4); in mppe_compress()
439 state->stats.unc_bytes += isize; in mppe_compress()
440 state->stats.unc_packets++; in mppe_compress()
441 state->stats.comp_bytes += osize; in mppe_compress()
442 state->stats.comp_packets++; in mppe_compress()
453 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; in mppe_comp_stats() local
455 *stats = state->stats; in mppe_comp_stats()
482 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; in mppe_decompress() local
483 SKCIPHER_REQUEST_ON_STACK(req, state->arc4); in mppe_decompress()
489 if (state->debug) in mppe_decompress()
492 state->unit, isize); in mppe_decompress()
504 "(have: %d need: %d)\n", state->unit, in mppe_decompress()
511 if (state->debug >= 7) in mppe_decompress()
513 state->unit, ccount); in mppe_decompress()
519 state->unit); in mppe_decompress()
520 state->sanity_errors += 100; in mppe_decompress()
523 if (!state->stateful && !flushed) { in mppe_decompress()
525 "stateless mode!\n", state->unit); in mppe_decompress()
526 state->sanity_errors += 100; in mppe_decompress()
529 if (state->stateful && ((ccount & 0xff) == 0xff) && !flushed) { in mppe_decompress()
531 "flag packet!\n", state->unit); in mppe_decompress()
532 state->sanity_errors += 100; in mppe_decompress()
540 if (!state->stateful) { in mppe_decompress()
542 if ((ccount - state->ccount) % MPPE_CCOUNT_SPACE in mppe_decompress()
544 state->sanity_errors++; in mppe_decompress()
549 while (state->ccount != ccount) { in mppe_decompress()
550 mppe_rekey(state, 0); in mppe_decompress()
551 state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE; in mppe_decompress()
555 if (!state->discard) { in mppe_decompress()
557 state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE; in mppe_decompress()
558 if (ccount != state->ccount) { in mppe_decompress()
564 state->discard = 1; in mppe_decompress()
575 (state->ccount & ~0xff)) { in mppe_decompress()
576 mppe_rekey(state, 0); in mppe_decompress()
577 state->ccount = in mppe_decompress()
578 (state->ccount + in mppe_decompress()
583 state->discard = 0; in mppe_decompress()
584 state->ccount = ccount; in mppe_decompress()
595 mppe_rekey(state, 0); in mppe_decompress()
618 skcipher_request_set_tfm(req, state->arc4); in mppe_decompress()
649 state->stats.unc_bytes += osize; in mppe_decompress()
650 state->stats.unc_packets++; in mppe_decompress()
651 state->stats.comp_bytes += isize; in mppe_decompress()
652 state->stats.comp_packets++; in mppe_decompress()
655 state->sanity_errors >>= 1; in mppe_decompress()
662 if (state->sanity_errors < SANITY_MAX) in mppe_decompress()
680 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; in mppe_incomp() local
682 if (state->debug && in mppe_incomp()
686 "(proto %04x)\n", state->unit, PPP_PROTOCOL(ibuf)); in mppe_incomp()
688 state->stats.inc_bytes += icnt; in mppe_incomp()
689 state->stats.inc_packets++; in mppe_incomp()
690 state->stats.unc_bytes += icnt; in mppe_incomp()
691 state->stats.unc_packets++; in mppe_incomp()