Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I wanted to add explicit key confirmation to Diffie-Hellman key exchange, would the following scheme be secure?

  1. Alice selects a random $a$ and sends $g^a \mod p$ to Bob

  2. Bob selects a random $b$, computes the shared secret $S = (g^a \mod p)^b$

  3. Bob computes two keys using HKDF ($H(k, m)$ denotes the HMAC of message $m$ using key $k$):

    • Compute $k = H(salt, S)$
    • Compute $k_1 = H(k, CTX || 0)$ and $k_2 = H(k, CTX || 1)$
  4. Bob sends $g^b \mod p$, $H(k_1, k_2)$, the salt, and the string CTX to Alice

  5. Alice computes the shared secret $S = (g^b \mod p)^a$, computes $k_1$ and $k_2$ using HKDF given the salt and the string CTX

  6. Alice computes $H(k_1, k_2)$ and verifies whether it's the same as the value that she received from Bob.

share|improve this question
up vote 4 down vote accepted

The major thing missing from Diffie-Hellman is that it provides no protection from someone running a man-in-the-middle attack. Your changes don't actually do anything to prevent that.

That is, suppose Eve was between Alice and Bob; when Alice sends the first message to Bob, Eve intercepts the message, and performs the exchange with Alice. At the same time, Eve forwards her own exchange to Bob. If Alice and Bob were attempting to perform this exchange to create secret keys, well, they will really share keys with Eve; when Alice sends a message, Eve will receive that encrypted message, decrypt it with the key she shares with Alice, examine it, and then encrypt it with the key she shares with Bob, and forwards it. That way, Eve sees all the traffic between Alice and Bob without being aware of it.

There is nothing that this key confirmation does that makes this any more difficult for Eve; she can compute $H(k_1, k_2)$ just as well as Alice and Bob, and so she will be able to impersonate Bob to Alice (and impersonating Alice to Bob).

Now, if the question was "is it secure if we don't have to worry about man-in-the-middle", the answer is "well, straight Diffie-Hellman is secure in that scenario; your additions don't appear to have made anything worse".

share|improve this answer
Thanks for looking at it, @poncho. Yes, I was assuming that man-in-the-middle was not an issue in the question. – herrfz Feb 7 '14 at 16:20
@herrfz: The sole additional information you're providing an evesdropper is $H(k_1, k_2)$; given that the only way to attack that is either to brute force it, or to have a Rainbow table, and the shared secret $S$ is too large for either; this doesn't give an evesdropper any additional edge. – poncho Feb 7 '14 at 16:47
@herrfz man-in-the-middle is always issue. – catpnosis Feb 7 '14 at 20:52
@catpnosis I'm totally aware of that. In my application we've achieved authentication through some other means, which I intentionally excluded from the question. I really just want to focus on the "explicit key confirmation" issue. – herrfz Feb 7 '14 at 21:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.