Skip to content

crypto: DH prime for bits <= 15 is always 35963 #28527

@bnoordhuis

Description

@bnoordhuis

With today's master:

const assert = require('assert');
const crypto = require('crypto');
for (let bits = 3; bits <= 15; bits++) {
  const p = crypto.createDiffieHellman(bits).getPrime();
  assert.strictEqual(p.length, 2);
  assert.strictEqual(p.readUInt16BE(0), 35963);
}

I'd expect the test case to fail (it should find different primes) but it returns the same prime for sizes 3 to 15. It's only at bits >= 16 that it starts to find different primes.

I'm not sure if this is a Node.js or an openssl bug. log2(35963) > 15 though so it definitely seems wrong to return that prime (and only that prime) for bits <= 15.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.cryptoIssues and PRs related to the crypto subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions