MCPcopy Create free account
hub / github.com/ElementsProject/elements / ecmult_const_mult_xonly

Function ecmult_const_mult_xonly

src/secp256k1/src/tests.c:4677–4730  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4675}
4676
4677static void ecmult_const_mult_xonly(void) {
4678 int i;
4679
4680 /* Test correspondence between secp256k1_ecmult_const and secp256k1_ecmult_const_xonly. */
4681 for (i = 0; i < 2*COUNT; ++i) {
4682 secp256k1_ge base;
4683 secp256k1_gej basej, resj;
4684 secp256k1_fe n, d, resx, v;
4685 secp256k1_scalar q;
4686 int res;
4687 /* Random base point. */
4688 random_group_element_test(&base);
4689 /* Random scalar to multiply it with. */
4690 random_scalar_order_test(&q);
4691 /* If i is odd, n=d*base.x for random non-zero d */
4692 if (i & 1) {
4693 random_fe_non_zero_test(&d);
4694 secp256k1_fe_mul(&n, &base.x, &d);
4695 } else {
4696 n = base.x;
4697 }
4698 /* Perform x-only multiplication. */
4699 res = secp256k1_ecmult_const_xonly(&resx, &n, (i & 1) ? &d : NULL, &q, i & 2);
4700 CHECK(res);
4701 /* Perform normal multiplication. */
4702 secp256k1_gej_set_ge(&basej, &base);
4703 secp256k1_ecmult(&resj, &basej, &q, NULL);
4704 /* Check that resj's X coordinate corresponds with resx. */
4705 secp256k1_fe_sqr(&v, &resj.z);
4706 secp256k1_fe_mul(&v, &v, &resx);
4707 CHECK(check_fe_equal(&v, &resj.x));
4708 }
4709
4710 /* Test that secp256k1_ecmult_const_xonly correctly rejects X coordinates not on curve. */
4711 for (i = 0; i < 2*COUNT; ++i) {
4712 secp256k1_fe x, n, d, r;
4713 int res;
4714 secp256k1_scalar q;
4715 random_scalar_order_test(&q);
4716 /* Generate random X coordinate not on the curve. */
4717 do {
4718 random_fe_test(&x);
4719 } while (secp256k1_ge_x_on_curve_var(&x));
4720 /* If i is odd, n=d*x for random non-zero d. */
4721 if (i & 1) {
4722 random_fe_non_zero_test(&d);
4723 secp256k1_fe_mul(&n, &x, &d);
4724 } else {
4725 n = x;
4726 }
4727 res = secp256k1_ecmult_const_xonly(&r, &n, (i & 1) ? &d : NULL, &q, 0);
4728 CHECK(res == 0);
4729 }
4730}
4731
4732static void ecmult_const_chain_multiply(void) {
4733 /* Check known result (randomly generated test problem from sage) */

Callers 1

run_ecmult_const_testsFunction · 0.85

Calls 11

random_scalar_order_testFunction · 0.85
random_fe_non_zero_testFunction · 0.85
check_fe_equalFunction · 0.85
random_fe_testFunction · 0.85
secp256k1_fe_mulFunction · 0.70
secp256k1_gej_set_geFunction · 0.70
secp256k1_ecmultFunction · 0.70
secp256k1_fe_sqrFunction · 0.70

Tested by

no test coverage detected