Filip Skokan
b116861e88
crypto: move DEP0198 to End-of-Life
...
Signed-off-by: Filip Skokan <panva.ip@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/64000
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
2026-06-21 11:18:48 +00:00
Filip Skokan
8c8c43882f
lib: fix missing lazyDOMException import
...
Signed-off-by: Filip Skokan <panva.ip@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/64033
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk >
2026-06-20 20:11:08 +02:00
Filip Skokan
8ec37ebbd6
crypto: support non-byte WebCrypto lengths and cSHAKE
...
Add shared bit-length helpers for WebCrypto operations that accept bit
sequences whose length is not byte-aligned.
Use the helpers for cSHAKE output, ECDH-derived bits, HMAC/KMAC key
generation/import/derivation, and KMAC sign/verify output. Preserve the
requested bit length in CryptoKey algorithm metadata while storing and
exporting rounded-up byte material with unused low bits cleared.
Keep byte-multiple validation for algorithms whose specs require it.
Extend the lower-end of KMAC's key length support.
Enable cSHAKE customization and functionName parameters.
Signed-off-by: Filip Skokan <panva.ip@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/63988
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
2026-06-20 18:42:04 +02:00
Filip Skokan
89bf6548b7
crypto: share WebCrypto method and usage helpers
...
Introduce prepareSubtleMethod() and convertSubtleArgument() for the
common SubtleCrypto call prelude. Methods now reuse the same receiver
check, required-argument check, error prefix construction, argument
context selection, and WebIDL conversion path.
Introduce WebCrypto key usage helpers for common usage validation and
key pair usage splitting. Algorithm modules now define their allowed
public, private, and key generation usages once, then call the shared
helpers from generateKey() and importKey() paths.
This removes repeated function-invocation setup in webcrypto.js and
repeated key usage checks across the WebCrypto algorithm modules while
preserving the existing validation behavior.
Mark normalized-algorithm fallback branches as unreachable assertions.
Signed-off-by: Filip Skokan <panva.ip@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/63975
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
2026-06-20 13:29:46 +00:00
Madelyn and Filip Skokan
463e56fb00
crypto: runtime-deprecate calling Hmac.digest() more than once
...
Emit a DEP0206 deprecation warning when Hmac.digest() is called on an
already-finalized instance. This behavior is inconsistent with
Hash.digest() which throws ERR_CRYPTO_HASH_FINALIZED.
Fixes: https://github.com/nodejs/node/issues/62838
Co-authored-by: Filip Skokan <panva.ip@gmail.com >
Signed-off-by: developers-universe-1 <madelynreyes2026@gmail.com >
Signed-off-by: Filip Skokan <panva.ip@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/63624
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day >
2026-06-15 21:22:58 +00:00
Haram Jeong
120c2a4558
crypto: fix unhandled error in Hash._transform
...
Signed-off-by: haramjeong <04harams77@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/63261
Fixes: https://github.com/nodejs/node/issues/63258
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
2026-06-14 15:22:50 +00:00
Filip Skokan
9b7e761ddf
crypto: coerce -0 to +0 before native calls
...
Signed-off-by: Filip Skokan <panva.ip@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/63556
Reviewed-By: Jordan Harband <ljharb@gmail.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2026-05-31 14:25:27 +00:00
Filip Skokan
e24e698a97
crypto: add WebCrypto CryptoJob mode
...
Add a WebCrypto-specific CryptoJob mode that returns a promise from
run() and resolves it when native work is finished.
Encode job output directly as Web Crypto values, including CryptoKey
instances and CryptoKeyPair dictionaries. Convert operation-specific
setup failures from AdditionalConfig into OperationError rejections.
Signed-off-by: Filip Skokan <panva.ip@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/63363
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk >
2026-05-23 15:45:30 +00:00
Filip Skokan
e0cab9dcf7
crypto: add TurboSHAKE and KangarooTwelve Web Cryptography algorithms
...
PR-URL: https://github.com/nodejs/node/pull/62183
Refs: https://wicg.github.io/webcrypto-modern-algos/#kangarootwelve
Refs: https://wicg.github.io/webcrypto-modern-algos/#turboshake
Refs: https://www.rfc-editor.org/rfc/rfc9861.html
Refs: https://redirect.github.com/openssl/openssl/issues/30304
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
2026-03-26 22:04:32 +01:00
Filip Skokan
ab8dc2b84c
crypto: rename CShakeParams and KmacParams length to outputLength
...
PR-URL: https://github.com/nodejs/node/pull/61875
Refs: https://github.com/web-platform-tests/wpt/pull/57802
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
2026-03-16 22:04:01 +01:00
Livia Medeiros
46dc5d7c9f
lib: prefer call() over apply() if argument list is not array
...
PR-URL: https://github.com/nodejs/node/pull/60796
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2025-11-23 08:45:46 +00:00
Renegade334
8869210dd8
crypto: use return await when returning Promises from async functions
...
This offers _some_ resistance to `%Promise.prototype%` pollution.
Refs: https://github.com/nodejs/node/issues/59699
PR-URL: https://github.com/nodejs/node/pull/59841
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Jordan Harband <ljharb@gmail.com >
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
2025-09-12 14:21:50 +00:00
Filip Skokan
1c4d534b75
crypto: add SHA-3 Web Cryptography digest algorithms
...
PR-URL: https://github.com/nodejs/node/pull/59365
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
2025-08-19 15:55:57 +02:00
Filip Skokan
327618c430
crypto: add SHAKE Web Cryptography digest algorithms
...
PR-URL: https://github.com/nodejs/node/pull/59365
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
2025-08-19 15:55:56 +02:00
Yagiz Nizipli
0fd1ecded6
meta: enable jsdoc/check-tag-names rule
...
PR-URL: https://github.com/nodejs/node/pull/58521
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: LiviaMedeiros <livia@cirno.name >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2025-07-18 09:28:21 +00:00
Filip Skokan
a472745958
crypto: runtime-deprecate default shake128/256 output lengths
...
PR-URL: https://github.com/nodejs/node/pull/59008
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
2025-07-11 14:21:46 +00:00
Aditi and Filip Skokan
1c4fe6d795
crypto: support outputLength option in crypto.hash for XOF functions
...
Support `outputLength` option in crypto.hash() for XOF hash
functions to align with the behaviour of crypto.createHash()
API
closes: https://github.com/nodejs/node/issues/57312
Co-authored-by: Filip Skokan <panva.ip@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/58121
Fixes: https://github.com/nodejs/node/issues/57312
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
2025-07-08 13:39:00 +00:00
Filip Skokan
f5da8f89ee
crypto: fix SHAKE128/256 breaking change introduced with OpenSSL 3.4
...
Reverts: https://github.com/nodejs/node/pull/56160
Fixes: https://github.com/nodejs/node/issues/56159
Fixes: https://github.com/nodejs/node/issues/58913
Refs: https://github.com/nodejs/node/pull/58121
PR-URL: https://github.com/nodejs/node/pull/58942
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
2025-07-05 09:34:24 +00:00
Antoine du Hamel
6dd1c75f4a
crypto: fix input validation in crypto.hash
...
PR-URL: https://github.com/nodejs/node/pull/52070
Refs: https://github.com/nodejs/node/pull/51044/files#r1522362983
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2024-03-21 12:12:31 +01:00
Joyee Cheung
4c46439fe9
crypto: implement crypto.hash()
...
This patch introduces a helper crypto.hash() that computes
a digest from the input at one shot. This can be 1.2-1.6x faster
than the object-based createHash() for smaller inputs (<= 5MB)
that are readily available (not streamed) and incur less memory
overhead since no intermediate objects will be created.
PR-URL: https://github.com/nodejs/node/pull/51044
Refs: https://github.com/nodejs/performance/issues/136
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br >
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io >
2024-02-27 13:27:19 +01:00
Joyee Cheung
57c22e4a22
crypto: use EVP_MD_fetch and cache EVP_MD for hashes
...
On OpenSSL 3, migrate from EVP_get_digestbyname() to EVP_MD_fetch()
to get the implementation and use a per-Environment cache for it.
The EVP_MDs are freed during Environment cleanup.
Drive-by: declare the smart pointer for EVP_MD_CTX as EVPMDCtxPointer
instead of EVPMDPointer to avoid confusion with EVP_MD pointers.
PR-URL: https://github.com/nodejs/node/pull/51034
Refs: https://www.openssl.org/docs/man3.0/man7/crypto.html#Explicit-fetching
Refs: https://github.com/nodejs/performance/issues/136
Reviewed-By: James M Snell <jasnell@gmail.com >
2024-01-05 22:16:27 +00:00
Joyee Cheung
c97322adff
benchmark: add create-hash benchmark
...
PR-URL: https://github.com/nodejs/node/pull/51026
Refs: https://github.com/nodejs/performance/issues/136
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2023-12-05 22:59:31 +00:00
Tobias Nießen
8ed4397985
crypto: remove default encoding from Hash/Hmac
...
getDefaultEncoding() always returns 'buffer' in Node.js 20. It requires
some careful justification but the default encoding can be eliminated
from hash.js entirely. The reasoning is almost identical with that in
https://github.com/nodejs/node/pull/49145 so I won't repeat it here.
Refs: https://github.com/nodejs/node/pull/47182
PR-URL: https://github.com/nodejs/node/pull/49167
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
2023-08-16 14:54:05 +00:00
Antoine du Hamel
ab8942848b
lib: enforce use of trailing commas
...
PR-URL: https://github.com/nodejs/node/pull/46881
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: Jacob Smith <jacob@frende.me >
2023-03-06 10:44:14 +01:00
Filip Skokan
3ef38c4bd7
crypto: use WebIDL converters in WebCryptoAPI
...
WebCryptoAPI functions' arguments are now coersed and validated as per
their WebIDL definitions like in other Web Crypto API implementations.
This further improves interoperability with other implementations of
Web Crypto API.
PR-URL: https://github.com/nodejs/node/pull/46067
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2023-01-17 08:57:58 +00:00
Filip Skokan
73a5112583
crypto: handle more webcrypto errors with OperationError
...
PR-URL: https://github.com/nodejs/node/pull/45320
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2022-11-07 06:35:35 +00:00
Filip Skokan
288304c888
crypto: fix webcrypto digest() invalid algorithm
...
PR-URL: https://github.com/nodejs/node/pull/43431
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2022-06-16 22:00:33 +02:00
Antoine du Hamel
da53a3caa3
crypto: refactor to use more primordials
...
PR-URL: https://github.com/nodejs/node/pull/36012
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2020-11-09 20:23:07 -08:00
James M Snell
dae283d96f
crypto: refactoring internals, add WebCrypto
...
Fixes: https://github.com/nodejs/node/issues/678
Refs: https://github.com/nodejs/node/issues/26854
Signed-off-by: James M Snell <jasnell@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/35093
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2020-10-07 17:27:05 -07:00
Ben Noordhuis
9ec8781502
crypto: make update(buf, enc) ignore encoding
...
Make the cipher/decipher/hash/hmac update() methods ignore the input
encoding when the input is a buffer.
This is the documented behavior but some inputs were rejected, notably
when the specified encoding is 'hex' and the buffer has an odd length
(because a _string_ with an odd length is never a valid hex string.)
The sign/verify update() methods work okay because they use different
validation logic.
Fixes: https://github.com/nodejs/node/issues/31751
PR-URL: https://github.com/nodejs/node/pull/31766
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2020-03-05 15:24:17 -04:00
Sebastien Ahkrin
eac3f0adc4
lib: replace Symbol global by the primordials Symbol
...
PR-URL: https://github.com/nodejs/node/pull/30737
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2019-12-08 13:38:58 +01:00
Michaël Zasso
0646eda4fc
lib: flatten access to primordials
...
Store all primordials as properties of the primordials object.
Static functions are prefixed by the constructor's name and prototype
methods are prefixed by the constructor's name followed by "Prototype".
For example: primordials.Object.keys becomes primordials.ObjectKeys.
PR-URL: https://github.com/nodejs/node/pull/30610
Refs: https://github.com/nodejs/node/issues/29766
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
2019-11-25 10:28:15 +01:00
Ben Noordhuis
9f203f927c
crypto: add Hash.prototype.copy() method
...
Make it possible to clone the internal state of a Hash object
into a new Hash object, i.e., to fork the state of the object.
Fixes: https://github.com/nodejs/node/issues/29903
PR-URL: https://github.com/nodejs/node/pull/29910
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Sam Roberts <vieuxtech@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-10-16 10:00:00 -07:00
Anna Henningsen
389969ea92
crypto: remove arbitrary UTF16 restriction
...
Since 71f633a32f , this is no longer necessary.
Refs: https://github.com/nodejs/node/pull/22622
Fixes: https://github.com/nodejs/node/issues/29793
PR-URL: https://github.com/nodejs/node/pull/29795
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: David Carlier <devnexen@gmail.com >
2019-10-03 13:54:36 -07:00
Yaniv Friedensohn
a0e2c6d284
src: add error codes to errors thrown in C++
...
PR-URL: https://github.com/nodejs/node/pull/27700
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2019-08-09 15:58:58 -07:00
cjihrig
92ca2c208b
crypto: add null check to outputLength logic
...
The Hash constructor's outputLength logic checks if the options
input is an object, but doesn't check for null objects. This
commit adds that check.
PR-URL: https://github.com/nodejs/node/pull/28864
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
2019-07-29 03:33:28 -10:00
Tobias Nießen
31d9b2f14f
crypto: add outputLength option to crypto.createHash
...
This change adds an outputLength option to crypto.createHash which
allows users to produce variable-length hash values using XOF hash
functons.
Fixes: https://github.com/nodejs/node/issues/28757
PR-URL: https://github.com/nodejs/node/pull/28805
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Sam Roberts <vieuxtech@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2019-07-25 23:00:41 -07:00
Michaël Zasso
908292cf1f
lib: enforce the use of Object from primordials
...
PR-URL: https://github.com/nodejs/node/pull/27146
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Gus Caplan <me@gus.host >
2019-04-12 05:38:45 +02:00
Tobias Nießen
2f1ed5c063
crypto: remove legacy native handles
...
PR-URL: https://github.com/nodejs/node/pull/27011
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
2019-04-04 16:45:41 +02:00
Amit Zur
e0a3d74135
crypto: include 'Buffer' in error output of Hash.update method
...
Fixes: https://github.com/nodejs/node/issues/25487
PR-URL: https://github.com/nodejs/node/pull/25533
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com >
Reviewed-By: Sam Roberts <vieuxtech@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2019-02-09 17:21:41 +01:00
Anna Henningsen
270ffb0fa7
src,lib: remove dead process.binding() code
...
There are no non-internal builtin modules left, so this
should be safe to remove to a large degree.
PR-URL: https://github.com/nodejs/node/pull/25829
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com >
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
2019-02-03 20:41:53 +01:00
Tobias Nießen
823d86c47c
crypto: add key object API
...
This commit makes multiple important changes:
1. A new key object API is introduced. The KeyObject class itself is
not exposed to users, instead, several new APIs can be used to
construct key objects: createSecretKey, createPrivateKey and
createPublicKey. The new API also allows to convert between
different key formats, and even though the API itself is not
compatible to the WebCrypto standard in any way, it makes
interoperability much simpler.
2. Key objects can be used instead of the raw key material in all
relevant crypto APIs.
3. The handling of asymmetric keys has been unified and greatly
improved. Node.js now fully supports both PEM-encoded and
DER-encoded public and private keys.
4. Conversions between buffers and strings have been moved to native
code for sensitive data such as symmetric keys due to security
considerations such as zeroing temporary buffers.
5. For compatibility with older versions of the crypto API, this
change allows to specify Buffers and strings as the "passphrase"
option when reading or writing an encoded key. Note that this
can result in unexpected behavior if the password contains a
null byte.
PR-URL: https://github.com/nodejs/node/pull/24234
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2018-12-24 14:50:16 +01:00
Ruben Bridgewater
59257543c3
lib: use ES6 class inheritance style
...
PR-URL: https://github.com/nodejs/node/pull/24755
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
2018-12-05 16:55:00 +01:00
Ruben Bridgewater
dcc82b37b6
lib: remove inherits() usage
...
This switches all `util.inherits()` calls to use
`Object.setPrototypeOf()` instead. In fact, `util.inherits()` is
mainly a small wrapper around exactly this function while adding
the `_super` property on the object as well.
Refs: #24395
PR-URL: https://github.com/nodejs/node/pull/24755
Refs: https://github.com/nodejs/node/issues/24395
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
2018-12-05 16:53:58 +01:00
Michaël Zasso
e83d7e8d88
crypto: put legacy _handle accessors on prototypes
...
Creating deprecated accessors each time an object is created is very
time consuming.
Refs: https://github.com/nodejs/node/pull/22747
Fixes: https://github.com/nodejs/node/issues/24266
PR-URL: https://github.com/nodejs/node/pull/24269
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2018-11-11 20:01:31 +01:00
Tobias Nießen
79d2536493
crypto: rename symbols to match guidelines
...
PR-URL: https://github.com/nodejs/node/pull/22770
Refs: https://github.com/nodejs/node/pull/22684
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2018-09-13 01:05:28 +02:00
Tobias Nießen
0ade10df79
crypto: hide native handles from JS modules
...
PR-URL: https://github.com/nodejs/node/pull/22747
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
2018-09-12 22:20:27 +02:00
Jon Moss
e570ae79f5
lib: extract validateString validator
...
Pulls out a common argument validator to `internal/validators`
PR-URL: https://github.com/nodejs/node/pull/22101
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2018-08-07 10:51:27 -04:00
Ruben Bridgewater
c6b6c92185
lib: always show ERR_INVALID_ARG_TYPE received part
...
This makes a effort to make sure all of these errors will actually
also show the received input.
On top of that it refactors a few tests for better maintainability.
It will also change the returned type to always be a simple typeof
instead of special handling null.
PR-URL: https://github.com/nodejs/node/pull/19445
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2018-03-25 01:45:37 +01:00
Michaël Zasso
1d2fd8b65b
lib: port remaining errors to new system
...
PR-URL: https://github.com/nodejs/node/pull/19137
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
2018-03-07 14:54:38 +01:00