fixed generation of IKEv1 key material
This commit is contained in:
+17
-7
@@ -33,7 +33,6 @@
|
|||||||
#include <asn1/asn1.h>
|
#include <asn1/asn1.h>
|
||||||
#include <crypto/hashers/hasher.h>
|
#include <crypto/hashers/hasher.h>
|
||||||
#include <crypto/prfs/prf.h>
|
#include <crypto/prfs/prf.h>
|
||||||
#include <crypto/prf_plus.h>
|
|
||||||
#include <crypto/rngs/rng.h>
|
#include <crypto/rngs/rng.h>
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
@@ -1332,31 +1331,42 @@ static bool generate_skeyids_iv(struct state *st)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
size_t keysize = st->st_oakley.enckeylen/BITS_PER_BYTE;
|
size_t keysize = st->st_oakley.enckeylen/BITS_PER_BYTE;
|
||||||
|
|
||||||
/* free any existing key */
|
/* free any existing key */
|
||||||
free(st->st_enc_key.ptr);
|
free(st->st_enc_key.ptr);
|
||||||
|
|
||||||
if (keysize > st->st_skeyid_e.len)
|
if (keysize > st->st_skeyid_e.len)
|
||||||
{
|
{
|
||||||
|
u_char keytemp[MAX_OAKLEY_KEY_LEN + MAX_DIGEST_LEN];
|
||||||
char seed_buf[] = { 0x00 };
|
char seed_buf[] = { 0x00 };
|
||||||
chunk_t seed = chunk_from_buf(seed_buf);
|
chunk_t seed = chunk_from_buf(seed_buf);
|
||||||
|
size_t prf_block_size, i;
|
||||||
pseudo_random_function_t prf_alg;
|
pseudo_random_function_t prf_alg;
|
||||||
prf_plus_t *prf_plus;
|
|
||||||
prf_t *prf;
|
prf_t *prf;
|
||||||
|
|
||||||
prf_alg = oakley_to_prf(st->st_oakley.hasher->algo_id);
|
prf_alg = oakley_to_prf(st->st_oakley.hasher->algo_id);
|
||||||
prf = lib->crypto->create_prf(lib->crypto, prf_alg);
|
prf = lib->crypto->create_prf(lib->crypto, prf_alg);
|
||||||
prf->set_key(prf, st->st_skeyid_e);
|
prf->set_key(prf, st->st_skeyid_e);
|
||||||
prf_plus = prf_plus_create(prf, seed);
|
prf_block_size = prf->get_block_size(prf);
|
||||||
prf_plus->allocate_bytes(prf_plus, keysize, &st->st_enc_key);
|
|
||||||
prf_plus->destroy(prf_plus);
|
for (i = 0;;)
|
||||||
|
{
|
||||||
|
prf->get_bytes(prf, seed, &keytemp[i]);
|
||||||
|
i += prf_block_size;
|
||||||
|
if (i >= keysize)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
seed = chunk_create(&keytemp[i-prf_block_size], prf_block_size);
|
||||||
|
}
|
||||||
prf->destroy(prf);
|
prf->destroy(prf);
|
||||||
|
st->st_enc_key = chunk_create(keytemp, keysize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
st->st_enc_key = chunk_create(st->st_skeyid_e.ptr, keysize);
|
st->st_enc_key = chunk_create(st->st_skeyid_e.ptr, keysize);
|
||||||
st->st_enc_key = chunk_clone(st->st_enc_key);
|
|
||||||
}
|
}
|
||||||
|
st->st_enc_key = chunk_clone(st->st_enc_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
DBG(DBG_CRYPT,
|
DBG(DBG_CRYPT,
|
||||||
|
|||||||
Reference in New Issue
Block a user