Let Alice's keypair be $(a, g^a)$ and Bob's be $(b, g^b)$. Now suppose the adversary steal's Alice's key $a$. Of course the adversary can now impersonate Alice to others. This question is asking about KCI attacks, where the adversary is able to impersonate others to Alice. Not all protocols protect against this.
Structure of implicitly authenticated protocols:
Suppose the parties also do an ephemeral DHKA with $g^x, g^y$.
Alice knows $x$ and her actual partner knows $y$.
Considering these ephemeral DHKA messages and their public keys, each party now has 2 DHKA messages, resulting in 4 possible combinations.
For each combination, we can ask, from Alice's point of view, what kind of adversary could compute the DH secret:
- $g^{ab}$: Only Bob ($b$) or someone who stole Alice's key ($a$)
- $g^{ay}$: Only Alice's actual partner ($y$) or someone who stole Alice's key ($a$)
- $g^{xb}$: Only Bob ($b$)
- $g^{xy}$: Only Alice's actual partner ($y$)
A protocol vulnerable to KCI
In "protocol 3" of Blake-Wilson, Johnson, and Menezes [1] the parties use $H( g^{ab}, g^{xy})$ as their final secret. Besides Alice, who could compute this value?
(Bob OR someone who stole Alice's key) AND (Alice's actual partner)
Thus, this protocol is vulnerable to a KCI attack. Alice's actual partner could be an adversary who stole her key. This is the canonical example of a protocol vulnerable to KCI.
A protocol that protects against KCI
On the other hand, in Triple Diffie-Hellman (3DH) the parties use $H( g^{ay}, g^{xb}, g^{xy})$ as the final secret. Besides Alice, who could compute this value?
(Alice's actual partner OR someone who stole Alice's key) AND (Bob) AND (Alice's actual partner)
In other words, only Bob and only if he was Alice's actual partner. There is no KCI attack; the protocol achieves implicit authentication even in the presence of KCI adversaries.
[1] Blake-Wilson, Johnson, and Menezes: Key agreement protocols and their security analysis. 6th IMA International Conference on Cryptography and Coding, 1997.