Пример #1
0
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))
Пример #2
0
def test_mult_fixed_window() -> None:
    for w in range(1, _MAX_W):
        for ec in low_card_curves.values():
            assert ec._jac_equality(_mult_fixed_window(0, ec.GJ, ec, w), INFJ)
            assert ec._jac_equality(_mult_fixed_window(0, INFJ, ec, w), INFJ)

            assert ec._jac_equality(_mult_fixed_window(1, INFJ, ec, w), INFJ)
            assert ec._jac_equality(_mult_fixed_window(1, ec.GJ, ec, w), ec.GJ)

            PJ = _mult_fixed_window(2, ec.GJ, ec, w)
            assert ec._jac_equality(PJ, ec._add_jac(ec.GJ, ec.GJ))

            PJ = _mult_fixed_window(ec.n - 1, ec.GJ, ec, w)
            assert ec._jac_equality(ec.negate_jac(ec.GJ), PJ)
            assert ec._jac_equality(_mult_fixed_window(ec.n - 1, INFJ, ec, w),
                                    INFJ)

            assert ec._jac_equality(ec._add_jac(PJ, ec.GJ), INFJ)
            assert ec._jac_equality(_mult_fixed_window(ec.n, ec.GJ, ec, w),
                                    INFJ)
            assert ec._jac_equality(_mult_mont_ladder(ec.n, INFJ, ec), INFJ)

            with pytest.raises(BTClibValueError, match="negative m: "):
                _mult_fixed_window(-1, ec.GJ, ec, w)

            with pytest.raises(BTClibValueError, match="non positive w: "):
                _mult_fixed_window(1, ec.GJ, ec, -w)

    ec = ec23_31
    for w in range(1, 10):
        for k1 in range(ec.n):
            K1 = _mult_fixed_window(k1, ec.GJ, ec, w)
            assert ec._jac_equality(K1, _mult_jac(k1, ec.GJ, ec))
Пример #3
0
for q in qs:
    T = _mult(q, ec.GJ, ec) if gen_only else _mult(q, T, ec)
benchmark = time.time() - start
print("Benchmark completed", cached_multiples.cache_info())

T = ec.GJ
start = time.time()
for q in qs:
    T = _mult_jac(q, ec.GJ, ec) if gen_only else _mult_jac(q, T, ec)
double_and_add = time.time() - start
print(f"Double & add     : {double_and_add / benchmark:.0%}")

T = ec.GJ
start = time.time()
for q in qs:
    T = _mult_mont_ladder(q, ec.GJ, ec) if gen_only else _mult_mont_ladder(
        q, T, ec)
montgomery = time.time() - start
print(f"Montgomery ladder: {montgomery / benchmark:.0%}")

cached_multiples.cache_clear()
cached_multiples(ec.GJ, ec)
T = ec.GJ
start = time.time()
for q in qs:
    T = _mult_base_3(q, ec.GJ, ec) if gen_only else _mult_base_3(q, T, ec)
base3 = time.time() - start
print(f"Base 3           : {base3 / benchmark:.0%}",
      cached_multiples.cache_info())

cached_multiples.cache_clear()
Пример #4
0
for q in qs:
    T = _mult_jac(q, T, ec)
benchmark = time.time() - start
print("Benchmark completed")

T = ec.GJ
start = time.time()
for q in qs:
    T = _mult_jac(q, T, ec)
double_and_add = time.time() - start
print(f"Double & add     : {double_and_add / benchmark:.0%}")

T = ec.GJ
start = time.time()
for q in qs:
    T = _mult_mont_ladder(q, T, ec)
montgomery = time.time() - start
print(f"Montgomery ladder: {montgomery / benchmark:.0%}")

T = ec.GJ
start = time.time()
for q in qs:
    T = _mult_base_3(q, T, ec)
base3 = time.time() - start
print(f"Base 3           : {base3 / benchmark:.0%}")

T = ec.GJ
w = 4
start = time.time()
for q in qs:
    T = _mult_fixed_window(q, T, ec, w)