@@ -169,10 +169,14 @@ See [`keyObject.export()`][], [`crypto.createPublicKey()`][], and
169169
170170` 'raw-public' ` is generally the fastest way to import a public key.
171171` 'raw-private' ` and ` 'raw-seed' ` are not always faster than other formats
172- because they only contain the private scalar or seed - importing them requires
173- deriving the public key component (e.g. elliptic curve point multiplication or
174- seed expansion), which can be expensive. Other formats include both private
175- and public components, avoiding that computation.
172+ because deriving a public key or expanding a seed can be expensive. Formats
173+ that include both private and public components can avoid this work.
174+
175+ For EC private keys, the public point is only derived when needed. Signing
176+ and ECDH key agreement do not need the local private key's public point, so
177+ importing ` 'raw-private' ` avoids this computation. Extracting the public key,
178+ exporting JWK, PEM, or DER, or using EC decapsulation derives the point on
179+ first use and caches it for subsequent operations.
176180
177181### Choosing a key format
178182
@@ -194,10 +198,11 @@ example:
194198
195199* Public keys - ` 'raw-public' ` is the fastest serialized format because the
196200 raw format skips all ASN.1 and Base64 decoding.
197- * EC private keys - ` 'raw-private' ` is faster than PEM or DER because it
198- avoids ASN.1 parsing. However, for larger curves (e.g. P-384, P-521) the
199- required derivation of the public point from the private scalar becomes
200- expensive, reducing the advantage.
201+ * EC private keys - ` 'raw-private' ` avoids ASN.1 parsing and deriving the
202+ public point until it is needed. This reduces the work needed to import
203+ a key for signing or ECDH. If the public point is needed immediately,
204+ a format that already
205+ includes it can be faster.
201206* RSA keys - ` 'jwk' ` is the fastest serialized format. JWK represents RSA
202207 key components as individual Base64url-encoded integers, avoiding the
203208 overhead of ASN.1 parsing entirely.
@@ -210,13 +215,10 @@ accept a PEM string or an object specifying the format and key
210215material directly. In this case the total cost is the sum of key import and
211216the cryptographic computation itself.
212217
213- For operations where the cryptographic computation dominates - such as
214- signing with RSA or ECDH key agreement with P-384 or P-521 - the
215- serialization format has negligible impact on overall throughput, so choose
216- whichever format is most convenient. For lightweight operations like Ed25519
217- signing or verification, the import cost is a larger fraction of the total,
218- so a faster format like ` 'raw-public' ` or ` 'raw-private' ` can meaningfully
219- improve throughput.
218+ When the cryptographic computation dominates, reducing the import cost has
219+ less impact on overall throughput. For lightweight operations, the import
220+ cost is a larger fraction of the total, so a faster import format can
221+ meaningfully improve throughput.
220222
221223Even if the same key material is used only a few times, it is worth importing it
222224into a [ ` KeyObject ` ] [ ] rather than passing the raw or PEM representation
0 commit comments