Key exchange
Agree on a shared secret with elliptic-curve Diffie-Hellman.
Choose a curve, generate or load a private key, and call
exchange(peer_public_key) to get the shared secret. Feed the shared secret
into a key derivation function before using it as a key; it is not uniformly
random.
Invalid keys, encodings and option values, and a peer key on a different
curve, raise ValueError. Inputs of the wrong type raise TypeError.
Algorithms
- ECDH P-224, P-256, P-384, P-521, secp256k1, brainpoolP256r1, brainpoolP384r1, brainpoolP256t1 and brainpoolP384t1.
- BIGN-256 Diffie-Hellman over the STB 34.101.45 curve.
- X25519 Diffie-Hellman on Curve25519 (RFC 7748).
- X448 Diffie-Hellman on Curve448 (RFC 7748), experimental.
Zeroization
An ECDHPrivateKey owns an elliptic_curve::SecretKey and a BIGNPrivateKey
owns a bignp256::SecretKey wrapping one. The upstream
crate is written to wipe when it is dropped. During exchange, oxcrypto wipes
its copy of the scalar and the shared-secret buffer before freeing them.
oxcrypto has not verified the upstream behavior independently.
Zeroization does not cover:
- Keys and shared secrets returned as Python
bytes. Python owns these objects. oxcrypto does not wipe them, and Python may copy them or leave them in freed memory. - Short-lived copies
elliptic-curvemakes on the stack duringdiffie_hellman: the projective and affine shared point. - The scalar copy
bignp256makes on the stack while encoding a BIGN-256 private key as PKCS#8 (to_der/to_pem). - The PBES2 key that
pkcs5derives frompasswordwhile encrypting or decrypting a PKCS#8 document;pkcs50.8.1 does not wipe it. - Copies left behind when Rust moves a key into the object.
Treat zeroization as defense in depth. It does not guarantee that secrets are gone from process memory.