IPsec is a framework protocol that consists of the sub-protocols ESP and AH. IPsec, inately, doesn't include a Key Exchange mechanism, and is therefore dependent on manually setting Keys (archaic), or using IKEv1 or IKEv2 to securely establish mutual keys between two parties.
From reading the IKE and IKEv2 RFC's, I know that both of them at some point generate KEYMAT, which is meant to be passed to IPsec so that IPsec can generate its own symmetric keys.
IKEv1 generates KEYMAT using this formula:
PFS Disabled: KEYMAT = prf(SKEYID_d, protocol | SPI | Ni_b | Nr_b). PFS Enabled: KEYMAT = prf(SKEYID_d, g(qm)^xy | protocol | SPI | Ni_b | Nr_b)
IKEv2 generates KEYMAT using this formula:
For the first Child SA: KEYMAT = prf+(SK_d, Ni | Nr) For all subsequent Child SA's KEYMAT = prf+(SK_d, g^ir (new) | Ni | Nr )
In both cases, KEYMAT is passed to IPSec to (presumably) create its own symmetric Encryption and Authentication keys. But I haven't been able to find anywhere the formulas IPsec uses to take the KEYMAT and/or derivative keys (SKEYID_d or SK_d) and create its own keys.
So my question is, What does IPsec do with KEYMAT in order to generate its own symmetric keys? And also related, What keys does IPsec generate after being given KEYMAT? Although I feel answering the first question will also answer the second.