aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/codegen/client.py
diff options
context:
space:
mode:
authorJ08nY2019-12-23 02:05:35 +0100
committerJ08nY2019-12-23 02:05:35 +0100
commitb43c5dba0ec18fe5a5204537855ea2b73fc674c6 (patch)
tree879c946cb9036f6db721fc44c37635c295ee2003 /pyecsca/codegen/client.py
parent878d95c4e4dadf882a205316a07bc0642f773256 (diff)
downloadpyecsca-codegen-b43c5dba0ec18fe5a5204537855ea2b73fc674c6.tar.gz
pyecsca-codegen-b43c5dba0ec18fe5a5204537855ea2b73fc674c6.tar.zst
pyecsca-codegen-b43c5dba0ec18fe5a5204537855ea2b73fc674c6.zip
Implement multipliers.
Diffstat (limited to 'pyecsca/codegen/client.py')
-rw-r--r--pyecsca/codegen/client.py78
1 files changed, 63 insertions, 15 deletions
diff --git a/pyecsca/codegen/client.py b/pyecsca/codegen/client.py
index 9d839fb..964487b 100644
--- a/pyecsca/codegen/client.py
+++ b/pyecsca/codegen/client.py
@@ -8,6 +8,7 @@ from pyecsca.ec.curve import EllipticCurve
from pyecsca.ec.group import AbelianGroup
from pyecsca.ec.mod import Mod
from pyecsca.ec.model import ShortWeierstrassModel
+from pyecsca.ec.mult import LTRMultiplier
from pyecsca.ec.point import Point
@@ -67,24 +68,71 @@ def cmd_set_curve(group: AbelianGroup) -> str:
return "c" + hexlify(encode_data(None, data)).decode()
+def cmd_generate() -> str:
+ return "g"
+
+
+def cmd_set_privkey(privkey: int) -> str:
+ return "s" + hexlify(encode_data(None, {"s": encode_scalar(privkey)})).decode()
+
+
+def cmd_set_pubkey(pubkey: Point) -> str:
+ return "w" + hexlify(encode_data(None, {"w": encode_point(pubkey)})).decode()
+
+
+def cmd_scalar_mult(scalar: int) -> str:
+ return "m" + hexlify(encode_data(None, {"s": encode_scalar(scalar)})).decode()
+
+
+def cmd_ecdh(pubkey: Point) -> str:
+ return "e" + hexlify(encode_data(None, {"w": encode_point(pubkey)})).decode()
+
+
+def cmd_ecdsa_sign(data: bytes) -> str:
+ return "a" + hexlify(encode_data(None, {"d": data})).decode()
+
+
+def cmd_ecdsa_verify(data: bytes, sig: bytes) -> str:
+ return "v" + hexlify(encode_data(None, {"d": data, "s": sig})).decode()
+
+
@click.command()
@click.version_option()
def main():
- model = ShortWeierstrassModel()
- coords = model.coordinates["projective"]
- p = 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff
- curve = EllipticCurve(model, coords,
- p,
- {"a": 0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc,
- "b": 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b})
- affine_g = Point(AffineCoordinateModel(model),
- x=Mod(0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296, p),
- y=Mod(0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5, p))
- g = Point.from_affine(coords, affine_g)
- neutral = Point(coords, X=Mod(0, p), Y=Mod(1, p), Z=Mod(0, p))
- group = AbelianGroup(curve, g, neutral,
- 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551, 0x1)
- print(cmd_set_curve(group))
+ pass
+ # model = ShortWeierstrassModel()
+ # coords = model.coordinates["projective"]
+ # p = 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff
+ # curve = EllipticCurve(model, coords,
+ # p,
+ # {"a": 0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc,
+ # "b": 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b})
+ # affine_g = Point(AffineCoordinateModel(model),
+ # x=Mod(0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296, p),
+ # y=Mod(0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5, p))
+ # g = Point.from_affine(coords, affine_g)
+ # neutral = Point(coords, X=Mod(0, p), Y=Mod(1, p), Z=Mod(0, p))
+ # group = AbelianGroup(curve, g, neutral,
+ # 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551, 0x1)
+ #
+ # print(cmd_set_curve(group))
+ # mul = LTRMultiplier(coords.formulas["add-1998-cmo"], coords.formulas["dbl-1998-cmo"], coords.formulas["z"])
+ # mul.init(group, g)
+ # res = mul.multiply(0x2EF035DF6D0634C7422161D08BCC794B5312E042DDB32B0135A4DE6E6345A555)
+ # rx = Mod(0x77E3FF34C12571970845CBEB1BE0A79E3ECEE187510C2B8894BA800F8164C954, p)
+ # ry = Mod(0x408A6A05607F9ACA97BB9A34EA643B107AADE0C9BB5EDB930EADE3009666B9D1, p)
+ # rz = Mod(0xC66ECD687C335D63A7030434CA70351191BAFF1C206332EFEA39FA3003E91646, p)
+ #
+ # ox = Mod(0x3B1E7733E3250C97EB9D00AE0394F0768902DD337FEAAF7C4F6B9588462920DD, p)
+ # oy = Mod(0xBA718497596C964E77F9666506505B1E730EE69D254E85AD44727DFFB2C7063E, p)
+ # oz = Mod(0x0000000000000000000000000000000000000000000000000000000000000001, p)
+ #
+ # pt = Point(coords, X=rx, Y=ry, Z=rz)
+ # ot = Point(coords, X=ox, Y=oy, Z=oz)
+ # print(ot, res)
+ # print(pt.equals(res))
+ # print(ot.equals(res))
+ # print(ot == res)
if __name__ == "__main__":