Skip to main content

Module ecdh

Module ecdh 

Source
Expand description

ecdh key creation (SP 800-56A ECDH over the NIST prime-order curves).

Keys minted here drive AgreementSecretKey::agree, whose result chains into the KDFs (see hkdf_sha2::prepare_from), exactly as X25519’s do. The shared secret is the x-coordinate of the agreed point, so its natural length is the curve’s field size: 32 bytes for P-256, 48 bytes for P-384. Unlike X25519’s deliberately permissive raw import, public imports are strict — a point not on the declared variant’s curve fails at import as Error::InvalidKey.

Enums§

EcdhVariant
The served curves. (Each algorithm interface names its closed set of parameterizations <algorithm>-variant; ECDH’s parameter is the curve alone.)

Functions§

generate_key
Generate a fresh random keypair on the declared variant’s curve, returning both halves.
import_public_key_jwk
Import a peer’s public key from an EC public JWK (as JSON text) whose crv matches the declared variant’s curve.
import_public_key_raw
Import a peer’s public key as an uncompressed SEC1 point (04 ‖ x ‖ y; 65 bytes for P-256, 97 bytes for P-384).
import_public_key_spki
Import a peer’s public key from an X.509 SubjectPublicKeyInfo (DER) whose encoded curve matches the declared variant’s.
import_secret_key_jwk
Import a static secret key from an EC private JWK (as JSON text) whose crv matches the declared variant’s curve.
import_secret_key_pkcs8
Import a static secret key from a PKCS#8 PrivateKeyInfo (DER) whose encoded curve matches the declared variant’s.