Skip to content

Commit 299cbb6

Browse files
committed
fix: default RSA-PSS saltLength to RSA_PSS_SALTLEN_MAX_SIGN in sign/verify
Match Node.js behavior: when padding === RSA_PKCS1_PSS_PADDING and saltLength is undefined, default to RSA_PSS_SALTLEN_MAX_SIGN before forwarding to native. Closes #1006.
1 parent 9155523 commit 299cbb6

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

packages/react-native-quick-crypto/src/keys/signVerify.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
KFormatType,
1414
KeyEncoding,
1515
} from '../utils';
16+
import { constants } from '../constants';
1617

1718
type KeyInput = BinaryLike | KeyObject | CryptoKey | KeyInputObject;
1819

@@ -144,6 +145,16 @@ function dsaEncodingToNumber(
144145
return undefined;
145146
}
146147

148+
function getSaltLength(options?: SignOptions): number | undefined {
149+
if (
150+
options?.padding === constants.RSA_PKCS1_PSS_PADDING &&
151+
options?.saltLength === undefined
152+
) {
153+
return constants.RSA_PSS_SALTLEN_MAX_SIGN;
154+
}
155+
return options?.saltLength;
156+
}
157+
147158
export class Sign {
148159
private handle: SignHandleSpec;
149160

@@ -169,7 +180,7 @@ export class Sign {
169180
const signature = this.handle.sign(
170181
keyObject.handle,
171182
options?.padding,
172-
options?.saltLength,
183+
getSaltLength(options),
173184
dsaEncodingToNumber(options?.dsaEncoding),
174185
);
175186

@@ -219,7 +230,7 @@ export class Verify {
219230
keyObject.handle,
220231
sigBuffer,
221232
options?.padding,
222-
options?.saltLength,
233+
getSaltLength(options),
223234
dsaEncodingToNumber(options?.dsaEncoding),
224235
);
225236
}

0 commit comments

Comments
 (0)