Add a return value to prf_t.set_key()

This commit is contained in:
Martin Willi
2012-07-16 14:53:34 +02:00
parent ecc080b393
commit f3ca96b2bf
12 changed files with 92 additions and 43 deletions
+25 -10
View File
@@ -240,7 +240,12 @@ static bool expand_skeyid_e(chunk_t skeyid_e, size_t key_size, prf_t *prf,
ka->len = key_size;
/* Ka = K1 | K2 | ..., K1 = prf(SKEYID_e, 0), K2 = prf(SKEYID_e, K1) ... */
prf->set_key(prf, skeyid_e);
if (!prf->set_key(prf, skeyid_e))
{
chunk_clear(ka);
chunk_clear(&skeyid_e);
return FALSE;
}
seed = octet_0;
for (i = 0; i < key_size; i += block_size)
{
@@ -434,8 +439,8 @@ METHOD(keymat_v1_t, derive_ike_keys, bool,
}
psk = shared_key->get_key(shared_key);
adjust_keylen(alg, &psk);
this->prf->set_key(this->prf, psk);
if (!this->prf->allocate_bytes(this->prf, nonces, &skeyid))
if (!this->prf->set_key(this->prf, psk) ||
!this->prf->allocate_bytes(this->prf, nonces, &skeyid))
{
chunk_clear(&g_xy);
return FALSE;
@@ -451,8 +456,8 @@ METHOD(keymat_v1_t, derive_ike_keys, bool,
case AUTH_HYBRID_INIT_RSA:
case AUTH_HYBRID_RESP_RSA:
{
this->prf->set_key(this->prf, nonces);
if (!this->prf->allocate_bytes(this->prf, g_xy, &skeyid))
if (!this->prf->set_key(this->prf, nonces) ||
!this->prf->allocate_bytes(this->prf, g_xy, &skeyid))
{
chunk_clear(&g_xy);
return FALSE;
@@ -467,11 +472,11 @@ METHOD(keymat_v1_t, derive_ike_keys, bool,
}
adjust_keylen(alg, &skeyid);
DBG4(DBG_IKE, "SKEYID %B", &skeyid);
this->prf->set_key(this->prf, skeyid);
/* SKEYID_d = prf(SKEYID, g^xy | CKY-I | CKY-R | 0) */
data = chunk_cat("cccc", g_xy, spi_i, spi_r, octet_0);
if (!this->prf->allocate_bytes(this->prf, data, &this->skeyid_d))
if (!this->prf->set_key(this->prf, skeyid) ||
!this->prf->allocate_bytes(this->prf, data, &this->skeyid_d))
{
chunk_clear(&g_xy);
chunk_clear(&data);
@@ -525,7 +530,11 @@ METHOD(keymat_v1_t, derive_ike_keys, bool,
chunk_clear(&skeyid);
return FALSE;
}
this->prf_auth->set_key(this->prf_auth, skeyid);
if (!this->prf_auth->set_key(this->prf_auth, skeyid))
{
chunk_clear(&skeyid);
return FALSE;
}
chunk_clear(&skeyid);
this->aead = create_aead(proposal, this->prf, skeyid_e);
@@ -628,7 +637,10 @@ METHOD(keymat_v1_t, derive_child_keys, bool,
}
/* KEYMAT = prf+(SKEYID_d, [ g(qm)^xy | ] protocol | SPI | Ni_b | Nr_b) */
this->prf->set_key(this->prf, this->skeyid_d);
if (!this->prf->set_key(this->prf, this->skeyid_d))
{
return FALSE;
}
protocol = proposal->get_protocol(proposal);
if (dh)
{
@@ -918,7 +930,10 @@ METHOD(keymat_v1_t, get_hash_phase2, bool,
default:
return FALSE;
}
this->prf->set_key(this->prf, this->skeyid_a);
if (!this->prf->set_key(this->prf, this->skeyid_a))
{
return FALSE;
}
if (add_message)
{
generator_t *generator;
+16 -13
View File
@@ -322,10 +322,10 @@ METHOD(keymat_v2_t, derive_ike_keys, bool,
if (rekey_function == PRF_UNDEFINED) /* not rekeying */
{
/* SKEYSEED = prf(Ni | Nr, g^ir) */
this->prf->set_key(this->prf, fixed_nonce);
if (this->prf->allocate_bytes(this->prf, secret, &skeyseed))
if (this->prf->set_key(this->prf, fixed_nonce) &&
this->prf->allocate_bytes(this->prf, secret, &skeyseed) &&
this->prf->set_key(this->prf, skeyseed))
{
this->prf->set_key(this->prf, skeyseed);
prf_plus = prf_plus_create(this->prf, TRUE, prf_plus_seed);
}
}
@@ -344,10 +344,10 @@ METHOD(keymat_v2_t, derive_ike_keys, bool,
return FALSE;
}
secret = chunk_cat("mc", secret, full_nonce);
rekey_prf->set_key(rekey_prf, rekey_skd);
if (rekey_prf->allocate_bytes(rekey_prf, secret, &skeyseed))
if (rekey_prf->set_key(rekey_prf, rekey_skd) &&
rekey_prf->allocate_bytes(rekey_prf, secret, &skeyseed) &&
rekey_prf->set_key(rekey_prf, skeyseed))
{
rekey_prf->set_key(rekey_prf, skeyseed);
prf_plus = prf_plus_create(rekey_prf, TRUE, prf_plus_seed);
}
}
@@ -536,7 +536,10 @@ METHOD(keymat_v2_t, derive_child_keys, bool,
int_size /= 8;
}
this->prf->set_key(this->prf, this->skd);
if (!this->prf->set_key(this->prf, this->skd))
{
return FALSE;
}
prf_plus = prf_plus_create(this->prf, TRUE, seed);
if (!prf_plus)
{
@@ -596,8 +599,8 @@ METHOD(keymat_v2_t, get_auth_octets, bool,
DBG3(DBG_IKE, "IDx' %B", &idx);
DBG3(DBG_IKE, "SK_p %B", &skp);
this->prf->set_key(this->prf, skp);
if (!this->prf->allocate_bytes(this->prf, idx, &chunk))
if (!this->prf->set_key(this->prf, skp) ||
!this->prf->allocate_bytes(this->prf, idx, &chunk))
{
return FALSE;
}
@@ -628,14 +631,14 @@ METHOD(keymat_v2_t, get_psk_sig, bool,
}
/* AUTH = prf(prf(Shared Secret,"Key Pad for IKEv2"), <msg octets>) */
key_pad = chunk_create(IKEV2_KEY_PAD, IKEV2_KEY_PAD_LENGTH);
this->prf->set_key(this->prf, secret);
if (!this->prf->allocate_bytes(this->prf, key_pad, &key))
if (!this->prf->set_key(this->prf, secret) ||
!this->prf->allocate_bytes(this->prf, key_pad, &key))
{
chunk_free(&octets);
return FALSE;
}
this->prf->set_key(this->prf, key);
if (!this->prf->allocate_bytes(this->prf, octets, sig))
if (!this->prf->set_key(this->prf, key) ||
!this->prf->allocate_bytes(this->prf, octets, sig))
{
chunk_free(&key);
chunk_free(&octets);