@@ -97,18 +97,18 @@ Creates and returns a hash object, a cryptographic hash with the given
97
97
algorithm which can be used to generate hash digests.
98
98
99
99
` 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
102
102
list-message-digest-algorithms` will display the available digest
103
103
algorithms.
104
104
105
- Example: this program that takes the sha1 sum of a file
105
+ Example: this program that takes the sha256 sum of a file
106
106
107
107
var filename = process.argv[2];
108
108
var crypto = require('crypto');
109
109
var fs = require('fs');
110
110
111
- var shasum = crypto.createHash('sha1 ');
111
+ var shasum = crypto.createHash('sha256 ');
112
112
113
113
var s = fs.ReadStream(filename);
114
114
s.on('data', function(d) {
@@ -511,21 +511,21 @@ expected.
511
511
## crypto.getDiffieHellman(group_name)
512
512
513
513
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.
523
523
524
524
Example (obtaining a shared secret):
525
525
526
526
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 ');
529
529
530
530
alice.generateKeys();
531
531
bob.generateKeys();
@@ -768,6 +768,26 @@ default, set the `crypto.DEFAULT_ENCODING` field to 'binary'. Note
768
768
that new programs will probably expect buffers, so only use this as a
769
769
temporary measure.
770
770
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.
771
791
772
792
[ createCipher() ] : #crypto_crypto_createcipher_algorithm_password
773
793
[ createCipheriv() ] : #crypto_crypto_createcipheriv_algorithm_key_iv
@@ -779,3 +799,4 @@ temporary measure.
779
799
[ RFC 3526 ] : http://www.rfc-editor.org/rfc/rfc3526.txt
780
800
[ crypto.pbkdf2 ] : #crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback
781
801
[ 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