def test_mult_recursive_aff() -> None: for ec in all_curves.values(): assert mult_recursive_aff(0, ec.G, ec) == INF assert mult_recursive_aff(0, INF, ec) == INF assert mult_recursive_aff(1, INF, ec) == INF assert mult_aff(1, ec.G, ec) == ec.G Q = ec.add_aff(ec.G, ec.G) assert Q == mult_recursive_aff(2, ec.G, ec) Q = mult_recursive_aff(ec.n - 1, ec.G, ec) assert ec.negate(ec.G) == Q assert mult_recursive_aff(ec.n - 1, INF, ec) == INF assert ec.add_aff(Q, ec.G) == INF assert mult_recursive_aff(ec.n, ec.G, ec) == INF assert mult_recursive_aff(ec.n, INF, ec) == INF with pytest.raises(BTClibValueError, match="negative m: "): mult_recursive_aff(-1, ec.G, ec) for ec in low_card_curves.values(): for q in range(ec.n): Q = mult_recursive_aff(q, ec.G, ec) assert ec.is_on_curve(Q), f"{q}, {ec}" QJ = _mult(q, ec.GJ, ec) assert ec.is_on_curve(ec.aff_from_jac(QJ)), f"{q}, {ec}" assert Q == ec.aff_from_jac(QJ), f"{q}, {ec}" assert INF == mult_recursive_aff(q, INF, ec), f"{q}, {ec}" assert ec.jac_equality(INFJ, _mult(q, INFJ, ec)), f"{q}, {ec}"
def test_mult_base_3() -> None: for ec in low_card_curves.values(): assert ec.jac_equality(mult_base_3(0, ec.GJ, ec), INFJ) assert ec.jac_equality(mult_base_3(0, INFJ, ec), INFJ) assert ec.jac_equality(mult_base_3(1, INFJ, ec), INFJ) assert ec.jac_equality(mult_base_3(1, ec.GJ, ec), ec.GJ) PJ = mult_base_3(2, ec.GJ, ec) assert ec.jac_equality(PJ, ec.add_jac(ec.GJ, ec.GJ)) PJ = mult_base_3(ec.n - 1, ec.GJ, ec) assert ec.jac_equality(ec.negate_jac(ec.GJ), PJ) assert ec.jac_equality(mult_base_3(ec.n - 1, INFJ, ec), INFJ) assert ec.jac_equality(ec.add_jac(PJ, ec.GJ), INFJ) assert ec.jac_equality(mult_base_3(ec.n, ec.GJ, ec), INFJ) assert ec.jac_equality(mult_mont_ladder(ec.n, INFJ, ec), INFJ) with pytest.raises(BTClibValueError, match="negative m: "): mult_base_3(-1, ec.GJ, ec) ec = ec23_31 for k1 in range(ec.n): K1 = mult_base_3(k1, ec.GJ, ec) assert ec.jac_equality(K1, _mult(k1, ec.GJ, ec))
def test_mult_fixed_window_cached() -> None: for _ in range(1, MAX_W): for ec in low_card_curves.values(): assert ec.jac_equality(mult_fixed_window_cached(0, ec.GJ, ec), INFJ) assert ec.jac_equality(mult_fixed_window_cached(0, INFJ, ec), INFJ) assert ec.jac_equality(mult_fixed_window_cached(1, INFJ, ec), INFJ) assert ec.jac_equality(mult_fixed_window_cached(1, ec.GJ, ec), ec.GJ) PJ = mult_fixed_window_cached(2, ec.GJ, ec) assert ec.jac_equality(PJ, ec.add_jac(ec.GJ, ec.GJ)) PJ = mult_fixed_window_cached(ec.n - 1, ec.GJ, ec) assert ec.jac_equality(ec.negate_jac(ec.GJ), PJ) assert ec.jac_equality( mult_fixed_window_cached(ec.n - 1, INFJ, ec), INFJ) assert ec.jac_equality(ec.add_jac(PJ, ec.GJ), INFJ) assert ec.jac_equality(mult_fixed_window_cached(ec.n, ec.GJ, ec), INFJ) assert ec.jac_equality(mult_mont_ladder(ec.n, INFJ, ec), INFJ) with pytest.raises(BTClibValueError, match="negative m: "): mult_fixed_window_cached(-1, ec.GJ, ec) with pytest.raises(BTClibValueError, match="non positive w: "): mult_fixed_window_cached(1, ec.GJ, ec, -1) ec = ec23_31 for w in range(1, 10): for k1 in range(ec.n): K1 = mult_fixed_window_cached(k1, ec.GJ, ec, w) assert ec.jac_equality(K1, mult_jac(k1, ec.GJ, ec))
def test_mult_w_NAF() -> None: for w in range(1, 6): for ec in low_card_curves.values(): assert ec.jac_equality(mult_w_NAF(0, ec.GJ, ec, w), INFJ) assert ec.jac_equality(mult_w_NAF(0, INFJ, ec, w), INFJ) assert ec.jac_equality(mult_w_NAF(1, INFJ, ec, w), INFJ) assert ec.jac_equality(mult_w_NAF(1, ec.GJ, ec, w), ec.GJ) PJ = mult_w_NAF(2, ec.GJ, ec, w) assert ec.jac_equality(PJ, ec.add_jac(ec.GJ, ec.GJ)) PJ = mult_w_NAF(ec.n - 1, ec.GJ, ec, w) assert ec.jac_equality(ec.negate_jac(ec.GJ), PJ) assert ec.jac_equality(mult_w_NAF(ec.n - 1, INFJ, ec, w), INFJ) assert ec.jac_equality(ec.add_jac(PJ, ec.GJ), INFJ) assert ec.jac_equality(mult_w_NAF(ec.n, ec.GJ, ec, w), INFJ) with pytest.raises(BTClibValueError, match="negative m: "): mult_w_NAF(-1, ec.GJ, ec, w) with pytest.raises(BTClibValueError, match="non positive w: "): mult_w_NAF(1, ec.GJ, ec, -w) ec = ec23_31 for w in range(1, 10): for k1 in range(ec.n): K1 = mult_w_NAF(k1, ec.GJ, ec, w) assert ec.jac_equality(K1, _mult(k1, ec.GJ, ec))