Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

crypto v0.10.29: Diffie-Hellman generated public key is missing a byte from time to time. #7906

@johnnycrab

Description

@johnnycrab

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions