diff options
Diffstat (limited to 'curve/curve.go')
-rw-r--r-- | curve/curve.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/curve/curve.go b/curve/curve.go new file mode 100644 index 0000000..a194cde --- /dev/null +++ b/curve/curve.go @@ -0,0 +1,61 @@ +// This package implements an abstraction for various +// elliptic curve primitives, as multiplicative group. +package curve + +import "io" + +type Data interface { + Bytes() []byte + String() string +} + +type SomeScalar[S Data] interface { + Add(S) S + Sub(S) S + Mult(S) S + Equal(S) bool + + // Maybe later: + // Invert(S) S + // Negate(S) S +} + +type ScalarReader[S any] interface { + RandomScalar() S + ScalarFromReader(io.Reader) (S, error) + ScalarFromBytes([]byte) (S, error) +} + +type MultiplicativeCurve[S SomeScalar[s], s Data, P MPoint[S, s, p], p Data] interface { + ScalarReader[S] + + Identity() P + Generator() P + Product([]P) P + Exp(S) P +} + +type MPoint[S SomeScalar[s], s Data, P Data] interface { + Mult(P) P + Div(P) P + Inv() P + Exp(S) P + Equal(P) bool +} + +// For additive formulation of the curve, use these interfaces: +type AdditiveCurve[S SomeScalar[s], s Data, P APoint[S, s, p], p Data] interface { + ScalarReader[S] + Zero() P + Generator() P + Sum([]P) P + Mul(S) P +} + +type APoint[S SomeScalar[s], s Data, P Data] interface { + Add(P) P + Sub(P) P + Neg(P) P + ScalarMult(S) P + Equal(P) bool +}
\ No newline at end of file |