Skip to content

Commit b5c9ee7

Browse files
committed
Make test_point_times_order test meaningful again
As wnaf splitting is scalar based, multiplying with the order directly would be reduced to multiplication with zero before even converting to wnaf.
1 parent 0b73059 commit b5c9ee7

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/tests.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -794,13 +794,16 @@ void run_ecmult_chain(void) {
794794
}
795795

796796
void test_point_times_order(const secp256k1_gej_t *point) {
797-
/* multiplying a point by the order results in O */
798-
const secp256k1_num_t *order = &secp256k1_ge_consts->order;
799-
secp256k1_num_t zero;
800-
secp256k1_num_set_int(&zero, 0);
801-
secp256k1_gej_t res;
802-
secp256k1_ecmult(&res, point, order, order); /* calc res = order * point + order * G; */
803-
CHECK(secp256k1_gej_is_infinity(&res));
797+
/* X * (point + G) + (order-X) * (pointer + G) = 0 */
798+
secp256k1_num_t x;
799+
random_num_order_test(&x);
800+
secp256k1_num_t nx;
801+
secp256k1_num_sub(&nx, &secp256k1_ge_consts->order, &x);
802+
secp256k1_gej_t res1, res2;
803+
secp256k1_ecmult(&res1, point, &x, &x); /* calc res1 = x * point + x * G; */
804+
secp256k1_ecmult(&res2, point, &nx, &nx); /* calc res2 = (order - x) * point + (order - x) * G; */
805+
secp256k1_gej_add_var(&res1, &res1, &res2);
806+
CHECK(secp256k1_gej_is_infinity(&res1));
804807
}
805808

806809
void run_point_times_order(void) {

0 commit comments

Comments
 (0)