diff --git a/umbral/keys.py b/umbral/keys.py index 29b46f36..e28bce82 100644 --- a/umbral/keys.py +++ b/umbral/keys.py @@ -25,6 +25,11 @@ class SecretKey: def __init__(self, scalar_key: CurveScalar): self._scalar_key = scalar_key + # Cached public key. Access it via `PublicKey.from_secret_key()` - + # it may be removed later. + # We are assuming here that there will be on average more calls to + # `PublicKey.from_secret_key()` than secret key instantiations. + self._public_key_point = CurvePoint.generator() * self._scalar_key @classmethod def random(cls) -> 'SecretKey': @@ -124,7 +129,7 @@ def from_secret_key(cls, sk: SecretKey) -> 'PublicKey': """ Creates the public key corresponding to the given secret key. """ - return cls(CurvePoint.generator() * sk.secret_scalar()) + return cls(sk._public_key_point) @classmethod def __take__(cls, data: bytes) -> Tuple['PublicKey', bytes]: