11
11
#include "field.h"
12
12
#include "group.h"
13
13
14
+ /* These points can be generated in sage as follows:
15
+ *
16
+ * 0. Setup a worksheet with the following parameters.
17
+ * b = 4 # whatever CURVE_B will be set to
18
+ * F = FiniteField (0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F)
19
+ * C = EllipticCurve ([F (0), F (b)])
20
+ *
21
+ * 1. Determine all the small orders available to you. (If there are
22
+ * no satisfactory ones, go back and change b.)
23
+ * print C.order().factor(limit=1000)
24
+ *
25
+ * 2. Choose an order as one of the prime factors listed in the above step.
26
+ * (You can also multiply some to get a composite order, though the
27
+ * tests will crash trying to invert scalars during signing.) We take a
28
+ * random point and scale it to drop its order to the desired value.
29
+ * There is some probability this won't work; just try again.
30
+ * order = 199
31
+ * P = C.random_point()
32
+ * P = (int(P.order()) / int(order)) * P
33
+ * assert(P.order() == order)
34
+ *
35
+ * 3. Print the values. You'll need to use a vim macro or something to
36
+ * split the hex output into 4-byte chunks.
37
+ * print "%x %x" % P.xy()
38
+ */
39
+ #if defined(EXHAUSTIVE_TEST_ORDER )
40
+ # if EXHAUSTIVE_TEST_ORDER == 199
41
+ const secp256k1_ge secp256k1_ge_const_g = SECP256K1_GE_CONST (
42
+ 0xFA7CC9A7 , 0x0737F2DB , 0xA749DD39 , 0x2B4FB069 ,
43
+ 0x3B017A7D , 0xA808C2F1 , 0xFB12940C , 0x9EA66C18 ,
44
+ 0x78AC123A , 0x5ED8AEF3 , 0x8732BC91 , 0x1F3A2868 ,
45
+ 0x48DF246C , 0x808DAE72 , 0xCFE52572 , 0x7F0501ED
46
+ );
47
+
48
+ const int CURVE_B = 4 ;
49
+ # elif EXHAUSTIVE_TEST_ORDER == 13
50
+ const secp256k1_ge secp256k1_ge_const_g = SECP256K1_GE_CONST (
51
+ 0xedc60018 , 0xa51a786b , 0x2ea91f4d , 0x4c9416c0 ,
52
+ 0x9de54c3b , 0xa1316554 , 0x6cf4345c , 0x7277ef15 ,
53
+ 0x54cb1b6b , 0xdc8c1273 , 0x087844ea , 0x43f4603e ,
54
+ 0x0eaf9a43 , 0xf6effe55 , 0x939f806d , 0x37adf8ac
55
+ );
56
+ const int CURVE_B = 2 ;
57
+ # else
58
+ # error No known generator for the specified exhaustive test group order.
59
+ # endif
60
+ #else
14
61
/** Generator for secp256k1, value 'g' defined in
15
62
* "Standards for Efficient Cryptography" (SEC2) 2.7.1.
16
63
*/
@@ -21,6 +68,9 @@ static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_GE_CONST(
21
68
0xFD17B448UL , 0xA6855419UL , 0x9C47D08FUL , 0xFB10D4B8UL
22
69
);
23
70
71
+ const int CURVE_B = 7 ;
72
+ #endif
73
+
24
74
static void secp256k1_ge_set_gej_zinv (secp256k1_ge * r , const secp256k1_gej * a , const secp256k1_fe * zi ) {
25
75
secp256k1_fe zi2 ;
26
76
secp256k1_fe zi3 ;
@@ -145,9 +195,15 @@ static void secp256k1_ge_globalz_set_table_gej(size_t len, secp256k1_ge *r, secp
145
195
146
196
static void secp256k1_gej_set_infinity (secp256k1_gej * r ) {
147
197
r -> infinity = 1 ;
148
- secp256k1_fe_set_int (& r -> x , 0 );
149
- secp256k1_fe_set_int (& r -> y , 0 );
150
- secp256k1_fe_set_int (& r -> z , 0 );
198
+ secp256k1_fe_clear (& r -> x );
199
+ secp256k1_fe_clear (& r -> y );
200
+ secp256k1_fe_clear (& r -> z );
201
+ }
202
+
203
+ static void secp256k1_ge_set_infinity (secp256k1_ge * r ) {
204
+ r -> infinity = 1 ;
205
+ secp256k1_fe_clear (& r -> x );
206
+ secp256k1_fe_clear (& r -> y );
151
207
}
152
208
153
209
static void secp256k1_gej_clear (secp256k1_gej * r ) {
@@ -169,7 +225,7 @@ static int secp256k1_ge_set_xquad(secp256k1_ge *r, const secp256k1_fe *x) {
169
225
secp256k1_fe_sqr (& x2 , x );
170
226
secp256k1_fe_mul (& x3 , x , & x2 );
171
227
r -> infinity = 0 ;
172
- secp256k1_fe_set_int (& c , 7 );
228
+ secp256k1_fe_set_int (& c , CURVE_B );
173
229
secp256k1_fe_add (& c , & x3 );
174
230
return secp256k1_fe_sqrt (& r -> y , & c );
175
231
}
@@ -228,7 +284,7 @@ static int secp256k1_gej_is_valid_var(const secp256k1_gej *a) {
228
284
secp256k1_fe_sqr (& x3 , & a -> x ); secp256k1_fe_mul (& x3 , & x3 , & a -> x );
229
285
secp256k1_fe_sqr (& z2 , & a -> z );
230
286
secp256k1_fe_sqr (& z6 , & z2 ); secp256k1_fe_mul (& z6 , & z6 , & z2 );
231
- secp256k1_fe_mul_int (& z6 , 7 );
287
+ secp256k1_fe_mul_int (& z6 , CURVE_B );
232
288
secp256k1_fe_add (& x3 , & z6 );
233
289
secp256k1_fe_normalize_weak (& x3 );
234
290
return secp256k1_fe_equal_var (& y2 , & x3 );
@@ -242,7 +298,7 @@ static int secp256k1_ge_is_valid_var(const secp256k1_ge *a) {
242
298
/* y^2 = x^3 + 7 */
243
299
secp256k1_fe_sqr (& y2 , & a -> y );
244
300
secp256k1_fe_sqr (& x3 , & a -> x ); secp256k1_fe_mul (& x3 , & x3 , & a -> x );
245
- secp256k1_fe_set_int (& c , 7 );
301
+ secp256k1_fe_set_int (& c , CURVE_B );
246
302
secp256k1_fe_add (& x3 , & c );
247
303
secp256k1_fe_normalize_weak (& x3 );
248
304
return secp256k1_fe_equal_var (& y2 , & x3 );
0 commit comments