keymat_v2: Refactor CHILD_SA key derivation so it only needs one prf+ call

This commit is contained in:
Tobias Brunner
2022-04-14 18:54:24 +02:00
parent 00cfc05467
commit 742134c112
+7 -10
View File
@@ -527,7 +527,7 @@ METHOD(keymat_v2_t, derive_child_keys, bool,
chunk_t *encr_r, chunk_t *integ_r) chunk_t *encr_r, chunk_t *integ_r)
{ {
uint16_t enc_alg, int_alg, enc_size = 0, int_size = 0; uint16_t enc_alg, int_alg, enc_size = 0, int_size = 0;
chunk_t seed, secret = chunk_empty; chunk_t seed, secret = chunk_empty, keymat = chunk_empty;
prf_plus_t *prf_plus; prf_plus_t *prf_plus;
if (proposal->get_algorithm(proposal, ENCRYPTION_ALGORITHM, if (proposal->get_algorithm(proposal, ENCRYPTION_ALGORITHM,
@@ -619,21 +619,18 @@ METHOD(keymat_v2_t, derive_child_keys, bool,
} }
*encr_i = *integ_i = *encr_r = *integ_r = chunk_empty; *encr_i = *integ_i = *encr_r = *integ_r = chunk_empty;
if (!prf_plus->allocate_bytes(prf_plus, enc_size, encr_i) || keymat.len = 2 * enc_size + 2 * int_size;
!prf_plus->allocate_bytes(prf_plus, int_size, integ_i) || if (!prf_plus->allocate_bytes(prf_plus, keymat.len, &keymat))
!prf_plus->allocate_bytes(prf_plus, enc_size, encr_r) ||
!prf_plus->allocate_bytes(prf_plus, int_size, integ_r))
{ {
chunk_free(encr_i);
chunk_free(integ_i);
chunk_free(encr_r);
chunk_free(integ_r);
prf_plus->destroy(prf_plus); prf_plus->destroy(prf_plus);
return FALSE; return FALSE;
} }
prf_plus->destroy(prf_plus); prf_plus->destroy(prf_plus);
chunk_split(keymat, "aaaa", enc_size, encr_i, int_size, integ_i,
enc_size, encr_r, int_size, integ_r);
chunk_clear(&keymat);
if (enc_size) if (enc_size)
{ {
DBG4(DBG_CHD, "encryption initiator key %B", encr_i); DBG4(DBG_CHD, "encryption initiator key %B", encr_i);