aboutsummaryrefslogtreecommitdiff
path: root/curve/curve.go
blob: 36c9eedd4d1690bd027304dd219a1a8634046a75 (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
62
63
// 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
	Mul(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 SomeCurve[S SomeScalar[s], s Data, P SomePoint[S, s, p], p Data] interface {
	ScalarReader[S]

	Identity() P
	Generator() P
	Product([]P) P
	Exp(S) P
}

type SomePoint[S SomeScalar[s], s Data, P Data] interface {
	Mul(P) P
	Div(P) P
	Inv() P
	Exp(S) P
	Equal(P) bool
}

/* Additive fomulation of a curve is not needed for now.

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
}
*/