diff options
| author | J08nY | 2025-03-13 19:38:48 +0100 |
|---|---|---|
| committer | J08nY | 2025-03-13 19:38:48 +0100 |
| commit | 7c2f12a0111de33330870b2179b71281b59ada29 (patch) | |
| tree | 80beb7f4e3090a4805d7aa20ffba5cbcc0078902 /pyecsca/sca/target | |
| parent | eccc58127b4c0c10f50e4d05e699d3585391e8a1 (diff) | |
| download | pyecsca-7c2f12a0111de33330870b2179b71281b59ada29.tar.gz pyecsca-7c2f12a0111de33330870b2179b71281b59ada29.tar.zst pyecsca-7c2f12a0111de33330870b2179b71281b59ada29.zip | |
Diffstat (limited to 'pyecsca/sca/target')
| -rw-r--r-- | pyecsca/sca/target/ISO7816.py | 35 | ||||
| -rw-r--r-- | pyecsca/sca/target/PCSC.py | 11 | ||||
| -rw-r--r-- | pyecsca/sca/target/base.py | 1 | ||||
| -rw-r--r-- | pyecsca/sca/target/binary.py | 1 | ||||
| -rw-r--r-- | pyecsca/sca/target/chipwhisperer.py | 5 | ||||
| -rw-r--r-- | pyecsca/sca/target/ectester.py | 1 | ||||
| -rw-r--r-- | pyecsca/sca/target/flash.py | 1 | ||||
| -rw-r--r-- | pyecsca/sca/target/leakage.py | 4 | ||||
| -rw-r--r-- | pyecsca/sca/target/leia.py | 11 | ||||
| -rw-r--r-- | pyecsca/sca/target/serial.py | 1 | ||||
| -rw-r--r-- | pyecsca/sca/target/simpleserial.py | 1 |
11 files changed, 46 insertions, 26 deletions
diff --git a/pyecsca/sca/target/ISO7816.py b/pyecsca/sca/target/ISO7816.py index 0af78db..950aa05 100644 --- a/pyecsca/sca/target/ISO7816.py +++ b/pyecsca/sca/target/ISO7816.py @@ -1,4 +1,5 @@ """Provides classes for working with ISO7816-4 APDUs and an abstract base class for an ISO7816-4 based target.""" + from abc import abstractmethod, ABC from dataclasses import dataclass from enum import IntEnum @@ -12,12 +13,14 @@ from pyecsca.sca.target.base import Target @public class CardConnectionException(Exception): """Card could not be connected.""" + pass @public class CardProtocol(IntEnum): """Card protocol to use/negotiate.""" + T0 = 0 T1 = 1 @@ -59,35 +62,35 @@ class CommandAPDU: # pragma: no cover if len(self.data) <= 255: # Case 3s return ( - bytes([self.cls, self.ins, self.p1, self.p2, len(self.data)]) - + self.data + bytes([self.cls, self.ins, self.p1, self.p2, len(self.data)]) + + self.data ) else: # Case 3e return ( - bytes([self.cls, self.ins, self.p1, self.p2, 0]) - + len(self.data).to_bytes(2, "big") - + self.data + bytes([self.cls, self.ins, self.p1, self.p2, 0]) + + len(self.data).to_bytes(2, "big") + + self.data ) else: if len(self.data) <= 255 and self.ne <= 256: # Case 4s return ( - bytes([self.cls, self.ins, self.p1, self.p2, len(self.data)]) - + self.data - + bytes([self.ne if self.ne != 256 else 0]) + bytes([self.cls, self.ins, self.p1, self.p2, len(self.data)]) + + self.data + + bytes([self.ne if self.ne != 256 else 0]) ) else: # Case 4e return ( - bytes([self.cls, self.ins, self.p1, self.p2, 0]) - + len(self.data).to_bytes(2, "big") - + self.data - + ( - self.ne.to_bytes(2, "big") - if self.ne != 65536 - else bytes([0, 0]) - ) + bytes([self.cls, self.ins, self.p1, self.p2, 0]) + + len(self.data).to_bytes(2, "big") + + self.data + + ( + self.ne.to_bytes(2, "big") + if self.ne != 65536 + else bytes([0, 0]) + ) ) diff --git a/pyecsca/sca/target/PCSC.py b/pyecsca/sca/target/PCSC.py index cd74149..53b04fa 100644 --- a/pyecsca/sca/target/PCSC.py +++ b/pyecsca/sca/target/PCSC.py @@ -1,4 +1,5 @@ """Provides a smartcard target communicating via PC/SC (Personal Computer/Smart Card).""" + from typing import Union, Optional from public import public @@ -7,8 +8,14 @@ from smartcard.System import readers from smartcard.pcsc.PCSCCardConnection import PCSCCardConnection from smartcard.pcsc.PCSCReader import PCSCReader -from pyecsca.sca.target.ISO7816 import ISO7816Target, CommandAPDU, ResponseAPDU, ISO7816, CardProtocol, \ - CardConnectionException +from pyecsca.sca.target.ISO7816 import ( + ISO7816Target, + CommandAPDU, + ResponseAPDU, + ISO7816, + CardProtocol, + CardConnectionException, +) @public diff --git a/pyecsca/sca/target/base.py b/pyecsca/sca/target/base.py index 53106d5..7cb1a75 100644 --- a/pyecsca/sca/target/base.py +++ b/pyecsca/sca/target/base.py @@ -1,4 +1,5 @@ """Provides an abstract base class for targets.""" + from abc import ABC, abstractmethod from public import public diff --git a/pyecsca/sca/target/binary.py b/pyecsca/sca/target/binary.py index 0dd22d5..dcfe704 100644 --- a/pyecsca/sca/target/binary.py +++ b/pyecsca/sca/target/binary.py @@ -1,4 +1,5 @@ """Provides a binary target class which represents a target that is a runnable binary on the host.""" + import subprocess from subprocess import Popen from typing import Optional, Union, List diff --git a/pyecsca/sca/target/chipwhisperer.py b/pyecsca/sca/target/chipwhisperer.py index 28a2cb8..30b4a86 100644 --- a/pyecsca/sca/target/chipwhisperer.py +++ b/pyecsca/sca/target/chipwhisperer.py @@ -5,6 +5,7 @@ ChipWhisperer is a side-channel analysis tool and framework. A ChipWhisperer tar that uses the ChipWhisperer's SimpleSerial communication protocol and is communicated with using ChipWhisperer-Lite or Pro. """ + from time import sleep import chipwhisperer as cw @@ -20,9 +21,7 @@ from pyecsca.sca.target.simpleserial import SimpleSerialTarget class ChipWhispererTarget(Flashable, SimpleSerialTarget): # pragma: no cover """ChipWhisperer-based target, using the SimpleSerial-ish protocol and communicating using ChipWhisperer-Lite/Pro.""" - def __init__( - self, target: SimpleSerial, scope: ScopeTypes, programmer, **kwargs - ): + def __init__(self, target: SimpleSerial, scope: ScopeTypes, programmer, **kwargs): super().__init__() self.target = target self.scope = scope diff --git a/pyecsca/sca/target/ectester.py b/pyecsca/sca/target/ectester.py index ec00502..5ab5d7e 100644 --- a/pyecsca/sca/target/ectester.py +++ b/pyecsca/sca/target/ectester.py @@ -1,4 +1,5 @@ """Provides an `ECTester <https://github.com/crocs-muni/ECTester/>`_ target class.""" + from abc import ABC from binascii import hexlify from enum import IntEnum, IntFlag diff --git a/pyecsca/sca/target/flash.py b/pyecsca/sca/target/flash.py index 95c078d..8ab1883 100644 --- a/pyecsca/sca/target/flash.py +++ b/pyecsca/sca/target/flash.py @@ -1,4 +1,5 @@ """Provides a mix-in class of a flashable target (e.g. one where the code gets flashed to it before running).""" + from public import public from abc import ABC, abstractmethod diff --git a/pyecsca/sca/target/leakage.py b/pyecsca/sca/target/leakage.py index 6487c56..a44f48f 100644 --- a/pyecsca/sca/target/leakage.py +++ b/pyecsca/sca/target/leakage.py @@ -121,9 +121,7 @@ class LeakageTarget(Target): if self.privkey is None: raise ValueError("Missing privkey") with local(DefaultContext()) as ctx: - ecdh = ECDH( - self.mult, self.params, other_pubkey, self.privkey, hash_algo - ) + ecdh = ECDH(self.mult, self.params, other_pubkey, self.privkey, hash_algo) shared_secret = ecdh.perform() return shared_secret, self.get_trace(ctx) diff --git a/pyecsca/sca/target/leia.py b/pyecsca/sca/target/leia.py index 59336b6..5bd19af 100644 --- a/pyecsca/sca/target/leia.py +++ b/pyecsca/sca/target/leia.py @@ -1,10 +1,17 @@ """Provides a smartcard target communicating via the LEIA board in solo mode.""" + from typing import Optional from smartleia import LEIA, create_APDU_from_bytes, T -from pyecsca.sca.target.ISO7816 import ISO7816Target, CommandAPDU, ResponseAPDU, ISO7816, CardProtocol, \ - CardConnectionException +from pyecsca.sca.target.ISO7816 import ( + ISO7816Target, + CommandAPDU, + ResponseAPDU, + ISO7816, + CardProtocol, + CardConnectionException, +) class LEIATarget(ISO7816Target): # pragma: no cover diff --git a/pyecsca/sca/target/serial.py b/pyecsca/sca/target/serial.py index 62dea45..a9dbdac 100644 --- a/pyecsca/sca/target/serial.py +++ b/pyecsca/sca/target/serial.py @@ -1,4 +1,5 @@ """Provides an abstract serial target, that communicates by writing and reading a stream of bytes.""" + from abc import abstractmethod from public import public diff --git a/pyecsca/sca/target/simpleserial.py b/pyecsca/sca/target/simpleserial.py index f13a0a6..d28f697 100644 --- a/pyecsca/sca/target/simpleserial.py +++ b/pyecsca/sca/target/simpleserial.py @@ -1,4 +1,5 @@ """Provides an abstract target class communicating using the `ChipWhisperer's <https://github.com/newaetech/chipwhisperer/>`_ SimpleSerial protocol.""" + from abc import ABC from time import time_ns, sleep from typing import Mapping, Union |
