Skip to content

Commit 7c81e38

Browse files
committed
fixup! crypto: support deterministic ECDSA/DSA signatures
1 parent 3d278ba commit 7c81e38

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

doc/api/crypto.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,7 +2379,9 @@ object, the following additional properties can be passed:
23792379
* `'ieee-p1363'`: Signature format `r || s` as proposed in IEEE-P1363.
23802380
* `dsaNonceType` {string} For DSA and ECDSA, this option specifies the
23812381
nonce generation method. It can be one of the following:
2382-
* `'random'` (default): Use a random nonce.
2382+
* `'hedged'` (default): Use a hedged nonce that combines cryptographic
2383+
randomness with the private key and the message, providing resilience
2384+
against both weak random number generators and side-channel attacks.
23832385
* `'deterministic'`[^openssl32]: Use a deterministic nonce as defined in [RFC 6979][].
23842386
* `padding` {integer} Optional padding value for RSA, one of the following:
23852387

@@ -2515,7 +2517,9 @@ object, the following additional properties can be passed:
25152517
* `'ieee-p1363'`: Signature format `r || s` as proposed in IEEE-P1363.
25162518
* `dsaNonceType` {string} For DSA and ECDSA, this option specifies the
25172519
nonce generation method used during signing. It can be one of the following:
2518-
* `'random'` (default): Use a random nonce.
2520+
* `'hedged'` (default): Use a hedged nonce that combines cryptographic
2521+
randomness with the private key and the message, providing resilience
2522+
against both weak random number generators and side-channel attacks.
25192523
* `'deterministic'`[^openssl32]: Use a deterministic nonce as defined in [RFC 6979][].
25202524
* `padding` {integer} Optional padding value for RSA, one of the following:
25212525

@@ -5808,7 +5812,9 @@ additional properties can be passed:
58085812
* `'ieee-p1363'`: Signature format `r || s` as proposed in IEEE-P1363.
58095813
* `dsaNonceType` {string} For DSA and ECDSA, this option specifies the
58105814
nonce generation method. It can be one of the following:
5811-
* `'random'` (default): Use a random nonce.
5815+
* `'hedged'` (default): Use a hedged nonce that combines cryptographic
5816+
randomness with the private key and the message, providing resilience
5817+
against both weak random number generators and side-channel attacks.
58125818
* `'deterministic'`[^openssl32]: Use a deterministic nonce as defined in [RFC 6979][].
58135819
* `padding` {integer} Optional padding value for RSA, one of the following:
58145820

@@ -5943,7 +5949,9 @@ additional properties can be passed:
59435949
* `'ieee-p1363'`: Signature format `r || s` as proposed in IEEE-P1363.
59445950
* `dsaNonceType` {string} For DSA and ECDSA, this option specifies the
59455951
nonce generation method used during signing. It can be one of the following:
5946-
* `'random'` (default): Use a random nonce.
5952+
* `'hedged'` (default): Use a hedged nonce that combines cryptographic
5953+
randomness with the private key and the message, providing resilience
5954+
against both weak random number generators and side-channel attacks.
59475955
* `'deterministic'`[^openssl32]: Use a deterministic nonce as defined in [RFC 6979][].
59485956
* `padding` {integer} Optional padding value for RSA, one of the following:
59495957

lib/internal/crypto/sig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function getDSASignatureEncoding(options) {
109109
function getDSANonceType(options) {
110110
if (typeof options === 'object') {
111111
const { dsaNonceType } = options;
112-
if (dsaNonceType === undefined || dsaNonceType === 'random')
112+
if (dsaNonceType === undefined || dsaNonceType === 'hedged')
113113
return undefined;
114114
if (dsaNonceType === 'deterministic')
115115
return true;

test/parallel/test-crypto-sign-deterministic-unsupported.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ const expectedError = {
8181
}));
8282
}
8383

84-
// dsaNonceType: 'random' should still work (explicit default).
84+
// dsaNonceType: 'hedged' should still work (explicit default).
8585
{
8686
const sig = crypto.sign('sha256', data, {
8787
key: ecPrivKey,
88-
dsaNonceType: 'random',
88+
dsaNonceType: 'hedged',
8989
});
9090
assert.strictEqual(
9191
crypto.verify('sha256', data, ecPrivKey, sig),
@@ -95,7 +95,7 @@ const expectedError = {
9595

9696
// Invalid dsaNonceType values should still throw validation errors.
9797
{
98-
for (const dsaNonceType of ['foo', null, {}, 5, true, NaN]) {
98+
for (const dsaNonceType of ['foo', 'random', null, {}, 5, true, NaN]) {
9999
assert.throws(() => {
100100
crypto.sign('sha256', data, {
101101
key: ecPrivKey,

test/parallel/test-crypto-sign-deterministic.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ const data = Buffer.from('Hello world');
9696
);
9797
}
9898

99-
// Test dsaNonceType: 'random' produces valid signatures (explicit default).
99+
// Test dsaNonceType: 'hedged' produces valid signatures (explicit default).
100100
{
101101
const ecPrivKey = fixtures.readKey('ec_p256_private.pem');
102102

103103
const sig = crypto.sign('sha256', data, {
104104
key: ecPrivKey,
105-
dsaNonceType: 'random',
105+
dsaNonceType: 'hedged',
106106
});
107107
assert.strictEqual(
108108
crypto.verify('sha256', data, ecPrivKey, sig),
@@ -170,7 +170,7 @@ const data = Buffer.from('Hello world');
170170
{
171171
const ecPrivKey = fixtures.readKey('ec_p256_private.pem');
172172

173-
for (const dsaNonceType of ['foo', null, {}, 5, true, NaN]) {
173+
for (const dsaNonceType of ['foo', 'random', null, {}, 5, true, NaN]) {
174174
assert.throws(() => {
175175
crypto.sign('sha256', data, {
176176
key: ecPrivKey,
@@ -186,7 +186,7 @@ const data = Buffer.from('Hello world');
186186
{
187187
const ecPrivKey = fixtures.readKey('ec_p256_private.pem');
188188

189-
for (const dsaNonceType of ['foo', null, {}, 5, true, NaN]) {
189+
for (const dsaNonceType of ['foo', 'random', null, {}, 5, true, NaN]) {
190190
assert.throws(() => {
191191
crypto.createSign('sha256').update(data).sign({
192192
key: ecPrivKey,

0 commit comments

Comments
 (0)