From 2e336566fbe3a603b5565142f5112880035be7f1 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Mon, 6 Dec 2021 14:56:01 +0300 Subject: [PATCH] Human readable curve name --- news.texi | 4 ++++ pygost/__init__.py | 2 +- pygost/gost3410.py | 9 ++++++++- pygost/stubs/pygost/gost3410.pyi | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/news.texi b/news.texi index f5752e6..6ad35a0 100644 --- a/news.texi +++ b/news.texi @@ -3,6 +3,10 @@ @table @strong +@anchor{Release 5.8} +@item 5.8 +Added human-readable name of the curve in @code{GOST3410Curve.name}. + @anchor{Release 5.7} @item 5.7 Fixed MGM ignoring of the set tag size. diff --git a/pygost/__init__.py b/pygost/__init__.py index 12d2bad..497345c 100644 --- a/pygost/__init__.py +++ b/pygost/__init__.py @@ -3,4 +3,4 @@ PyGOST is free software: see the file COPYING for copying conditions. """ -__version__ = "5.7" +__version__ = "5.8" diff --git a/pygost/gost3410.py b/pygost/gost3410.py index f4c0538..96520cb 100644 --- a/pygost/gost3410.py +++ b/pygost/gost3410.py @@ -53,8 +53,9 @@ class GOST3410Curve(object): the canonical form :param long e, d: coefficients of the equation of the elliptic curve in the twisted Edwards form + :param str name: human-readable curve name """ - def __init__(self, p, q, a, b, x, y, cofactor=1, e=None, d=None): + def __init__(self, p, q, a, b, x, y, cofactor=1, e=None, d=None, name=None): self.p = p self.q = q self.a = a @@ -67,11 +68,15 @@ class GOST3410Curve(object): if not self.contains((x, y)): raise ValueError("Invalid parameters") self._st = None + self.name = name @property def point_size(self): return point_size(self.p) + def __repr__(self): + return "<%s: %s>" % (self.__class__.__name__, self.name) + def pos(self, v): """Make positive number """ @@ -231,6 +236,8 @@ CURVES["id-tc26-gost-3410-2012-512-paramSetTest"] = CURVES["id-tc26-gost-3410-12 CURVES["id-tc26-gost-3410-2012-512-paramSetA"] = CURVES["id-tc26-gost-3410-12-512-paramSetA"] CURVES["id-tc26-gost-3410-2012-512-paramSetB"] = CURVES["id-tc26-gost-3410-12-512-paramSetB"] CURVES["id-tc26-gost-3410-2012-512-paramSetC"] = CURVES["id-tc26-gost-3410-12-512-paramSetC"] +for name, curve in CURVES.items(): + curve.name = name DEFAULT_CURVE = CURVES["id-tc26-gost-3410-12-256-paramSetB"] diff --git a/pygost/stubs/pygost/gost3410.pyi b/pygost/stubs/pygost/gost3410.pyi index 345a3e6..8f0dcb8 100644 --- a/pygost/stubs/pygost/gost3410.pyi +++ b/pygost/stubs/pygost/gost3410.pyi @@ -17,6 +17,7 @@ class GOST3410Curve(object): cofactor = ... # type: int e = ... # type: int d = ... # type: int + name = ... # type: str def __init__( self, @@ -29,6 +30,7 @@ class GOST3410Curve(object): cofactor: int = 1, e: int = None, d: int = None, + name: str = None, ) -> None: ... def pos(self, v: int) -> int: ... -- 2.44.0