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().
This commit is contained in:
Sylvain Rochet 2015-04-18 00:33:57 +02:00
parent da40445d75
commit 879c94b01e
2 changed files with 5 additions and 46 deletions

View File

@ -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);

View File

@ -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;