ECDH
Elliptic Curve Diffie-Hellman
ECDH process is very simple:
- choose a curve, there are a lot of curves available.
ghci> :info CurveName type CurveName :: * data CurveName = SEC_p112r1 | SEC_p112r2 | SEC_p128r1 ...
- Alice generate a private key
- Bob generate a private key
- Alice’s private key * Base point * Bob’s public key = share key = Alice’s public key * Base point * Bob’s private key
ghci> import Crypto.PubKey.ECC.DH
ghci> import Crypto.PubKey.ECC.Types
ghci> let curve = getCurveByName SEC_p384r1
ghci> do
ghci| alicePrivateKey <- generatePrivate curve
ghci| let alicePublicKey = calculatePublic curve alicePrivateKey
ghci| bobPrivateKey <- generatePrivate curve
ghci| let bobPublicKey = calculatePublic curve bobPrivateKey
ghci| let aliceSharedKey = getShared curve alicePrivateKey bobPublicKey
ghci| let bobSharedKey = getShared curve bobPrivateKey alicePublicKey
ghci| return (aliceSharedKey == bobSharedKey)
ghci|
True