func testKeyGeneration(t *testing.T, c *bitelliptic.BitCurve, tag string) { priv, err := GenerateKey(c, rand.Reader) if err != nil { t.Errorf("%s: error: %s", tag, err) return } if !c.IsOnCurve(priv.PublicKey.X, priv.PublicKey.Y) { t.Errorf("%s: public key invalid: %s", tag, err) } }
// GenerateKey generates a public&private key pair. func GenerateKey(c *bitelliptic.BitCurve, rand io.Reader) (priv *PrivateKey, err error) { k, err := randFieldElement(c, rand) if err != nil { return } priv = new(PrivateKey) priv.PublicKey.BitCurve = c priv.D = k priv.PublicKey.X, priv.PublicKey.Y = c.ScalarBaseMult(k.Bytes()) return }