github.com/cloudflare/circl@v1.5.0/dh/curve4q/curve4Q.go (about) 1 package curve4q 2 3 import "github.com/cloudflare/circl/ecc/fourq" 4 5 // Size is the size in bytes of keys. 6 const Size = 32 7 8 // Key represents a public or private key of FourQ. 9 type Key [Size]byte 10 11 // KeyGen calculates a public key k from a secret key. 12 func KeyGen(public, secret *Key) { 13 var P fourq.Point 14 P.ScalarBaseMult((*[Size]byte)(secret)) 15 P.Marshal((*[Size]byte)(public)) 16 } 17 18 // Shared calculates a shared key k from Alice's secret and Bob's public key. 19 // Returns true on success. 20 func Shared(shared, secret, public *Key) bool { 21 var P, Q fourq.Point 22 ok := P.Unmarshal((*[Size]byte)(public)) 23 Q.ScalarMult((*[Size]byte)(secret), &P) 24 Q.Marshal((*[Size]byte)(shared)) 25 ok = ok && Q.IsOnCurve() 26 return ok 27 }