@@ -59,6 +59,19 @@ static void random_fe(secp256k1_fe *x) {
59
59
}
60
60
} while (1 );
61
61
}
62
+
63
+ static void random_fe_non_zero (secp256k1_fe * nz ) {
64
+ int tries = 10 ;
65
+ while (-- tries >= 0 ) {
66
+ random_fe (nz );
67
+ secp256k1_fe_normalize (nz );
68
+ if (!secp256k1_fe_is_zero (nz )) {
69
+ break ;
70
+ }
71
+ }
72
+ /* Infinitesimal probability of spurious failure here */
73
+ CHECK (tries >= 0 );
74
+ }
62
75
/** END stolen from tests.c */
63
76
64
77
static uint32_t num_cores = 1 ;
@@ -174,10 +187,37 @@ static void test_exhaustive_ecmult(const secp256k1_ge *group, const secp256k1_ge
174
187
secp256k1_ecmult (& tmp , & groupj [r_log ], & na , & ng );
175
188
ge_equals_gej (& group [(i * r_log + j ) % EXHAUSTIVE_TEST_ORDER ], & tmp );
176
189
177
- if (i > 0 ) {
178
- secp256k1_ecmult_const (& tmp , & group [i ], & ng , 256 );
179
- ge_equals_gej (& group [(i * j ) % EXHAUSTIVE_TEST_ORDER ], & tmp );
180
- }
190
+ }
191
+ }
192
+ }
193
+
194
+ for (j = 0 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) {
195
+ for (i = 1 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) {
196
+ int ret ;
197
+ secp256k1_gej tmp ;
198
+ secp256k1_fe xn , xd , tmpf ;
199
+ secp256k1_scalar ng ;
200
+
201
+ if (skip_section (& iter )) continue ;
202
+
203
+ secp256k1_scalar_set_int (& ng , j );
204
+
205
+ /* Test secp256k1_ecmult_const. */
206
+ secp256k1_ecmult_const (& tmp , & group [i ], & ng , 256 );
207
+ ge_equals_gej (& group [(i * j ) % EXHAUSTIVE_TEST_ORDER ], & tmp );
208
+
209
+ if (j != 0 ) {
210
+ /* Test secp256k1_ecmult_const_xonly with all curve X coordinates, and xd=NULL. */
211
+ ret = secp256k1_ecmult_const_xonly (& tmpf , & group [i ].x , NULL , & ng , 256 , 0 );
212
+ CHECK (ret );
213
+ CHECK (secp256k1_fe_equal_var (& tmpf , & group [(i * j ) % EXHAUSTIVE_TEST_ORDER ].x ));
214
+
215
+ /* Test secp256k1_ecmult_const_xonly with all curve X coordinates, with random xd. */
216
+ random_fe_non_zero (& xd );
217
+ secp256k1_fe_mul (& xn , & xd , & group [i ].x );
218
+ ret = secp256k1_ecmult_const_xonly (& tmpf , & xn , & xd , & ng , 256 , 0 );
219
+ CHECK (ret );
220
+ CHECK (secp256k1_fe_equal_var (& tmpf , & group [(i * j ) % EXHAUSTIVE_TEST_ORDER ].x ));
181
221
}
182
222
}
183
223
}
0 commit comments