For a crypto course I need to realize a small software project where a client and a server want to communicate over a unsecured network. They both have the same secret. So I bascially have to secure Diffie Hellman against MIM attacks.
Now I must admit that I don't really understand the mathematics behind DH, but I grasp the concept with easy words: Both generate a random private key, share their random generated public key. Then both parties can calculate the symmetrical key from that.
Is there an easy way to secure DH against MIM? My workaround would be to just use the DH sym key, add the shared secret (as "salt") and generate a new sym key from it by using PDKF2. But I'm sure there is smarter way to do this?