ecc

Elliptic Curve Cryptograpy library from scratch in python.
Log | Files | Refs | README | LICENSE

commit 52788017f0f36551f0afeab77f3bc422764ad582
parent 4831f13b200a5c91ebea1f0e868ff131f954461f
Author: Shivakumar <[email protected]>
Date:   Mon,  4 Aug 2025 23:05:04 +0530

add ecdh function to PrivateKey

Diffstat:
Mecc/keys.py | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git a/ecc/keys.py b/ecc/keys.py @@ -20,6 +20,7 @@ from functools import cached_property from secrets import randbelow from .curve import Curve +from .ecdh import generate_shared_secret from .ecdsa import Signature, _rfc6979_nonce from .point import Point @@ -127,6 +128,20 @@ class PrivateKey: return Signature(r, s) + def ecdh(self, public_key: PublicKey, **kdf_params) -> bytes: + """ + Performs an ECDH key exchange to generate a shared secret. + + Args: + public_key : The public key of the other party. + **kdf_params : Optional parameters for the Key Derivation Function + (e.g., salt, info, key_length). + + Returns: + A cryptographically strong shared secret. + """ + return generate_shared_secret(self, public_key, **kdf_params) + def __eq__(self, other: object) -> bool: if not isinstance(other, PrivateKey): return NotImplemented