Skip to main content

Module x25519

Module x25519 

Source
Expand description

X25519 key agreement (RFC 7748), as the Web Cryptography API serves it.

Keys returned here drive key-agreement.secret-key.agree, whose derive-input output feeds derive-bits, the key-minting interfaces’ derive-key, and hkdf-sha2.prepare-from — the spec’s own worked example (X25519 → HKDF → AES-GCM) runs entirely through handles.

Formats follow the format-admission rule (see README.md, “Design notes”): every format is one a platform-backed host passes to the platform verbatim. The public key travels as the raw 32-byte RFC 7748 u-coordinate (the platform’s public-only raw format); the secret key travels only as an RFC 8037 OKP private JWK (the platform’s jwk format — its sole non-ASN.1 private form). Bare secret scalars have no platform door and are not a format here.

Functions§

generate_key
Generate a fresh X25519 key pair.
import_public_key_jwk
Import a public key as an RFC 8037 OKP public JWK (kty: "OKP", crv: "X25519", x). jwk is the JWK as JSON text; see mac-key.export-key-jwk for the package-wide JWK contract.
import_public_key_raw
Import a raw 32-byte RFC 7748 u-coordinate as a public key.
import_public_key_spki
Import a public key as an X.509 SubjectPublicKeyInfo (DER, RFC 8410 algorithm id 1.3.101.110). The embedded u-coordinate is admitted exactly as import-public-key-raw admits it.
import_secret_key_jwk
Import a static secret key as an RFC 8037 OKP private JWK (kty: "OKP", crv: "X25519", with x and d both required — RFC 8037 makes the public coordinate mandatory, so this is inherently the public+private form).
import_secret_key_pkcs8
Import a static secret key as a PKCS#8 PrivateKeyInfo (DER, RFC 8410: the 32-byte scalar in a CurvePrivateKey). The scalar is clamped at use per RFC 7748, like the JWK import’s d.
unwrap_secret_key_jwk
Mint a static secret key from unwrapped key material (see the wrapping interface): input’s bytes are read as an OKP private JWK, subject to import-secret-key-jwk’s contract plus the unwrap-path use/key_ops checks (see README.md, “JWK contract”). input is consumed.
unwrap_secret_key_pkcs8
Mint a static secret key from unwrapped key material read as a PKCS#8 PrivateKeyInfo, subject to import-secret-key-pkcs8’s contract. input is consumed; see unwrap-secret-key-jwk for the options model.

Type Aliases§

AgreementKeyOptions
Error
PublicKey
SecretKey
UnwrapInput