Skip to main content

A simple implementation of unauthenticated ECDH

This package implements unauthenticated ECDH (the Elliptic Curve Diffie-Hellman key agreement protocol) between two endpoints. After the exchange is complete, you can then add authentication to verify that both parties are who they say they are — for example, mutual short string authentication by displaying a derivative of the key (derived key) to both parties, as exemplified by the simpleauthstrings package.

Here is a sample with working code:

from blindecdh import ECDHProtocol
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.serialization import (
    load_pem_public_key,
)


def pubkey_to_pem(pubkey):
    return pubkey.public_bytes(
        serialization.Encoding.PEM,
        serialization.PublicFormat.SubjectPublicKeyInfo,
    )


def pem_to_pubkey(pem):
    return load_pem_public_key(pem)


# ------------------------

# Alice's side.

## Instantiate the protocol.
alice = ECDHProtocol()

## Serialize and send Alice's public key.
## The specific communications mechanism is omitted for brevity.
## We assume both parties traffic in PEM-encoded certificates.
bob_socket.send(pubkey_to_pem(alice.public_key))

## Get and deserialize Bob's public key.
bobs_public_key = pem_to_pubkey(bob_socket.receive())

## Compute the result.
result = alice.run(bobs_public_key)

## Display the derived key.  It will match Bob's.
print(result.derived_key)

# -----------------------

# Bob's side.

bob = ECDHProtocol()

## Get and deserialize Alice's public key.
## On Bob's side we do the send first, but here we receive first.
alices_public_key = pem_to_pubkey(alice_socket.receive())

## Serialize and send Bob's public key.
alice_socket.send(pubkey_to_pem(bob.public_key))

## Compute the result.
result = bob.run(alices_public_key)

## Display the derived key.  It will match Bob's.
print(result.derived_key)

See module for developer documentation.

This package is distributed under the GNU Lesser General Public License v2.1. For relicensing, contact the package author.

Metadata

Release files for blindecdh 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for blindecdh 0.1.9
File Size Uploaded Provenance
blindecdh-0.1.9.tar.gz 14.7 kB Without provenance Details

Release files / blindecdh-0.1.9.tar.gz

Download URL blindecdh-0.1.9.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
21e48324bb0481e92adf1f9b5b0c8cd3c0866d3ddd841cb382b5a24de581a6c5
BLAKE2b-256 checksum
How to use checksums
2e932ebeb5f6a7fb6bd399b5dd09d32af3c6a78cc5758bea0e809c48ff4733e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.10.4

Security for blindecdh 0.1.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page