@@ -7,67 +7,131 @@ import (
7
7
"io"
8
8
)
9
9
10
+ // Params stores the size in bytes of elements and scalars.
10
11
type Params struct {
11
12
ElementLength uint // Length in bytes of an element.
12
13
CompressedElementLength uint // Length in bytes of a compressed element.
13
14
ScalarLength uint // Length in bytes of a scalar.
14
15
}
15
16
16
- // Group represents a prime-order group based on elliptic curves.
17
+ // Group represents an additive prime-order group based on elliptic curves.
17
18
type Group interface {
18
19
Params () * Params // Params returns parameters for the group
20
+ // Creates an element of the group set to the identity of the group.
19
21
NewElement () Element
22
+ // Creates a scalar of the group set to zero.
20
23
NewScalar () Scalar
24
+ // Creates an element of the group set to the identity of the group.
21
25
Identity () Element
26
+ // Creates an element of the group set to the generator of the group.
22
27
Generator () Element
28
+ // Returns a scalar set to the group order.
23
29
Order () Scalar
24
- RandomElement (io.Reader ) Element
25
- RandomScalar (io.Reader ) Scalar
30
+ // RandomElement creates an element chosen at random (using randomness
31
+ // from rnd) from the set of group elements. Use crypto/rand.Reader as
32
+ // a cryptographically secure random number generator
33
+ RandomElement (rnd io.Reader ) Element
34
+ // RandomScalar creates a scalar chosen at random (using randomness
35
+ // from rnd) from the set of group scalars. Use crypto/rand.Reader as
36
+ // a cryptographically secure random number generator
37
+ RandomScalar (rnd io.Reader ) Scalar
38
+ // RandomNonZeroScalar creates a scalar chosen at random (using randomness
39
+ // from rnd) from the set of group scalars. Use crypto/rand.Reader as
40
+ // a cryptographically secure random number generator. It is guaranteed
41
+ // the scalar is not zero.
26
42
RandomNonZeroScalar (io.Reader ) Scalar
27
- HashToElement (data , dst []byte ) Element
28
- HashToElementNonUniform (b , dst []byte ) Element
29
- HashToScalar (data , dst []byte ) Scalar
43
+ // HashToElement hashes a message (msg) using a domain separation string
44
+ // (dst) producing a group element with uniform distribution.
45
+ HashToElement (msg , dst []byte ) Element
46
+ // HashToElementNonUniform hashes a message (msg) using a domain separation
47
+ // string (dst) producing a group element with nonuniform distribution.
48
+ HashToElementNonUniform (msg , dst []byte ) Element
49
+ // HashToScalar hashes a message (msg) using a domain separation string
50
+ // (dst) producing a group scalar with uniform distribution.
51
+ HashToScalar (msg , dst []byte ) Scalar
30
52
}
31
53
32
- // Element represents an abstract element of a prime-order group.
54
+ // Element represents an element of a prime-order group.
33
55
type Element interface {
56
+ // Returns the group that the element belongs to.
34
57
Group () Group
35
- Set (Element ) Element
58
+ // Set the receiver to x, and returns the receiver.
59
+ Set (x Element ) Element
60
+ // Copy returns a new element equal to the receiver.
36
61
Copy () Element
62
+ // IsIdentity returns true if the receiver is the identity element of the
63
+ // group.
37
64
IsIdentity () bool
38
- IsEqual (Element ) bool
39
- CMov (int , Element ) Element
40
- CSelect (int , Element , Element ) Element
41
- Add (Element , Element ) Element
42
- Dbl (Element ) Element
43
- Neg (Element ) Element
44
- Mul (Element , Scalar ) Element
45
- MulGen (Scalar ) Element
65
+ // IsEqual returns true if the receiver is equal to x.
66
+ IsEqual (x Element ) bool
67
+ // CMov sets the receiver to x if b=1; the receiver is unmodified if b=0;
68
+ // otherwise panics if b is not 0 or 1. In all the cases, it returns the
69
+ // receiver.
70
+ CMov (b int , x Element ) Element
71
+ // CSelect sets the receiver to x if b=1; sets the receiver to y if b=0;
72
+ // otherwise panics if b is not 0 or 1. In all the cases, it returns the
73
+ // receiver.
74
+ CSelect (b int , x , y Element ) Element
75
+ // Add sets the receiver to x + y, and returns the receiver.
76
+ Add (x , y Element ) Element
77
+ // Dbl sets the receiver to 2 * x, and returns the receiver.
78
+ Dbl (x Element ) Element
79
+ // Neg sets the receiver to -x, and returns the receiver.
80
+ Neg (x Element ) Element
81
+ // Mul sets the receiver to s * x, and returns the receiver.
82
+ Mul (x Element , s Scalar ) Element
83
+ // MulGen sets the receiver to s * Generator(), and returns the receiver.
84
+ MulGen (s Scalar ) Element
85
+ // BinaryMarshaler returns a byte representation of the element.
46
86
encoding.BinaryMarshaler
87
+ // BinaryUnmarshaler recovers an element from a byte representation
88
+ // produced either by encoding.BinaryMarshaler or MarshalBinaryCompress.
47
89
encoding.BinaryUnmarshaler
90
+ // MarshalBinaryCompress returns a byte representation of an elment in a
91
+ // compact form whenever the group supports it; otherwise, returns the
92
+ // same byte representation produced by encoding.BinaryMarshaler.
48
93
MarshalBinaryCompress () ([]byte , error )
49
94
}
50
95
51
- // Scalar represents an integer scalar.
96
+ // Scalar represents a scalar of a prime-order group .
52
97
type Scalar interface {
98
+ // Returns the group that the scalar belongs to.
53
99
Group () Group
54
- Set (Scalar ) Scalar
100
+ // Set the receiver to x, and returns the receiver.
101
+ Set (x Scalar ) Scalar
102
+ // Copy returns a new scalar equal to the receiver.
55
103
Copy () Scalar
56
- IsEqual (Scalar ) bool
57
- SetUint64 (uint64 )
58
- CMov (int , Scalar ) Scalar
59
- CSelect (int , Scalar , Scalar ) Scalar
60
- Add (Scalar , Scalar ) Scalar
61
- Sub (Scalar , Scalar ) Scalar
62
- Mul (Scalar , Scalar ) Scalar
63
- Neg (Scalar ) Scalar
64
- Inv (Scalar ) Scalar
104
+ // IsEqual returns true if the receiver is equal to x.
105
+ IsEqual (x Scalar ) bool
106
+ // SetUint64 set the receiver to x, and returns the receiver.
107
+ SetUint64 (x uint64 ) Scalar
108
+ // CMov sets the receiver to x if b=1; the receiver is unmodified if b=0;
109
+ // otherwise panics if b is not 0 or 1. In all the cases, it returns the
110
+ // receiver.
111
+ CMov (b int , x Scalar ) Scalar
112
+ // CSelect sets the receiver to x if b=1; sets the receiver to y if b=0;
113
+ // otherwise panics if b is not 0 or 1. In all the cases, it returns the
114
+ // receiver.
115
+ CSelect (b int , x , y Scalar ) Scalar
116
+ // Add sets the receiver to x + y, and returns the receiver.
117
+ Add (x , y Scalar ) Scalar
118
+ // Sub sets the receiver to x - y, and returns the receiver.
119
+ Sub (x , y Scalar ) Scalar
120
+ // Mul sets the receiver to x * y, and returns the receiver.
121
+ Mul (x , y Scalar ) Scalar
122
+ // Neg sets the receiver to -x, and returns the receiver.
123
+ Neg (x Scalar ) Scalar
124
+ // Inv sets the receiver to 1/x, and returns the receiver.
125
+ Inv (x Scalar ) Scalar
126
+ // BinaryMarshaler returns a byte representation of the scalar.
65
127
encoding.BinaryMarshaler
128
+ // BinaryUnmarshaler recovers a scalar from a byte representation produced
129
+ // by encoding.BinaryMarshaler.
66
130
encoding.BinaryUnmarshaler
67
131
}
68
132
69
133
var (
70
- ErrType = errors .New ("type mismatch" )
71
- ErrUnmarshal = errors .New ("error unmarshaling" )
134
+ ErrType = errors .New ("group: type mismatch" )
135
+ ErrUnmarshal = errors .New ("group: error unmarshaling" )
72
136
ErrSelector = errors .New ("group: selector must be 0 or 1" )
73
137
)
0 commit comments