A simple to use implementation of ECDH with curve25519 for Go. The core mathematics of this algorithm are already present in golang.org/x/crypto/curve25519, this library just implements the algorithm in such a way that knowledge of the underlying mathematics is not necessary.
The below example does not include proper error handling.
package main
import (
"github.com/luke-park/ecdh25519"
)
func main() {
prv1, _ := ecdh25519.GenerateKey()
prv2, _ := ecdh25519.GenerateKey()
s1 := prv1.ComputeSecret(prv2.Public())
s2 := prv2.ComputeSecret(prv1.Public())
// bytes.Compare(s1, s2) == 0
}
The full documentation of this package can be found on GoDoc.