Skip to content

Commit

Permalink
Improve pylint score
Browse files Browse the repository at this point in the history
  • Loading branch information
Jörn Heissler committed Dec 2, 2020
1 parent 938c9a1 commit 1393f0c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 7 deletions.
4 changes: 4 additions & 0 deletions pvss/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Public interface for PVSS
"""

from .pvss import Pvss

__version__ = "0.2.0"
4 changes: 4 additions & 0 deletions pvss/asn1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
ASN.1 data types for PVSS objects
"""

from __future__ import annotations

from typing import Any as _Any
Expand Down
6 changes: 5 additions & 1 deletion pvss/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def __repr__(self) -> str:


class PreGroupValue(ABC):
"""
Abstract pre-group value, e.g. some private key.
"""

group: PreGroup

@abstractmethod
Expand Down Expand Up @@ -204,7 +208,7 @@ def __repr__(self) -> str:

class ImageValue(ABC):
"""
Abstract image value, e.g. a curve point or a quadratic residue modulo p
Abstract image value, e.g. a curve point or a quadratic residue modulo p.
"""

group: ImageGroup
Expand Down
49 changes: 48 additions & 1 deletion pvss/pvss.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Implementation of PVSS algorithms.
"""

from __future__ import annotations

from abc import ABC, abstractmethod
Expand Down Expand Up @@ -73,7 +77,14 @@ def prod(items: Iterable[_T0], initializer: Optional[_T0] = None) -> _T0:


class Asn1Object(ABC):
"""
Abstract base class for all other PVSS ASN.1 objects.
"""

# Reference to PVSS object that holds all ASN.1 objects.
pvss: Pvss

# ASN.1 type. Child classes set a more concrete type.
asn1: Asn1Value

def __init__(self, pvss: Pvss, asn1: Asn1Value) -> None:
Expand Down Expand Up @@ -109,7 +120,14 @@ def __eq__(self, other: Any) -> bool:


class SystemParameters(Asn1Object):
"""
Base class for system parameter object.
Holds the group descriptions and generators.
"""

# Set by child class to denote one of the registered group algorithms.
ALGO: str

asn1: _asn1.SystemParameters

def __new__(cls, pvss: Pvss, asn1: _asn1.SystemParameters) -> SystemParameters:
Expand Down Expand Up @@ -163,6 +181,10 @@ def _make_gen(self, seed: str) -> ImageValue:


class PrivateKey(Asn1Object):
"""
Private user or receiver key.
"""

asn1: _asn1.PrivateKey

def _validate(self) -> None:
Expand All @@ -189,6 +211,10 @@ def pub(self, name: str) -> PublicKey:


class PublicKey(Asn1Object):
"""
Public user or receiver key.
"""

asn1: _asn1.PublicKey

def _validate(self) -> None:
Expand Down Expand Up @@ -217,6 +243,11 @@ def pub(self) -> Tuple[ImageValue, ImageValue]:


class Secret(Asn1Object):
"""
Secret that is protected through PVSS.
The DER encoding of this object can be used to protect some actual payload.
"""

asn1: _asn1.Secret

@classmethod
Expand Down Expand Up @@ -321,6 +352,10 @@ def _validate(self) -> None:


class SharedSecret(Asn1Object):
"""
All shares of a shared secret, along with Zero Knowledge proof.
"""

asn1: _asn1.SharedSecret

@classmethod
Expand Down Expand Up @@ -478,6 +513,10 @@ def create_shared_secret(


class ReencryptedShare(Asn1Object):
"""
Secret Share after reencryption.
"""

asn1: _asn1.ReencryptedShare

@classmethod
Expand Down Expand Up @@ -665,6 +704,10 @@ def challenge(self) -> int:


class SharesChallenge(Challenge):
"""
Zero-Knowledge challenge for "shared secret" message.
"""

asn1: _asn1.SharesChallenge

@classmethod
Expand Down Expand Up @@ -703,6 +746,10 @@ def create(


class ReencryptedChallenge(Challenge):
"""
Zero-Knowledge challenge for "reencrypted share" message.
"""

asn1: _asn1.ReencryptedChallenge

@classmethod
Expand Down Expand Up @@ -990,7 +1037,7 @@ def reconstruct_secret(self, der_private_key: ByteString) -> bytes:

class Poly(Sequence[PreGroupValue]):
"""
Polynomial
Polynomial with random coefficients.
"""

_coeffs: List[PreGroupValue]
Expand Down
10 changes: 5 additions & 5 deletions pvss/ristretto_255.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


# Order of the Ristretto255 group.
group_order = 2 ** 252 + 27742317777372353535851937790883648493
_RST_255_GROUP_ORDER = 2 ** 252 + 27742317777372353535851937790883648493


def create_ristretto_255_parameters(pvss: Pvss) -> bytes:
Expand Down Expand Up @@ -211,7 +211,7 @@ def from_hash(self, value: ByteString) -> Ristretto255Point:

@property
def len(self) -> int:
return group_order
return _RST_255_GROUP_ORDER

def __repr__(self) -> str:
return "Ristretto255Group()"
Expand Down Expand Up @@ -323,7 +323,7 @@ def __call__(self, value: Union[int, Asn1Value, Fraction]) -> Ristretto255Scalar

if isinstance(value, _asn1.PreGroupValue):
value = int(value)
if not 0 <= value < group_order:
if not 0 <= value < _RST_255_GROUP_ORDER:
raise ValueError("Not a valid group element")
res = ctypes.create_string_buffer(value.to_bytes(32, "little"), 32)
return Ristretto255Scalar(self, res)
Expand Down Expand Up @@ -358,7 +358,7 @@ def len(self) -> int:
group size
"""

return group_order
return _RST_255_GROUP_ORDER

@property
def rand(self) -> Ristretto255Scalar:
Expand All @@ -369,7 +369,7 @@ def rand(self) -> Ristretto255Scalar:
Random group element
"""

value = randbelow(group_order)
value = randbelow(_RST_255_GROUP_ORDER)
res = ctypes.create_string_buffer(value.to_bytes(32, "little"), 32)
return Ristretto255Scalar(self, res)

Expand Down
1 change: 1 addition & 0 deletions pvss/zq.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""
Integers modulo prime q
"""

from __future__ import annotations
Expand Down

0 comments on commit 1393f0c

Please sign in to comment.