@@ -15,19 +15,10 @@ import (
15
15
//gopherjs:purge for go1.19 without generics
16
16
type nistPoint [T any ] interface {}
17
17
18
- type wrappedPoint interface {
19
- Bytes () []byte
20
- SetBytes (b []byte ) (wrappedPoint , error )
21
- Add (w1 , w2 wrappedPoint ) wrappedPoint
22
- Double (w1 wrappedPoint ) wrappedPoint
23
- ScalarMult (w1 wrappedPoint , scalar []byte ) (wrappedPoint , error )
24
- ScalarBaseMult (scalar []byte ) (wrappedPoint , error )
25
- }
26
-
27
18
// nistCurve replaces the generics with a version using the wrappedPoint
28
19
// interface, then update all the method signatures to also use wrappedPoint.
29
20
type nistCurve struct {
30
- newPoint func () wrappedPoint
21
+ newPoint func () nistec. WrappedPoint
31
22
params * CurveParams
32
23
}
33
24
@@ -38,10 +29,10 @@ func (curve *nistCurve) Params() *CurveParams
38
29
func (curve * nistCurve ) IsOnCurve (x , y * big.Int ) bool
39
30
40
31
//gopherjs:override-signature
41
- func (curve * nistCurve ) pointFromAffine (x , y * big.Int ) (p wrappedPoint , err error )
32
+ func (curve * nistCurve ) pointFromAffine (x , y * big.Int ) (p nistec. WrappedPoint , err error )
42
33
43
34
//gopherjs:override-signature
44
- func (curve * nistCurve ) pointToAffine (p wrappedPoint ) (x , y * big.Int )
35
+ func (curve * nistCurve ) pointToAffine (p nistec. WrappedPoint ) (x , y * big.Int )
45
36
46
37
//gopherjs:override-signature
47
38
func (curve * nistCurve ) Add (x1 , y1 , x2 , y2 * big.Int ) (* big.Int , * big.Int )
@@ -68,46 +59,7 @@ func (curve *nistCurve) Unmarshal(data []byte) (x, y *big.Int)
68
59
func (curve * nistCurve ) UnmarshalCompressed (data []byte ) (x , y * big.Int )
69
60
70
61
var p224 = & nistCurve {
71
- newPoint : newP224WrappedPoint ,
72
- }
73
-
74
- type p224Wrapper struct {
75
- point * nistec.P224Point
76
- }
77
-
78
- func wrapP224 (point * nistec.P224Point ) wrappedPoint {
79
- return p224Wrapper {point : point }
80
- }
81
-
82
- func newP224WrappedPoint () wrappedPoint {
83
- return wrapP224 (nistec .NewP224Point ())
84
- }
85
-
86
- func (w p224Wrapper ) Bytes () []byte {
87
- return w .point .Bytes ()
88
- }
89
-
90
- func (w p224Wrapper ) SetBytes (b []byte ) (wrappedPoint , error ) {
91
- p , err := w .point .SetBytes (b )
92
- return wrapP224 (p ), err
93
- }
94
-
95
- func (w p224Wrapper ) Add (w1 , w2 wrappedPoint ) wrappedPoint {
96
- return wrapP224 (w .point .Add (w1 .(p224Wrapper ).point , w2 .(p224Wrapper ).point ))
97
- }
98
-
99
- func (w p224Wrapper ) Double (w1 wrappedPoint ) wrappedPoint {
100
- return wrapP224 (w .point .Double (w1 .(p224Wrapper ).point ))
101
- }
102
-
103
- func (w p224Wrapper ) ScalarMult (w1 wrappedPoint , scalar []byte ) (wrappedPoint , error ) {
104
- p , err := w .point .ScalarMult (w1 .(p224Wrapper ).point , scalar )
105
- return wrapP224 (p ), err
106
- }
107
-
108
- func (w p224Wrapper ) ScalarBaseMult (scalar []byte ) (wrappedPoint , error ) {
109
- p , err := w .point .ScalarBaseMult (scalar )
110
- return wrapP224 (p ), err
62
+ newPoint : nistec .NewP224WrappedPoint ,
111
63
}
112
64
113
65
type p256Curve struct {
@@ -116,131 +68,14 @@ type p256Curve struct {
116
68
117
69
var p256 = & p256Curve {
118
70
nistCurve : nistCurve {
119
- newPoint : newP256WrappedPoint ,
71
+ newPoint : nistec . NewP256WrappedPoint ,
120
72
},
121
73
}
122
74
123
- type p256Wrapper struct {
124
- point * nistec.P256Point
125
- }
126
-
127
- func wrapP256 (point * nistec.P256Point ) wrappedPoint {
128
- return p256Wrapper {point : point }
129
- }
130
-
131
- func newP256WrappedPoint () wrappedPoint {
132
- return wrapP256 (nistec .NewP256Point ())
133
- }
134
-
135
- func (w p256Wrapper ) Bytes () []byte {
136
- return w .point .Bytes ()
137
- }
138
-
139
- func (w p256Wrapper ) SetBytes (b []byte ) (wrappedPoint , error ) {
140
- p , err := w .point .SetBytes (b )
141
- return wrapP256 (p ), err
142
- }
143
-
144
- func (w p256Wrapper ) Add (w1 , w2 wrappedPoint ) wrappedPoint {
145
- return wrapP256 (w .point .Add (w1 .(p256Wrapper ).point , w2 .(p256Wrapper ).point ))
146
- }
147
-
148
- func (w p256Wrapper ) Double (w1 wrappedPoint ) wrappedPoint {
149
- return wrapP256 (w .point .Double (w1 .(p256Wrapper ).point ))
150
- }
151
-
152
- func (w p256Wrapper ) ScalarMult (w1 wrappedPoint , scalar []byte ) (wrappedPoint , error ) {
153
- p , err := w .point .ScalarMult (w1 .(p256Wrapper ).point , scalar )
154
- return wrapP256 (p ), err
155
- }
156
-
157
- func (w p256Wrapper ) ScalarBaseMult (scalar []byte ) (wrappedPoint , error ) {
158
- p , err := w .point .ScalarBaseMult (scalar )
159
- return wrapP256 (p ), err
160
- }
161
-
162
75
var p521 = & nistCurve {
163
- newPoint : newP521WrappedPoint ,
164
- }
165
-
166
- type p521Wrapper struct {
167
- point * nistec.P521Point
168
- }
169
-
170
- func wrapP521 (point * nistec.P521Point ) wrappedPoint {
171
- return p521Wrapper {point : point }
172
- }
173
-
174
- func newP521WrappedPoint () wrappedPoint {
175
- return wrapP521 (nistec .NewP521Point ())
176
- }
177
-
178
- func (w p521Wrapper ) Bytes () []byte {
179
- return w .point .Bytes ()
180
- }
181
-
182
- func (w p521Wrapper ) SetBytes (b []byte ) (wrappedPoint , error ) {
183
- p , err := w .point .SetBytes (b )
184
- return wrapP521 (p ), err
185
- }
186
-
187
- func (w p521Wrapper ) Add (w1 , w2 wrappedPoint ) wrappedPoint {
188
- return wrapP521 (w .point .Add (w1 .(p521Wrapper ).point , w2 .(p521Wrapper ).point ))
189
- }
190
-
191
- func (w p521Wrapper ) Double (w1 wrappedPoint ) wrappedPoint {
192
- return wrapP521 (w .point .Double (w1 .(p521Wrapper ).point ))
193
- }
194
-
195
- func (w p521Wrapper ) ScalarMult (w1 wrappedPoint , scalar []byte ) (wrappedPoint , error ) {
196
- p , err := w .point .ScalarMult (w1 .(p521Wrapper ).point , scalar )
197
- return wrapP521 (p ), err
198
- }
199
-
200
- func (w p521Wrapper ) ScalarBaseMult (scalar []byte ) (wrappedPoint , error ) {
201
- p , err := w .point .ScalarBaseMult (scalar )
202
- return wrapP521 (p ), err
76
+ newPoint : nistec .NewP521WrappedPoint ,
203
77
}
204
78
205
79
var p384 = & nistCurve {
206
- newPoint : newP384WrappedPoint ,
207
- }
208
-
209
- type p384Wrapper struct {
210
- point * nistec.P384Point
211
- }
212
-
213
- func wrapP384 (point * nistec.P384Point ) wrappedPoint {
214
- return p384Wrapper {point : point }
215
- }
216
-
217
- func newP384WrappedPoint () wrappedPoint {
218
- return wrapP384 (nistec .NewP384Point ())
219
- }
220
-
221
- func (w p384Wrapper ) Bytes () []byte {
222
- return w .point .Bytes ()
223
- }
224
-
225
- func (w p384Wrapper ) SetBytes (b []byte ) (wrappedPoint , error ) {
226
- p , err := w .point .SetBytes (b )
227
- return wrapP384 (p ), err
228
- }
229
-
230
- func (w p384Wrapper ) Add (w1 , w2 wrappedPoint ) wrappedPoint {
231
- return wrapP384 (w .point .Add (w1 .(p384Wrapper ).point , w2 .(p384Wrapper ).point ))
232
- }
233
-
234
- func (w p384Wrapper ) Double (w1 wrappedPoint ) wrappedPoint {
235
- return wrapP384 (w .point .Double (w1 .(p384Wrapper ).point ))
236
- }
237
-
238
- func (w p384Wrapper ) ScalarMult (w1 wrappedPoint , scalar []byte ) (wrappedPoint , error ) {
239
- p , err := w .point .ScalarMult (w1 .(p384Wrapper ).point , scalar )
240
- return wrapP384 (p ), err
241
- }
242
-
243
- func (w p384Wrapper ) ScalarBaseMult (scalar []byte ) (wrappedPoint , error ) {
244
- p , err := w .point .ScalarBaseMult (scalar )
245
- return wrapP384 (p ), err
80
+ newPoint : nistec .NewP384WrappedPoint ,
246
81
}
0 commit comments