S5C1: implement Diffie-Hellman (+ refactoring).