x25519

0.0.2 · abandoned · verified Thu Apr 16

The `x25519` library (version 0.0.2) provides a pure Python implementation of the Curve25519 elliptic curve for Diffie-Hellman key exchange. It was last released in October 2021 and appears to be unmaintained, with no active development or official GitHub repository discoverable at the provided link. This library is distinct from the more robust and actively maintained X25519 implementations found in the `cryptography` library.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to generate X25519 private and public keys and then derive a shared secret using the `x25519` library's `scalar_base_mult` and `scalar_mult` functions. Ensure private keys are truly random bytes in a real-world scenario.

import x25519
from binascii import hexlify

# Generate a 32-byte private key (randomly in a real application)
private_key_a = b'\x01' * 32 # Example: should be randomly generated
private_key_b = b'\x02' * 32 # Example: should be randomly generated

# Derive public keys
public_key_a = x25519.scalar_base_mult(private_key_a)
public_key_b = x25519.scalar_base_mult(private_key_b)

print(f"Public Key A: {hexlify(public_key_a).decode()}")
print(f"Public Key B: {hexlify(public_key_b).decode()}")

# Compute shared secrets
shared_secret_ab = x25519.scalar_mult(private_key_a, public_key_b)
shared_secret_ba = x25519.scalar_mult(private_key_b, public_key_a)

print(f"Shared Secret A->B: {hexlify(shared_secret_ab).decode()}")
print(f"Shared Secret B->A: {hexlify(shared_secret_ba).decode()}")

assert shared_secret_ab == shared_secret_ba
print("Shared secrets match!")

view raw JSON →