@@ -77,12 +77,32 @@ const data = Buffer.from('Hello world');
7777 saltLength : crypto . constants . RSA_PSS_SALTLEN_AUTO ,
7878 } , sig ) , true ) ;
7979
80- // Cross-verify with crypto.verify
80+ // Cross-verify: sign with crypto.signDigest, verify with crypto.verify
8181 assert . strictEqual ( crypto . verify ( 'sha256' , data , {
8282 key : pubKey ,
8383 padding : crypto . constants . RSA_PKCS1_PSS_PADDING ,
8484 saltLength : crypto . constants . RSA_PSS_SALTLEN_AUTO ,
8585 } , sig ) , true ) ;
86+
87+ // Cross-verify: sign with crypto.sign, verify with crypto.verifyDigest
88+ const sig2 = crypto . sign ( 'sha256' , data , {
89+ key : privKey ,
90+ padding : crypto . constants . RSA_PKCS1_PSS_PADDING ,
91+ saltLength : 32 ,
92+ } ) ;
93+ assert . strictEqual ( crypto . verifyDigest ( 'sha256' , digest , {
94+ key : pubKey ,
95+ padding : crypto . constants . RSA_PKCS1_PSS_PADDING ,
96+ saltLength : crypto . constants . RSA_PSS_SALTLEN_AUTO ,
97+ } , sig2 ) , true ) ;
98+
99+ // Wrong digest
100+ const wrongDigest = crypto . createHash ( 'sha256' ) . update ( Buffer . from ( 'wrong' ) ) . digest ( ) ;
101+ assert . strictEqual ( crypto . verifyDigest ( 'sha256' , wrongDigest , {
102+ key : pubKey ,
103+ padding : crypto . constants . RSA_PKCS1_PSS_PADDING ,
104+ saltLength : crypto . constants . RSA_PSS_SALTLEN_AUTO ,
105+ } , sig ) , false ) ;
86106}
87107
88108// --- RSA-PSS key type (hash/padding/salt baked into key) ---
@@ -97,8 +117,10 @@ const data = Buffer.from('Hello world');
97117
98118 assert . strictEqual ( crypto . verifyDigest ( 'sha256' , digest , pubKey , sig ) , true ) ;
99119
100- // Cross-verify
120+ // Cross-verify: sign with crypto.signDigest, verify with crypto.verify
101121 assert . strictEqual ( crypto . verify ( 'sha256' , data , pubKey , sig ) , true ) ;
122+
123+ // Cross-verify: sign with crypto.sign, verify with crypto.verifyDigest
102124 const sig2 = crypto . sign ( 'sha256' , data , privKey ) ;
103125 assert . strictEqual ( crypto . verifyDigest ( 'sha256' , digest , pubKey , sig2 ) , true ) ;
104126
@@ -126,9 +148,10 @@ const data = Buffer.from('Hello world');
126148
127149 assert . strictEqual ( crypto . verifyDigest ( hash , digest , pubKey , sig ) , true ) ;
128150
129- // Cross-verify with crypto.sign / crypto.verify
151+ // Cross-verify: sign with crypto.signDigest, verify with crypto.verify
130152 assert . strictEqual ( crypto . verify ( hash , data , pubKey , sig ) , true ) ;
131153
154+ // Cross-verify: sign with crypto.sign, verify with crypto.verifyDigest
132155 const sig2 = crypto . sign ( hash , data , privKey ) ;
133156 assert . strictEqual ( crypto . verifyDigest ( hash , digest , pubKey , sig2 ) , true ) ;
134157
@@ -158,11 +181,28 @@ const data = Buffer.from('Hello world');
158181 dsaEncoding : 'ieee-p1363' ,
159182 } , sig ) , true ) ;
160183
161- // Cross-verify with crypto.verify
184+ // Cross-verify: sign with crypto.signDigest, verify with crypto.verify
162185 assert . strictEqual ( crypto . verify ( 'sha256' , data , {
163186 key : pubKey ,
164187 dsaEncoding : 'ieee-p1363' ,
165188 } , sig ) , true ) ;
189+
190+ // Cross-verify: sign with crypto.sign, verify with crypto.verifyDigest
191+ const sig2 = crypto . sign ( 'sha256' , data , {
192+ key : privKey ,
193+ dsaEncoding : 'ieee-p1363' ,
194+ } ) ;
195+ assert . strictEqual ( crypto . verifyDigest ( 'sha256' , digest , {
196+ key : pubKey ,
197+ dsaEncoding : 'ieee-p1363' ,
198+ } , sig2 ) , true ) ;
199+
200+ // Wrong digest
201+ const wrongDigest = crypto . createHash ( 'sha256' ) . update ( Buffer . from ( 'wrong' ) ) . digest ( ) ;
202+ assert . strictEqual ( crypto . verifyDigest ( 'sha256' , wrongDigest , {
203+ key : pubKey ,
204+ dsaEncoding : 'ieee-p1363' ,
205+ } , sig ) , false ) ;
166206}
167207
168208// --- DSA ---
@@ -177,8 +217,10 @@ const data = Buffer.from('Hello world');
177217
178218 assert . strictEqual ( crypto . verifyDigest ( 'sha256' , digest , pubKey , sig ) , true ) ;
179219
180- // Cross-verify
220+ // Cross-verify: sign with crypto.signDigest, verify with crypto.verify
181221 assert . strictEqual ( crypto . verify ( 'sha256' , data , pubKey , sig ) , true ) ;
222+
223+ // Cross-verify: sign with crypto.sign, verify with crypto.verifyDigest
182224 const sig2 = crypto . sign ( 'sha256' , data , privKey ) ;
183225 assert . strictEqual ( crypto . verifyDigest ( 'sha256' , digest , pubKey , sig2 ) , true ) ;
184226
0 commit comments