# Diffie Hellman Exchange Confusion [closed]

I am working on this question and I am wondering I have figured out the secret key, but my problem is I don't know how to use the secret key to decrypt the ciphertext.

Thanks for the help!

## closed as unclear what you're asking by cygnusv, yyyyyyy, fgrieu, otus, SEJPM♦Jun 9 '16 at 19:15

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Diffie-Hellman Exchange is used for establishing a common secret between two parties, not for encrypting/decrypting – cygnusv Jun 8 '16 at 6:02
• I think more context is needed to answer the question in a meaningful way. – puzzlepalace Jun 9 '16 at 18:08

Diffie Hellman(DH) is a key exchange method, it is not a encryption/decryption algorithm. You have to use the secret key generated from DH in a symmetric cipher algorithm which is the algorithm used to create ciphertext from plaintext in the first place.

For example, lets say Alice and Bob make a DH key exchange to generate a secret key $K$, then Alice uses that key to send a message $M$ to Bob by encrypting it using an encrption algorithm such as AES. So Alice creates ciphertext $C =AES_{Enc}(M,K)$ and Alice sends $C$ to Bob. Then Bob takes ciphertext $C$ and decrypts it using the same algorithm and the same secret key that Alice used to get the message: $M =AES_{Dec}(C,K)$.

• I'd like a mention of a KDF (PRF) in the answer. A well defined protocol would probably not directly use the agreed secret as a symmetric key. Hopefully Alice & Bob use a separate key for sending and receiving, and use an authenticated cipher or MAC on top of just performing encryption. – Maarten Bodewes Jun 8 '16 at 9:04
• @MaartenBodewes Thanks for additional info. related to the underlying protocol that Alice and Bob communicates. I just wanted to correct the misunderstanding about DH Exchange. – Makif Jun 8 '16 at 10:26
• Yes and it's a pretty clear description at the right level of understanding. Already upvoted of course! – Maarten Bodewes Jun 8 '16 at 11:12

Two parties choose private secrets $x_1$ and $x_2$, which they then exponentiate; $2^{x_1}$ and $2^{x_2}$, and swap with each other.

Each party is now able to compute a shared secret, $s = (2^{x_1})^{x_2} = (2^{x_2})^{x_1}$, which can be used to initialize a symmetric cipher for further communication.

When these operations are carried out modulo some large prime number, it is known as the Diffie-Hellmen key exchange. Finding the shared secret without knowledge of the private secrets amounts to solving the discrete logarithm problem which is considered computationally impractical.

• Actually, the value of the generator they both start off with needn't be 2, but is in general a well-known value $g$ (which is part of the description of the group). $g=2$ is used for some groups; however some groups use different values for $g$ (as for those groups, the value $2^x \bmod p$ would leak $x \bmod n$ for a surprisingly large $n$; for group23 from RFC5114 (section 2.2), $n \approx 2^{100}$) – poncho Jun 9 '16 at 16:33