SAE: Don't use potentially uninitialized keys

If SAE_CONFIG_PK is not defined and sae->pk isn't zero (which is
possible as it is controlled by the commit message status code),
sae_derive_keys() may end up deriving PMK and KCK from an
uninitialized array. Fix that.

Fixes: 6b9e99e571 ("SAE-PK: Extend SAE functionality for AP validation")
Fixes: 20ccf97b3d ("SAE-PK: AP functionality")
Signed-off-by: Andrei Otcheretianski <andrei.otcheretianski@intel.com>
This commit is contained in:
Andrei Otcheretianski 2020-10-19 11:06:30 +03:00 committed by Jouni Malinen
parent b4c7114cf5
commit 80662accb5

View File

@ -1609,18 +1609,26 @@ static int sae_derive_keys(struct sae_data *sae, const u8 *k)
* octets). */ * octets). */
crypto_bignum_to_bin(tmp, val, sizeof(val), sae->tmp->order_len); crypto_bignum_to_bin(tmp, val, sizeof(val), sae->tmp->order_len);
wpa_hexdump(MSG_DEBUG, "SAE: PMKID", val, SAE_PMKID_LEN); wpa_hexdump(MSG_DEBUG, "SAE: PMKID", val, SAE_PMKID_LEN);
if (!sae->pk &&
sae_kdf_hash(hash_len, keyseed, "SAE KCK and PMK", #ifdef CONFIG_SAE_PK
if (sae->pk) {
if (sae_kdf_hash(hash_len, keyseed, "SAE-PK keys",
val, sae->tmp->order_len,
keys, 2 * hash_len + SAE_PMK_LEN) < 0)
goto fail;
} else {
if (sae_kdf_hash(hash_len, keyseed, "SAE KCK and PMK",
val, sae->tmp->order_len,
keys, hash_len + SAE_PMK_LEN) < 0)
goto fail;
}
#else /* CONFIG_SAE_PK */
if (sae_kdf_hash(hash_len, keyseed, "SAE KCK and PMK",
val, sae->tmp->order_len, val, sae->tmp->order_len,
keys, hash_len + SAE_PMK_LEN) < 0) keys, hash_len + SAE_PMK_LEN) < 0)
goto fail; goto fail;
#ifdef CONFIG_SAE_PK #endif /* !CONFIG_SAE_PK */
if (sae->pk &&
sae_kdf_hash(hash_len, keyseed, "SAE-PK keys",
val, sae->tmp->order_len,
keys, 2 * hash_len + SAE_PMK_LEN) < 0)
goto fail;
#endif /* CONFIG_SAE_PK */
forced_memzero(keyseed, sizeof(keyseed)); forced_memzero(keyseed, sizeof(keyseed));
os_memcpy(sae->tmp->kck, keys, hash_len); os_memcpy(sae->tmp->kck, keys, hash_len);
sae->tmp->kck_len = hash_len; sae->tmp->kck_len = hash_len;