Hi :)
I have encountered something weird when using the crypto module's Diffie-Hellman feature. Obviously the modp14 group should return 2048 bit numbers, however from time to time, the generated public key is missing a byte and the length is merely 255 bytes.
EDIT: Please check comment below, the issue can appear in all Diffie Hellman exchange objects, not only in group modp14.
Here is a short snippet that reproduces the behaviour:
crypto = require('crypto');
var iterations = 0;
var create = function () {
iterations++;
var dh = crypto.getDiffieHellman('modp14');
var publicKey = dh.generateKeys();
if (publicKey.length === 255) {
console.log('Diffie bad length! Iterations: ' + iterations);
iterations = 0;
setTimeout(function () {
create();
}, 5);
}
else {
setTimeout(function () {
create();
}, 5);
}
};
create();
On node v.0.10.29 this can output:
Diffie bad length! Iterations: 1056
Diffie bad length! Iterations: 82
Diffie bad length! Iterations: 114
Diffie bad length! Iterations: 720
(...)
And so on and so on. I haven't found any related issue, so I thought maybe someone has a clue on what is going on there? Is it node? Is it OpenSSL?
Thanks in advance!
EDIT: Same behaviour on v0.11.13