diff options
| author | J08nY | 2023-08-27 23:31:26 +0200 |
|---|---|---|
| committer | J08nY | 2023-08-27 23:31:26 +0200 |
| commit | e786ae764596bffc92d9ed28250e3d134d03dd7e (patch) | |
| tree | 3c7fe3c8d73a72216b6684ab8fe3c34e52922fd2 | |
| parent | 54e9958c811a57b7adbc052cc86fedaa582c102f (diff) | |
| download | pyecsca-e786ae764596bffc92d9ed28250e3d134d03dd7e.tar.gz pyecsca-e786ae764596bffc92d9ed28250e3d134d03dd7e.tar.zst pyecsca-e786ae764596bffc92d9ed28250e3d134d03dd7e.zip | |
Fix RPA distinguish test.
| -rw-r--r-- | pyecsca/ec/configuration.py | 2 | ||||
| -rw-r--r-- | pyecsca/ec/mult/window.py | 2 | ||||
| -rw-r--r-- | pyecsca/ec/scalar.py | 23 | ||||
| -rw-r--r-- | test/sca/test_rpa.py | 10 |
4 files changed, 26 insertions, 11 deletions
diff --git a/pyecsca/ec/configuration.py b/pyecsca/ec/configuration.py index 0e3b338..1a7020e 100644 --- a/pyecsca/ec/configuration.py +++ b/pyecsca/ec/configuration.py @@ -127,7 +127,7 @@ def all_configurations(**kwargs) -> Generator[Configuration, Configuration, None .. warning:: The returned number of configurations might be quite large and take up significant - memory space. + memory space. Use this generator and do not store the results. :param kwargs: The configuration parameters to match. :return: A generator of the configurations. diff --git a/pyecsca/ec/mult/window.py b/pyecsca/ec/mult/window.py index 15126a7..8b1ae2c 100644 --- a/pyecsca/ec/mult/window.py +++ b/pyecsca/ec/mult/window.py @@ -16,7 +16,7 @@ from ..scalar import convert_base, sliding_window_rtl, sliding_window_ltr @public class SlidingWindowMultiplier(AccumulatorMultiplier, ScalarMultiplier): - """""" + """Sliding window scalar multiplier.""" requires = {AdditionFormula, DoublingFormula} optionals = {ScalingFormula} diff --git a/pyecsca/ec/scalar.py b/pyecsca/ec/scalar.py index d5f3d2a..c191160 100644 --- a/pyecsca/ec/scalar.py +++ b/pyecsca/ec/scalar.py @@ -9,9 +9,9 @@ def convert_base(i: int, base: int) -> List[int]: """ Convert an integer to base. - :param i: - :param base: - :return: + :param i: The scalar. + :param base: The base. + :return: The resulting digit list. """ if i == 0: return [0] @@ -28,9 +28,9 @@ def sliding_window_ltr(i: int, w: int) -> List[int]: Compute the sliding-window left-to-right form. From https://eprint.iacr.org/2017/627.pdf. - :param i: - :param w: - :return: + :param i: The scalar. + :param w: The width. + :return: The sliding-window LTR form. """ result: List[int] = [] b = i.bit_length() - 1 @@ -84,6 +84,17 @@ def wnaf(k: int, w: int) -> List[int]: """ Compute width `w` NAF (Non-Adjacent Form) of the scalar `k`. + Algorithm 9.35 from GECC, Algorithm 9.20 from HEHCC. + + .. note:: + According to HEHCC this is actually not unique + + A left-to-right variant to compute an NAFw expansion of an integer can be found both + in [AVA 2005a] and in [MUST 2005]. The result may differ from the expansion produced + by Algorithm 9.20 but they have the same digit set and the same optimal weight. + + According to GECC it is. + :param k: The scalar. :param w: The width. :return: The NAF. diff --git a/test/sca/test_rpa.py b/test/sca/test_rpa.py index daaf028..5187ccf 100644 --- a/test/sca/test_rpa.py +++ b/test/sca/test_rpa.py @@ -12,7 +12,7 @@ from pyecsca.ec.mult import ( RTLMultiplier, BinaryNAFMultiplier, WindowNAFMultiplier, - SimpleLadderMultiplier, AccumulationOrder, ProcessingDirection, + SimpleLadderMultiplier, AccumulationOrder, ProcessingDirection, SlidingWindowMultiplier, FixedWindowLTRMultiplier, ) from pyecsca.ec.params import DomainParameters from pyecsca.ec.point import Point @@ -79,8 +79,12 @@ def test_distinguish(secp128r1, add, dbl, neg): RTLMultiplier(add, dbl, None, True, AccumulationOrder.PeqRP, True), SimpleLadderMultiplier(add, dbl, None, True, True), BinaryNAFMultiplier(add, dbl, neg, None, ProcessingDirection.LTR, AccumulationOrder.PeqRP, True), - WindowNAFMultiplier(add, dbl, neg, 3, None, True), - WindowNAFMultiplier(add, dbl, neg, 4, None, True)] + WindowNAFMultiplier(add, dbl, neg, 3, None, AccumulationOrder.PeqRP, True), + WindowNAFMultiplier(add, dbl, neg, 4, None, AccumulationOrder.PeqRP, True), + SlidingWindowMultiplier(add, dbl, 3, None, ProcessingDirection.LTR, AccumulationOrder.PeqRP, True), + SlidingWindowMultiplier(add, dbl, 3, None, ProcessingDirection.RTL, AccumulationOrder.PeqRP, True), + FixedWindowLTRMultiplier(add, dbl, 3, None, AccumulationOrder.PeqRP, True), + FixedWindowLTRMultiplier(add, dbl, 8, None, AccumulationOrder.PeqRP, True)] for real_mult in multipliers: def simulated_oracle(scalar, affine_point): point = affine_point.to_model(secp128r1.curve.coordinate_model, secp128r1.curve) |
