diff options
author | Özgür Kesim <oec@codeblau.de> | 2024-03-21 19:02:20 +0100 |
---|---|---|
committer | Özgür Kesim <oec@codeblau.de> | 2024-03-21 19:02:20 +0100 |
commit | 989d09c8511eb10f2af06977d210deff39b6ff9e (patch) | |
tree | d360f2e3aa06d0e6dc2eaaac62274ca602d8821c /curve/curve.go | |
parent | 458f9b7172148a272b23d61747f0758bf21dbf1f (diff) |
veto, curve: Added an abstraction layer for elliptic curves
This will allow to easily swap various curves and implementations, for benchmarking, f.e.
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 |