Skip to content

Commit

Permalink
Cache public key in the secret key to speed up generate_kfrags()
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Mar 27, 2021
1 parent f349de5 commit aef69de
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion umbral/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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]:
Expand Down

0 comments on commit aef69de

Please sign in to comment.