Skip to content

Commit

Permalink
Add Ladder sort-of regression test.
Browse files Browse the repository at this point in the history
  • Loading branch information
J08nY committed May 31, 2024
1 parent ead235f commit e2bb0ab
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/ec/test_mult.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest

from pyecsca.ec.mod import Mod
from pyecsca.ec.mult import (
DoubleAndAddMultiplier,
LTRMultiplier,
Expand Down Expand Up @@ -178,6 +179,41 @@ def test_ladder(curve25519):
assert_pt_equality(a, b, True)


@pytest.mark.parametrize(
"scalar,x,res",
[
(
29893438142586401087946310744922998080771935139441267052026283852717044358472,
48084050389777770101701157326923977117307187144965043058462938058489685090437,
40694087602335028385342029955981451169449898924211721351135404099078471497195,
)
],
)
def test_ladder_full(curve25519, scalar, x, res):
p = curve25519.curve.prime
point = Point(curve25519.curve.coordinate_model, X=Mod(x, p), Z=Mod(1, p))
result = Point(curve25519.curve.coordinate_model, X=Mod(res, p), Z=Mod(1, p))

mult = LadderMultiplier(
curve25519.curve.coordinate_model.formulas["ladd-1987-m"],
curve25519.curve.coordinate_model.formulas["dbl-1987-m"],
# complete=False
)
fixed = int(Mod(scalar, curve25519.order))

mult.init(curve25519, point)
computed = mult.multiply(fixed)

point_aff = list(curve25519.curve.affine_lift_x(Mod(x, p)))[0]
result_aff = list(curve25519.curve.affine_lift_x(Mod(res, p)))[0]
computed_aff = curve25519.curve.affine_multiply(point_aff, scalar)

scale = curve25519.curve.coordinate_model.formulas["scale"]
converted = scale(p, computed, **curve25519.curve.parameters)[0]
assert computed_aff.x == result_aff.x
assert converted.X == result.X


@pytest.mark.parametrize(
"add,dbl,scale",
[
Expand Down

0 comments on commit e2bb0ab

Please sign in to comment.