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 28, 2021
1 parent a08a552 commit 7d0f2fe
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(Serializable):

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 @@ -130,7 +135,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 7d0f2fe

Please sign in to comment.