aboutsummaryrefslogtreecommitdiff
path: root/curve/curve.go
blob: a194cded8b5acaac82d82294c3cb0c070fb0468a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
}