aboutsummaryrefslogtreecommitdiff
path: root/frozen_deps/ecdsa/ecdh.py
diff options
context:
space:
mode:
Diffstat (limited to 'frozen_deps/ecdsa/ecdh.py')
-rw-r--r--frozen_deps/ecdsa/ecdh.py37
1 files changed, 23 insertions, 14 deletions
diff --git a/frozen_deps/ecdsa/ecdh.py b/frozen_deps/ecdsa/ecdh.py
index 9173279..7f697d9 100644
--- a/frozen_deps/ecdsa/ecdh.py
+++ b/frozen_deps/ecdsa/ecdh.py
@@ -116,7 +116,7 @@ class ECDH(object):
:raises NoCurveError: Curve must be set before key generation.
:return: public (verifying) key from this private key.
- :rtype: VerifyingKey object
+ :rtype: VerifyingKey
"""
if not self.curve:
raise NoCurveError("Curve must be set prior to key generation.")
@@ -135,7 +135,7 @@ class ECDH(object):
:raises InvalidCurveError: private_key curve not the same as self.curve
:return: public (verifying) key from this private key.
- :rtype: VerifyingKey object
+ :rtype: VerifyingKey
"""
if not self.curve:
self.curve = private_key.curve
@@ -158,7 +158,7 @@ class ECDH(object):
:raises NoCurveError: Curve must be set before loading.
:return: public (verifying) key from this private key.
- :rtype: VerifyingKey object
+ :rtype: VerifyingKey
"""
if not self.curve:
raise NoCurveError("Curve must be set prior to key load.")
@@ -183,7 +183,7 @@ class ECDH(object):
:raises InvalidCurveError: private_key curve not the same as self.curve
:return: public (verifying) key from this private key.
- :rtype: VerifyingKey object
+ :rtype: VerifyingKey
"""
return self.load_private_key(SigningKey.from_der(private_key_der))
@@ -204,7 +204,7 @@ class ECDH(object):
:raises InvalidCurveError: private_key curve not the same as self.curve
:return: public (verifying) key from this private key.
- :rtype: VerifyingKey object
+ :rtype: VerifyingKey
"""
return self.load_private_key(SigningKey.from_pem(private_key_pem))
@@ -215,8 +215,8 @@ class ECDH(object):
Needs to be sent to the remote party.
:return: public (verifying) key from local private key.
- :rtype: VerifyingKey object
- """
+ :rtype: VerifyingKey
+ """
return self.private_key.get_verifying_key()
def load_received_public_key(self, public_key):
@@ -237,7 +237,9 @@ class ECDH(object):
raise InvalidCurveError("Curve mismatch.")
self.public_key = public_key
- def load_received_public_key_bytes(self, public_key_str):
+ def load_received_public_key_bytes(
+ self, public_key_str, valid_encodings=None
+ ):
"""
Load public key from byte string.
@@ -247,9 +249,16 @@ class ECDH(object):
:param public_key_str: public key in bytes string format
:type public_key_str: :term:`bytes-like object`
+ :param valid_encodings: list of acceptable point encoding formats,
+ supported ones are: :term:`uncompressed`, :term:`compressed`,
+ :term:`hybrid`, and :term:`raw encoding` (specified with ``raw``
+ name). All formats by default (specified with ``None``).
+ :type valid_encodings: :term:`set-like object`
"""
return self.load_received_public_key(
- VerifyingKey.from_string(public_key_str, self.curve)
+ VerifyingKey.from_string(
+ public_key_str, self.curve, valid_encodings
+ )
)
def load_received_public_key_der(self, public_key_der):
@@ -301,10 +310,10 @@ class ECDH(object):
:raises NoKeyError: public_key or private_key is not set
:return: shared secret
- :rtype: byte string
+ :rtype: bytes
"""
return number_to_string(
- self.generate_sharedsecret(), self.private_key.curve.order
+ self.generate_sharedsecret(), self.private_key.curve.curve.p()
)
def generate_sharedsecret(self):
@@ -314,9 +323,9 @@ class ECDH(object):
The objects needs to have both private key and received public key
before generation is allowed.
- It's the same for local and remote party.
- shared secret(local private key, remote public key ) ==
- shared secret (local public key, remote private key)
+ It's the same for local and remote party,
+ shared secret(local private key, remote public key) ==
+ shared secret(local public key, remote private key)
:raises InvalidCurveError: public_key curve not the same as self.curve
:raises NoKeyError: public_key or private_key is not set