X25519
Agree on a shared secret with X25519 from RFC 7748.
from oxcrypto.exchange.x25519 import X25519
alice = X25519.X25519.generate()
bob = X25519.X25519.generate()
assert alice.exchange(bob.public_key()) == bob.exchange(alice.public_key())Private keys, public keys and shared secrets are 32 bytes. As RFC 7748
specifies, a public key is any 32-byte u-coordinate: the top bit is ignored
and values of p or more are reduced modulo p. An exchange whose result is all
zeros raises ValueError (RFC 7748 section 6.1). to_bytes() returns the
private key as loaded; the scalar is clamped when it is used.
Keys
| Format | Private key | Public key |
|---|---|---|
| Raw | to_bytes(), load_private_bytes | to_bytes(), load_public_bytes (u-coordinate) |
| DER | to_der(format="pkcs8", password=None), load_private_der | to_der(format="spki"), load_public_der |
| PEM | to_pem(...), load_private_pem | to_pem(...), load_public_pem |
DER and PEM use the RFC 8410 OID 1.3.101.110. With password, the private
key is written as an encrypted PKCS#8 EncryptedPrivateKeyInfo using PBES2
with scrypt and AES-256-CBC; pass the same password to load_private_der
or load_private_pem. Before deriving a key, loading an encrypted document
applies the same scrypt and PBKDF2 limits as
signature keys. Private keys compare in constant
time with subtle, cannot be copied, pickled or hashed, and their repr
shows only the selector.
Upstream
| Crate | Standard | Audit |
|---|---|---|
x25519-dalek 3.0.0 on curve25519-dalek 5.0.0 | RFC 7748 | No published audit of these versions; Quarkslab's 2019 assessment covered earlier releases |
curve25519-dalek is written to run the Montgomery ladder in constant time;
oxcrypto has not verified this independently. Both crates build with Rust
1.88, the oxcrypto MSRV. Tests use RFC 7748 sections 5.2 and 6.1 and the C2SP
Wycheproof x25519_test.json, x25519_asn_test.json and
x25519_pem_test.json vectors.
Zeroization
Note
A private key owns an x25519-dalek StaticSecret, which the crate is
written to wipe when it is dropped; oxcrypto has not verified this
independently. The shared secret and DER built from a private key are wiped
after the returned bytes are created. Not covered: keys, passwords and
shared secrets passed in or returned as Python bytes, the clamped scalar
curve25519-dalek copies on the stack during a call, and the PBES2 key
pkcs5 derives from a password.