Skip to content

crypto: support deterministic ECDSA/DSA signatures#62252

Draft
panva wants to merge 1 commit intonodejs:mainfrom
panva:dsa-deterministic
Draft

crypto: support deterministic ECDSA/DSA signatures#62252
panva wants to merge 1 commit intonodejs:mainfrom
panva:dsa-deterministic

Conversation

@panva
Copy link
Member

@panva panva commented Mar 14, 2026

Add dsaNonceType option to sign/verify node:crypto APIs. When set to 'deterministic', uses deterministic digital signature generation procedure per RFC 6979.

Add dsaNonceType option to sign/verify node:crypto
APIs. When set to 'deterministic', uses
deterministic digital signature generation
procedure per RFC 6979.
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/security-wg

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Mar 14, 2026
@panva
Copy link
Member Author

panva commented Mar 14, 2026

Leaving this at draft PR unless there's user interest.

@ChALkeR
Copy link
Member

ChALkeR commented Mar 14, 2026

cc @paulmillr you might be interested / have an opinion on this

@paulmillr
Copy link

  • Random nonces are absolute garbage. break csprng and you're leaking private keys through signatures
  • Deterministic nonces are better as default, but suboptimal in some (albeit rare) situations
  • Deterministic + random combination is ideal

See RFC6979 3.6 and https://paulmillr.com/posts/deterministic-signatures/.

The suggestion is to switch to deterministic by default + add an ability to pass either specific randomness Buffer, or make node auto-generate random buffer:

  1. (default) sign() - always deterministic
  2. (option) sign(randomness: Buffer) - specific buffer of randomness; but still deterministic
  3. (option) sign(randomness: true) - auto-produce randomness; but still deterministic

@ChALkeR
Copy link
Member

ChALkeR commented Mar 14, 2026

@panva

  1. Does random here imply csprng -> nonce or (csprng, input) -> deterministic RFC 6979 -> nonce?
  2. It should be noted that any bug or change in the deterministic algo would mean an immediate leak of private keys

@panva
Copy link
Member Author

panva commented Mar 14, 2026

https://docs.openssl.org/master/man7/provider-signature/#signature-parameters > OSSL_SIGNATURE_PARAM_NONCE_TYPE

that's what this is, exposed as an opt-in option, not a new default

IIUC there are no other options available to us

@panva panva added crypto Issues and PRs related to the crypto subsystem. semver-minor PRs that contain new features and should be released in the next minor version. labels Mar 14, 2026
@ChALkeR
Copy link
Member

ChALkeR commented Mar 14, 2026

The question is about how "random nonces" work, not about how deterministic one works
There is a fundamental difference between just using csprng output as a nonce and using that as a mixin to RFC 6979 algo to get a nonce
Ok i'll check openssl

Upd:
The OpenSSL doc states:

The default value for "nonce-type" is 0 and results in a random value being used for the nonce k as defined in FIPS 186-4 Section 6.3 "Secret Number Generation".

This is... bad.
Not the fault of this PR, the current state of things is bad.

@panva
Copy link
Member Author

panva commented Mar 14, 2026

0 / random = current behaviour, csprng -> k, not changed by this PR
1 / deterministic = this PR opt-in, RFC 6979, possible future semver major default (problematic to roll out because of OpenSSL version not being a given)

noisy / hedged is not an option in OpenSSL, draft-irtf-cfrg-det-sigs-with-noise would need to be finished and published as RFC first for OpenSSL to consider it.

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

Labels

crypto Issues and PRs related to the crypto subsystem. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants