Skip to content

Commit d1b5833

Browse files
Shigeki Ohtsujasnell
Shigeki Ohtsu
authored andcommitted
doc: add caveats of algs and key size in crypto
Add description of user responsibility in the choice of cypto algorithms and its key length. Some of recommendations for the safer use are also described. PR-URL: #3479 Reviewed-By: James M Snell <[email protected]>
1 parent 329e88e commit d1b5833

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

doc/api/crypto.markdown

+36-15
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,18 @@ Creates and returns a hash object, a cryptographic hash with the given
9797
algorithm which can be used to generate hash digests.
9898

9999
`algorithm` is dependent on the available algorithms supported by the
100-
version of OpenSSL on the platform. Examples are `'sha1'`, `'md5'`,
101-
`'sha256'`, `'sha512'`, etc. On recent releases, `openssl
100+
version of OpenSSL on the platform. Examples are `'sha256'`,
101+
`'sha512'`, etc. On recent releases, `openssl
102102
list-message-digest-algorithms` will display the available digest
103103
algorithms.
104104

105-
Example: this program that takes the sha1 sum of a file
105+
Example: this program that takes the sha256 sum of a file
106106

107107
var filename = process.argv[2];
108108
var crypto = require('crypto');
109109
var fs = require('fs');
110110

111-
var shasum = crypto.createHash('sha1');
111+
var shasum = crypto.createHash('sha256');
112112

113113
var s = fs.ReadStream(filename);
114114
s.on('data', function(d) {
@@ -511,21 +511,21 @@ expected.
511511
## crypto.getDiffieHellman(group_name)
512512

513513
Creates a predefined Diffie-Hellman key exchange object. The
514-
supported groups are: `'modp1'`, `'modp2'`, `'modp5'` (defined in [RFC
515-
2412][]) and `'modp14'`, `'modp15'`, `'modp16'`, `'modp17'`,
516-
`'modp18'` (defined in [RFC 3526][]). The returned object mimics the
517-
interface of objects created by [crypto.createDiffieHellman()][]
518-
above, but will not allow to change the keys (with
519-
[diffieHellman.setPublicKey()][] for example). The advantage of using
520-
this routine is that the parties don't have to generate nor exchange
521-
group modulus beforehand, saving both processor and communication
522-
time.
514+
supported groups are: `'modp1'`, `'modp2'`, `'modp5'` (defined in
515+
[RFC 2412][], but see [Caveats](#crypto_caveats)) and `'modp14'`,
516+
`'modp15'`, `'modp16'`, `'modp17'`, `'modp18'` (defined in
517+
[RFC 3526][]). The returned object mimics the interface of objects
518+
created by [crypto.createDiffieHellman()][] above, but will not allow
519+
changing the keys (with [diffieHellman.setPublicKey()][] for example).
520+
The advantage of using this routine is that the parties do not have to
521+
generate nor exchange group modulus beforehand, saving both processor
522+
and communication time.
523523

524524
Example (obtaining a shared secret):
525525

526526
var crypto = require('crypto');
527-
var alice = crypto.getDiffieHellman('modp5');
528-
var bob = crypto.getDiffieHellman('modp5');
527+
var alice = crypto.getDiffieHellman('modp14');
528+
var bob = crypto.getDiffieHellman('modp14');
529529

530530
alice.generateKeys();
531531
bob.generateKeys();
@@ -768,6 +768,26 @@ default, set the `crypto.DEFAULT_ENCODING` field to 'binary'. Note
768768
that new programs will probably expect buffers, so only use this as a
769769
temporary measure.
770770

771+
## Caveats
772+
773+
The crypto module still supports some algorithms which are already
774+
compromised. And the API also allows the use of ciphers and hashes
775+
with a small key size that are considered to be too weak for safe use.
776+
777+
Users should take full responsibility for selecting the crypto
778+
algorithm and key size according to their security requirements.
779+
780+
Based on the recommendations of [NIST SP 800-131A]:
781+
782+
- MD5 and SHA-1 are no longer acceptable where collision resistance is
783+
required such as digital signatures.
784+
- The key used with RSA, DSA and DH algorithms is recommended to have
785+
at least 2048 bits and that of the curve of ECDSA and ECDH at least
786+
224 bits, to be safe to use for several years.
787+
- The DH groups of `modp1`, `modp2` and `modp5` have a key size
788+
smaller than 2048 bits and are not recommended.
789+
790+
See the reference for other recommendations and details.
771791

772792
[createCipher()]: #crypto_crypto_createcipher_algorithm_password
773793
[createCipheriv()]: #crypto_crypto_createcipheriv_algorithm_key_iv
@@ -779,3 +799,4 @@ temporary measure.
779799
[RFC 3526]: http://www.rfc-editor.org/rfc/rfc3526.txt
780800
[crypto.pbkdf2]: #crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback
781801
[EVP_BytesToKey]: https://www.openssl.org/docs/crypto/EVP_BytesToKey.html
802+
[NIST SP 800-131A]: http://csrc.nist.gov/publications/nistpubs/800-131A/sp800-131A.pdf

0 commit comments

Comments
 (0)