Ed25519
Sign and verify with Ed25519 and Ed25519ph from RFC 8032.
from oxcrypto.signature.ed25519 import ED25519
private_key = ED25519.ED25519PH.generate()
signature = private_key.sign(b"message", context=b"protocol v1")
public_key = private_key.public_key()
assert public_key.verify(signature, b"message", context=b"protocol v1")ED25519 is pure Ed25519 and takes no context; passing context raises
ValueError. ED25519PH hashes the message with SHA-512 first and takes an
optional context of up to 255 bytes (default empty). Private keys are 32-byte
seeds, public keys are 32 bytes and signatures are 64 bytes. A key object
carries its selector, so an ED25519PH key signs and verifies only
Ed25519ph.
Verification
verify uses the RFC 8032 cofactorless equation through
VerifyingKey::verify and rejects non-canonical S values.
Loading a small-order public key (raw, SPKI, or the public key embedded in a
PKCS#8 v2 document) raises ValueError. RFC 8032 and Wycheproof accept such
keys, but a small-order key such as the identity verifies signatures that
were made without a private key. Mixed-order public keys are accepted.
Keys
| Format | Private key | Public key |
|---|---|---|
| Raw | to_bytes(), load_private_bytes (RFC 8032 seed) | to_bytes(), load_public_bytes (RFC 8032 encoding) |
| 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.112 for both selectors. 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. Loading reads
PKCS#8 v1 and v2, and the public key in a v2 document must match the private
key. Encrypted keys are subject to the key-derivation limits described in
Signatures.
Upstream
| Crate | Standard | Audit |
|---|---|---|
ed25519-dalek 3.0.0 on curve25519-dalek 5.0.0 | RFC 8032, FIPS 186-5 | No published audit of these versions; Quarkslab's 2019 assessment covered earlier releases |
curve25519-dalek is written to run secret-dependent arithmetic in constant
time; oxcrypto has not verified this independently. Both crates build with
Rust 1.88, the oxcrypto MSRV. Tests use RFC 8032 sections 7.1 and 7.3 and the
C2SP Wycheproof ed25519_test.json vectors.
Zeroization
Note
ed25519-dalek is written to wipe the seed, the expanded secret scalar and
the hash prefix of a SigningKey when it is dropped; oxcrypto has not
verified this independently. DER built from a private key is wiped after
the returned bytes are created. Not covered: seeds, passwords and
serialized keys passed in or returned as Python bytes, the per-signature
nonce and hash state ed25519-dalek keeps on the stack during sign, and
the PBES2 key pkcs5 derives from a password.