aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--pyecsca/ec/context.py9
-rw-r--r--pyecsca/ec/mod.py6
-rw-r--r--pyecsca/sca/scope/picoscope_alt.py3
-rw-r--r--pyecsca/sca/scope/picoscope_sdk.py50
-rw-r--r--test/ec/test_mod.py6
5 files changed, 72 insertions, 2 deletions
diff --git a/pyecsca/ec/context.py b/pyecsca/ec/context.py
index 144ca92..02c8a6d 100644
--- a/pyecsca/ec/context.py
+++ b/pyecsca/ec/context.py
@@ -195,13 +195,20 @@ class PathContext(Context):
self.current.pop()
self.current_depth -= 1
-
def __init__(self, path: Sequence[int]):
+ """
+ Create a :py:class:`PathContext`.
+
+ :param path: The path of an action in the execution tree that will be captured.
+ """
self.path = list(path)
self.current = []
self.current_depth = 0
self.value = None
+ def __repr__(self):
+ return f"{self.__class__.__name__}({self.current!r}, depth={self.current_depth!r})"
+
_actual_context: ContextVar[Context] = ContextVar("operational_context", default=NullContext())
diff --git a/pyecsca/ec/mod.py b/pyecsca/ec/mod.py
index f59fcf4..fa5f866 100644
--- a/pyecsca/ec/mod.py
+++ b/pyecsca/ec/mod.py
@@ -239,6 +239,12 @@ class Mod(object):
def __pow__(self, n):
if type(n) is not int:
raise TypeError
+ if n == 0:
+ return Mod(1, self.n)
+ if n < 0:
+ return self.inverse()**(-n)
+ if n == 1:
+ return Mod(self.x, self.n)
q = self
r = self if n & 1 else Mod(1, self.n)
diff --git a/pyecsca/sca/scope/picoscope_alt.py b/pyecsca/sca/scope/picoscope_alt.py
index f93c997..7c96f8b 100644
--- a/pyecsca/sca/scope/picoscope_alt.py
+++ b/pyecsca/sca/scope/picoscope_alt.py
@@ -1,6 +1,7 @@
from time import time_ns, sleep
from typing import Optional, Tuple, Sequence, Union
+from picoscope.ps3000 import PS3000
from picoscope.ps4000 import PS4000
from picoscope.ps5000 import PS5000
from picoscope.ps6000 import PS6000
@@ -13,7 +14,7 @@ from ..trace import Trace
@public
class PicoScopeAlt(Scope): # pragma: no cover
- def __init__(self, ps: Union[PS4000, PS5000, PS6000]):
+ def __init__(self, ps: Union[PS3000, PS4000, PS5000, PS6000]):
super().__init__()
self.ps = ps
self.trig_ratio: float = 0.0
diff --git a/pyecsca/sca/scope/picoscope_sdk.py b/pyecsca/sca/scope/picoscope_sdk.py
index 0ec59c9..503f57d 100644
--- a/pyecsca/sca/scope/picoscope_sdk.py
+++ b/pyecsca/sca/scope/picoscope_sdk.py
@@ -6,6 +6,7 @@ from typing import Mapping, Optional, MutableMapping, Union, Tuple
import numpy as np
from picosdk.functions import assert_pico_ok
from picosdk.library import Library
+from picosdk.ps3000 import ps3000
from picosdk.ps4000 import ps4000
from picosdk.ps5000 import ps5000
from picosdk.ps6000 import ps6000
@@ -200,6 +201,55 @@ class PicoScopeSdk(Scope): # pragma: no cover
@public
+class PS3000Scope(PicoScopeSdk): # pragma: no cover
+ MODULE = ps3000
+ PREFIX = "ps3000"
+ CHANNELS = {
+ "A": ps3000.PS3000_CHANNEL["PS3000_CHANNEL_A"],
+ "B": ps3000.PS3000_CHANNEL["PS3000_CHANNEL_B"],
+ "C": ps3000.PS3000_CHANNEL["PS3000_CHANNEL_C"],
+ "D": ps3000.PS3000_CHANNEL["PS3000_CHANNEL_D"]
+ }
+
+ RANGES = {
+ 0.02: ps3000.PS3000_RANGE["PS3000_20MV"],
+ 0.05: ps3000.PS3000_RANGE["PS3000_50MV"],
+ 0.10: ps3000.PS3000_RANGE["PS3000_100MV"],
+ 0.20: ps3000.PS3000_RANGE["PS3000_200MV"],
+ 0.50: ps3000.PS3000_RANGE["PS3000_500MV"],
+ 1.00: ps3000.PS3000_RANGE["PS3000_1V"],
+ 2.00: ps3000.PS3000_RANGE["PS3000_2V"],
+ 5.00: ps3000.PS3000_RANGE["PS3000_5V"],
+ 10.0: ps3000.PS3000_RANGE["PS3000_10V"],
+ 20.0: ps3000.PS3000_RANGE["PS3000_20V"],
+ 50.0: ps3000.PS3000_RANGE["PS3000_50V"],
+ 100.0: ps3000.PS3000_RANGE["PS3000_100V"],
+ 200.0: ps3000.PS3000_RANGE["PS3000_200V"],
+ 400.0: ps3000.PS3000_RANGE["PS3000_400V"]
+ }
+
+ MAX_ADC_VALUE = 32764 # TODO: fix
+ MIN_ADC_VALUE = -32764 # TODO: fix
+
+ COUPLING = {
+ "AC": ps3000.PICO_COUPLING["AC"],
+ "DC": ps3000.PICO_COUPLING["DC"]
+ }
+
+ def set_frequency(self, frequency: int, pretrig: int, posttrig: int): # TODO: fix
+ variant = self.get_variant()
+ if variant in ("4223", "4224", "4423", "4424"):
+ return self._set_freq(frequency, pretrig, posttrig, 50e-9, 2, 80_000_000, 20_000_000, 1)
+ elif variant in ("4226", "4227"):
+ return self._set_freq(frequency, pretrig, posttrig, 32e-9, 3, 250_000_000, 31_250_000,
+ 2)
+ elif variant == "4262":
+ return self._set_freq(frequency, pretrig, posttrig, 0, 0, 0, 10_000_000, -1)
+
+
+
+
+@public
class PS4000Scope(PicoScopeSdk): # pragma: no cover
MODULE = ps4000
PREFIX = "ps4000"
diff --git a/test/ec/test_mod.py b/test/ec/test_mod.py
index db54456..399af11 100644
--- a/test/ec/test_mod.py
+++ b/test/ec/test_mod.py
@@ -37,6 +37,12 @@ class ModTests(TestCase):
self.assertNotEqual(Mod(1, 7), Mod(5, 7))
self.assertNotEqual(Mod(1, 7), Mod(1, 5))
+ def test_pow(self):
+ a = Mod(5, 7)
+ self.assertEqual(a**(-1), a.inverse())
+ self.assertEqual(a**0, Mod(1, 7))
+ self.assertEqual(a**(-2),a.inverse()**2)
+
def test_wrong_mod(self):
a = Mod(5, 7)
b = Mod(4, 11)