Exemplo n.º 1
0
 def test_debug(self):
     target_path = join(dirname(realpath(__file__)), "..", "data",
                        "target.py")
     target = TestTarget(["python", target_path], debug_output=True)
     target.connect()
     target.send_cmd(SimpleSerialMessage("d", ""), 500)
     target.disconnect()
Exemplo n.º 2
0
 def scalar_mult(self, scalar: int, point: Point) -> Point:
     resp = self.send_cmd(SMessage.from_raw(cmd_scalar_mult(scalar, point)), self.timeout)
     result = resp["w"]
     plen = ((self.params.curve.prime.bit_length() + 7) // 8) * 2
     params = {var: Mod(int(result.data[i * plen:(i + 1) * plen], 16), self.params.curve.prime)
               for
               i, var in enumerate(self.coords.variables)}
     return Point(self.coords, **params)
Exemplo n.º 3
0
 def test_basic_target(self):
     target_path = join(dirname(realpath(__file__)), "..", "data", "target.py")
     target = TestTarget(["python", target_path])
     target.connect()
     resp = target.send_cmd(SimpleSerialMessage("d", ""), 500)
     self.assertIn("r", resp)
     self.assertIn("z", resp)
     self.assertEqual(resp["r"].data, "01020304")
     target.disconnect()
Exemplo n.º 4
0
 def generate(self) -> Tuple[int, Point]:
     resp = self.send_cmd(SMessage.from_raw(cmd_generate()), self.timeout)
     priv = resp["s"].data
     pub = resp["w"].data
     self.privkey = int(priv, 16)
     pub_len = len(pub)
     x = int(pub[:pub_len // 2], 16)
     y = int(pub[pub_len // 2:], 16)
     self.pubkey = Point(AffineCoordinateModel(self.model), x=Mod(x, self.params.curve.prime),
                         y=Mod(y, self.params.curve.prime))
     return self.privkey, self.pubkey
Exemplo n.º 5
0
 def set_trigger(self, actions: Triggers) -> None:
     self.send_cmd(SMessage.from_raw(cmd_set_trigger(actions)), self.timeout)
     self.trigger = actions
Exemplo n.º 6
0
 def debug(self) -> Tuple[str, str]:
     resp = self.send_cmd(SMessage.from_raw(cmd_debug()), self.timeout)["d"]
     model, coords = unhexlify(resp.data).decode().split(",")
     return model, coords
Exemplo n.º 7
0
 def ecdsa_verify(self, data: bytes, signature: bytes) -> bool:
     resp = self.send_cmd(SMessage.from_raw(cmd_ecdsa_verify(data, signature)), self.timeout)
     result = resp["v"]
     return unhexlify(result.data)[0] == 1
Exemplo n.º 8
0
 def ecdsa_sign(self, data: bytes) -> bytes:
     resp = self.send_cmd(SMessage.from_raw(cmd_ecdsa_sign(data)), self.timeout)
     signature = resp["s"]
     return unhexlify(signature.data)
Exemplo n.º 9
0
 def ecdh(self, other_pubkey: Point) -> bytes:
     resp = self.send_cmd(SMessage.from_raw(cmd_ecdh(other_pubkey)), self.timeout)
     result = resp["r"]
     return unhexlify(result.data)
Exemplo n.º 10
0
 def set_pubkey(self, pubkey: Point) -> None:
     self.send_cmd(SMessage.from_raw(cmd_set_pubkey(pubkey)), self.timeout)
     self.pubkey = pubkey
Exemplo n.º 11
0
 def set_privkey(self, privkey: int) -> None:
     self.send_cmd(SMessage.from_raw(cmd_set_privkey(privkey)), self.timeout)
     self.privkey = privkey
Exemplo n.º 12
0
 def set_params(self, params: DomainParameters) -> None:
     self.send_cmd(SMessage.from_raw(cmd_set_params(params)), self.timeout)
     self.params = params
Exemplo n.º 13
0
 def init_prng(self, seed: bytes) -> None:
     self.send_cmd(SMessage.from_raw(cmd_init_prng(seed)), self.timeout)
     self.seed = seed