aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/codegen/client.py
diff options
context:
space:
mode:
authorJ08nY2020-02-28 17:25:51 +0100
committerJ08nY2020-02-28 17:35:08 +0100
commit0341d359dc67ced3f1e65d1d11af3590c1f0992f (patch)
tree660140e64e8abe7647554e1424b1678a3ab98631 /pyecsca/codegen/client.py
parentb387d00511a03dc20e15ac55fcbf07f3dfa79ce0 (diff)
downloadpyecsca-codegen-0341d359dc67ced3f1e65d1d11af3590c1f0992f.tar.gz
pyecsca-codegen-0341d359dc67ced3f1e65d1d11af3590c1f0992f.tar.zst
pyecsca-codegen-0341d359dc67ced3f1e65d1d11af3590c1f0992f.zip
Add dynamic triggering.
Diffstat (limited to 'pyecsca/codegen/client.py')
-rw-r--r--pyecsca/codegen/client.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/pyecsca/codegen/client.py b/pyecsca/codegen/client.py
index c9f7b67..6eaec79 100644
--- a/pyecsca/codegen/client.py
+++ b/pyecsca/codegen/client.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
import re
from binascii import hexlify, unhexlify
+from enum import IntFlag
from os import path
from typing import Mapping, Union, Optional, Tuple
@@ -21,6 +22,23 @@ from pyecsca.sca.target import (SimpleSerialTarget, ChipWhispererTarget, BinaryT
from .common import wrap_enum, Platform, get_model, get_coords
+class Triggers(IntFlag):
+ add = 1 << 0
+ dadd = 1 << 1
+ dbl = 1 << 2
+ ladd = 1 << 3
+ neg = 1 << 4
+ scl = 1 << 5
+ tpl = 1 << 6
+ mult = 1 << 7
+ keygen = 1 << 8
+ ecdh = 1 << 9
+ ecdsa_sign = 1 << 10
+ ecdsa_verify = 1 << 11
+ coord_map = 1 << 12
+ random_mod = 1 << 13
+
+
def encode_scalar(val: Union[int, Mod]) -> bytes:
if isinstance(val, int):
return val.to_bytes((val.bit_length() + 7) // 8, "big")
@@ -120,6 +138,12 @@ def cmd_ecdsa_verify(data: bytes, sig: bytes) -> str:
@public
+def cmd_set_trigger(actions: Triggers) -> str:
+ vector_bytes = actions.to_bytes(4, "little")
+ return "t" + hexlify(vector_bytes)
+
+
+@public
def cmd_debug() -> str:
return "d"
@@ -131,6 +155,7 @@ class ImplTarget(SimpleSerialTarget):
params: Optional[DomainParameters]
privkey: Optional[int]
pubkey: Optional[Point]
+ trigger: Optional[Triggers]
timeout: int
def __init__(self, model: CurveModel, coords: CoordinateModel, **kwargs):
@@ -145,6 +170,7 @@ class ImplTarget(SimpleSerialTarget):
self.params = None
self.privkey = None
self.pubkey = None
+ self.trigger = None
def init_prng(self, seed: bytes) -> None:
self.send_cmd(SMessage.from_raw(cmd_init_prng(seed)), self.timeout)
@@ -203,6 +229,10 @@ class ImplTarget(SimpleSerialTarget):
model, coords = unhexlify(resp.data).decode().split(",")
return model, coords
+ def set_trigger(self, actions: Triggers) -> None:
+ self.send_cmd(SMessage.from_raw(cmd_set_trigger(actions)), self.timeout)
+ self.trigger = actions
+
def disconnect(self):
self.write(b"x\n")
super().disconnect()