Skip to content

Multiple diffieHellman.generateKeys calls don't update the public key #56990

Open
@toramanomer

Description

@toramanomer

Affected URL(s)

https://nodejs.org/docs/latest-v22.x/api/crypto.html#diffiehellmangeneratekeysencoding

Description of the problem

The documentation regarding diffieHellman.generateKeys([encoding]) in crypto module states as follows:

This function is a thin wrapper around DH_generate_key(). In particular, once a private key has been generated or set, calling this function only updates the public key but does not generate a new private key.

I have not been able to observe in any way that calling generateKeys multiple times results in different public keys.

import { createDiffieHellman } from 'node:crypto'

const alice = createDiffieHellman(1024)
const public1 = alice.generateKeys('hex')
const public2 = alice.generateKeys('hex')
const public3 = alice.generateKeys('hex')

console.log(public1 === public2)     // true
console.log(public1 === public3)     // true
console.log(public2 === public3)    // true

NodeJS docs state that it is a thin wrapper around OpenSSL's DH_generate_key. The OpenSSL page on DH_generate_key states that as follows in their docs:

All of the functions described on this page are deprecated. Applications should instead use EVP_PKEY_derive_init(3) and EVP_PKEY_derive(3).

Is it possible this is the result of such deprecation?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cryptoIssues and PRs related to the crypto subsystem.docIssues and PRs related to the documentations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions