From 879c94b01e35fa173bf2f653ad2071e32c3b9abf Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sat, 18 Apr 2015 00:33:57 +0200 Subject: [PATCH] PPP, MPPE, removed mppe_alloc() and mppe_free() We are going to use statically allocated struct ppp_mppe_state through PPP PCB, removed now useless mppe_alloc() and mppe_free(). Merged mppe_alloc() key copy to mppe_init(). --- src/include/netif/ppp/mppe.h | 2 -- src/netif/ppp/mppe.c | 49 ++++-------------------------------- 2 files changed, 5 insertions(+), 46 deletions(-) diff --git a/src/include/netif/ppp/mppe.h b/src/include/netif/ppp/mppe.h index ea8e95fd..6bd22f80 100644 --- a/src/include/netif/ppp/mppe.h +++ b/src/include/netif/ppp/mppe.h @@ -152,8 +152,6 @@ struct ppp_mppe_state { int debug; }; -struct ppp_mppe_state *mppe_alloc(unsigned char *options, int optlen); -void mppe_free(struct ppp_mppe_state *state); int mppe_comp_init(struct ppp_mppe_state *state, unsigned char *options, int optlen, int unit, int hdrlen, int debug); void mppe_comp_reset(struct ppp_mppe_state *state); diff --git a/src/netif/ppp/mppe.c b/src/netif/ppp/mppe.c index c8dbcfba..68feab6c 100644 --- a/src/netif/ppp/mppe.c +++ b/src/netif/ppp/mppe.c @@ -113,49 +113,6 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key) arc4_setup(&state->arc4, state->session_key, state->keylen); } -/* - * Allocate space for a (de)compressor. - */ -struct ppp_mppe_state *mppe_alloc(unsigned char *options, int optlen) -{ - struct ppp_mppe_state *state; - - if (optlen != CILEN_MPPE + sizeof(state->master_key) || - options[0] != CI_MPPE || options[1] != CILEN_MPPE) - goto out; - - /* FIXME: remove malloc() */ - state = (struct ppp_mppe_state *)malloc(sizeof(*state)); - if (state == NULL) - goto out; - - /* Save keys. */ - memcpy(state->master_key, &options[CILEN_MPPE], - sizeof(state->master_key)); - memcpy(state->session_key, state->master_key, - sizeof(state->master_key)); - - /* - * We defer initial key generation until mppe_init(), as mppe_alloc() - * is called frequently during negotiation. - */ - - return state; - -out: - return NULL; -} - -/* - * Deallocate space for a (de)compressor. - */ -void mppe_free(struct ppp_mppe_state *state) -{ - if (state) { - free(state); - } -} - /* * Initialize (de)compressor state. */ @@ -165,10 +122,14 @@ mppe_init(struct ppp_mppe_state *state, unsigned char *options, int optlen, int { unsigned char mppe_opts; - if (optlen != CILEN_MPPE || + if (optlen != CILEN_MPPE + sizeof(state->master_key) || options[0] != CI_MPPE || options[1] != CILEN_MPPE) return 0; + /* Save keys. */ + MEMCPY(state->master_key, &options[CILEN_MPPE], sizeof(state->master_key)); + MEMCPY(state->session_key, state->master_key, sizeof(state->master_key)); + MPPE_CI_TO_OPTS(&options[2], mppe_opts); if (mppe_opts & MPPE_OPT_128) state->keylen = 16;