Install & Compatibility
Where this runs
tested against v0.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.022s · 17.8MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 1.5s · import 0.022s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
scalar_base_mult
✓ import x25519
public_key = x25519.scalar_base_mult(private_key)
✗ from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey
This library is a separate, pure-Python implementation, not part of the 'cryptography' project.
scalar_mult
✓ import x25519
shared_secret = x25519.scalar_mult(private_key, peer_public_key)
✗ private_key.exchange(peer_public_key)
The API for this `x25519` package uses functional calls, not object methods like the `cryptography` library.
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!")
Debug
Known issues
breakingThe GitHub repository linked in the PyPI metadata for this library is non-existent (404 Not Found), indicating the project is likely unmaintained and should not be used for new development.fixMigrate to a actively maintained and audited cryptography library, such as `cryptography` (e.g., `cryptography.hazmat.primitives.asymmetric.x25519`).
affects: 0.0.2 and potentially earlier
gotchaPure Python cryptographic implementations, especially for operations like X25519, can be vulnerable to timing attacks due to variations in execution time based on input values. This can leak sensitive information.fixFor security-critical applications, prefer native code implementations (like those in `cryptography` which wraps OpenSSL) that are designed for constant-time execution.
affects: All versions
gotchaThis `x25519` PyPI package is a distinct, pure-Python implementation and is NOT the X25519 implementation provided by the `cryptography` library, which is the standard and recommended choice for robust cryptography in Python.fixIf you intend to use the widely-accepted and audited X25519 implementation, install `cryptography` (`pip install cryptography`) and import from `cryptography.hazmat.primitives.asymmetric.x25519`.
affects: All versions
gotchaThe raw shared secret derived from X25519 should generally not be used directly as an encryption key. It should be processed through a Key Derivation Function (KDF) like HKDF to produce a strong, fixed-length key suitable for symmetric encryption.fixAfter obtaining the `shared_secret`, apply a KDF (e.g., from `cryptography.hazmat.primitives.kdf.hkdf`) to derive a secure symmetric key.
affects: All versions
Errors
Common errors & fixes
AttributeError: module 'x25519' has no attribute 'X25519PrivateKey'
Attempting to use `cryptography` library's object-oriented API with the `x25519` pure Python package.
fixThe `x25519` package uses functional calls (e.g., `x25519.scalar_base_mult`). If you intended to use the `cryptography` library, ensure it's installed (`pip install cryptography`) and import `from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey`.
TypeError: 'bytes' object cannot be interpreted as an integer
Incorrect input type for cryptographic functions. X25519 operations typically expect 32-byte `bytes` objects for keys.
fixEnsure all key material (private keys, public keys) are precisely 32-byte `bytes` objects. Avoid passing strings or integers directly.
Upgrade
Version history
0.0.2latest on PyPI · released Oct 24, 2021
Audit
Dependencies
No dependency data recorded yet.
Resources
No resource links recorded.