-
Notifications
You must be signed in to change notification settings - Fork 237
Closed
Labels
Description
please fix, use of weak algorithm in ntls.js which using DES-ECB
Description
The code at
var des = crypto.createCipheriv('DES-ECB', key, ''); |
DES-ECB
algorithm for encryption which is considered weak and insecure due to the below following reasons:
- DES is an outdated encryption standard with a key length of 56 bits, making it susceptible to brute-force attacks.
- The use of ECB mode reveals patterns in the plaintext, as identical plaintext blocks result in identical ciphertext blocks. This can leak sensitive information about the structure of the plaintext.
Code With Issue
function encrypt(buf) {
var key = insertZerosEvery7Bits(buf);
var des = crypto.createCipheriv('DES-ECB', key, '');
return des.update("KGS!@#$%"); // page 57 in [MS-NLMP]
}
Impact
- could be: The static string
"KGS!@#$%"
makes the encryption output predictable. - why its weak: Many security standards (e.g., PCI-DSS, NIST) prohibit the use of DES due to its known vulnerabilities.
Recommendation
To resolve this issue, I recommend switching to a modern encryption algorithm like AES (Advanced Encryption Standard) in GCM (Galois/Counter Mode) or CBC (Cipher Block Chaining) mode. For example:
// sample fix code
const crypto = require('crypto');
function encrypt(buf) {
...
const cipher = crypto.createCipheriv('aes-256-gcm', key, iv); // fixed code
return { encrypted, iv, tag };
...
}
to fix the issue
- Replace
DES-ECB
withAES-GCM
orAES-CBC
.
References
- [NIST Recommendations for Block Cipher Modes of Operation](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf)