コード例 #1
0
ファイル: test_curve_group.py プロジェクト: btclib-org/btclib
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))
コード例 #2
0
ファイル: test_curve_group.py プロジェクト: btclib-org/btclib
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))