func NewKey() (*Key, error) { pub, priv, err := ed25519.GenerateKey(rand.Reader) if err != nil { return nil, err } k := &Key{ Public: *pub, Private: priv, } k.ID = k.Serialize().ID() return k, nil }
func TestCurve25519Conversion(t *testing.T) { public, private, _ := ed25519.GenerateKey(rand.Reader) var curve25519Public, curve25519Public2, curve25519Private [32]byte PrivateKeyToCurve25519(&curve25519Private, private) curve25519.ScalarBaseMult(&curve25519Public, &curve25519Private) if !PublicKeyToCurve25519(&curve25519Public2, public) { t.Fatalf("PublicKeyToCurve25519 failed") } if !bytes.Equal(curve25519Public[:], curve25519Public2[:]) { t.Errorf("Values didn't match: curve25519 produced %x, conversion produced %x", curve25519Public[:], curve25519Public2[:]) } }