@@ -202,59 +202,21 @@ common.expectsError(() => {
202
202
// The following RSA-OAEP test cases were created using the WebCrypto API to
203
203
// ensure compatibility when using non-SHA1 hash functions.
204
204
{
205
- function testDecrypt ( oaepHash , ciphertext ) {
205
+ const { decryptionTests } =
206
+ JSON . parse ( fixtures . readSync ( 'rsa-oaep-test-vectors.js' , 'utf8' ) ) ;
207
+
208
+ for ( const { ct, oaepHash, oaepLabel } of decryptionTests ) {
206
209
const decrypted = crypto . privateDecrypt ( {
207
210
key : rsaPkcs8KeyPem ,
208
- oaepHash
209
- } , Buffer . from ( ciphertext , 'hex' ) ) ;
211
+ oaepHash,
212
+ oaepLabel : oaepLabel ? Buffer . from ( oaepLabel , 'hex' ) : undefined
213
+ } , Buffer . from ( ct , 'hex' ) ) ;
210
214
211
215
assert . strictEqual ( decrypted . toString ( 'utf8' ) , 'Hello Node.js' ) ;
212
216
}
213
-
214
- testDecrypt ( undefined , '16ece59cf985a8cf1a3434e4b9707c922c20638fdf9abf7e5dc' +
215
- '7943f4136899348c54116d15b2c17563b9c7143f9d5b85b4561' +
216
- '5ad0598ea6d21c900f3957b65400612306a9bebae441f005646' +
217
- 'f7a7c97129a103ab54e777168ef966514adb17786b968ea0ff4' +
218
- '30a524904c4a11c683764b7c8dbb60df0952768381cdba4d665' +
219
- 'e5006034393a10d56d33e75b2714db824a18da46441ef7f94a3' +
220
- '4a7058c0bbad0394083a038558bcc6dd370f8e518e1bd8d73b2' +
221
- '96fc51d77da44799e4ee774926ded7910e8768f92db76f63107' +
222
- '338d33354b735d3ad094240dbd7ffdfda27ef0255306dcf4a64' +
223
- '62849492abd1a97fdd37743ff87c4d2ec89866c5cdbb696bd2b' +
224
- '30' ) ;
225
- testDecrypt ( 'sha1' , '16ece59cf985a8cf1a3434e4b9707c922c20638fdf9abf7e5dc794' +
226
- '3f4136899348c54116d15b2c17563b9c7143f9d5b85b45615ad059' +
227
- '8ea6d21c900f3957b65400612306a9bebae441f005646f7a7c9712' +
228
- '9a103ab54e777168ef966514adb17786b968ea0ff430a524904c4a' +
229
- '11c683764b7c8dbb60df0952768381cdba4d665e5006034393a10d' +
230
- '56d33e75b2714db824a18da46441ef7f94a34a7058c0bbad039408' +
231
- '3a038558bcc6dd370f8e518e1bd8d73b296fc51d77da44799e4ee7' +
232
- '74926ded7910e8768f92db76f63107338d33354b735d3ad094240d' +
233
- 'bd7ffdfda27ef0255306dcf4a6462849492abd1a97fdd37743ff87' +
234
- 'c4d2ec89866c5cdbb696bd2b30' ) ;
235
- testDecrypt ( 'sha256' , '16ccf09afe5eb0130182b9fc1ca4af61a38e772047cac42146bf' +
236
- 'a0fa5879aa9639203e4d01442d212ff95bddfbe4661222215a2e' +
237
- '91908c37ab926edea7cfc53f83357bc27f86af0f5f2818ae141f' +
238
- '4e9e934d4e66189aff30f062c9c3f6eb9bc495a59082cb978f99' +
239
- 'b56ce5fa530a8469e46129258e5c42897cb194b6805e936e5cbb' +
240
- 'eaa535bad6b1d3cdfc92119b7dd325a2e6d2979e316bdacc9f80' +
241
- 'e29c7bbdf6846d738e380deadcb48df8c1e8aabf7a9dd2f8c71d' +
242
- '6681dbec7dcadc01887c51288674268796bc77fdf8f1c94c9ca5' +
243
- '0b1cc7cddbaf4e56cb151d23e2c699d2844c0104ee2e7e9dcdb9' +
244
- '07cfab43339120a40c59ca54f32b8d21b48a29656c77' ) ;
245
- testDecrypt ( 'sha512' , '831b72e8dd91841729ecbddf2647d6f19dc0094734f8803d8c65' +
246
- '1b5655a12ae6156b74d9b594bcc0eacd002728380b94f46e8657' +
247
- 'f130f354e03b6e7815ee257eda78dba296d67d24410c31c48e58' +
248
- '75cc79e4bde594b412be5f357f57a7ac1f1d18b718e408df162d' +
249
- '1795508e6a0616192b647ad942ea068a44fb2b323d35a3a61b92' +
250
- '6feb105d6c0b2a8fc8050222d1cf4a9e44da1f95bbc677fd6437' +
251
- '49c6c89ac551d072f04cd9320c97a8d94755c8a804954c082bed' +
252
- '7fa59199a00aca154c14a7b584b63c538daf9b9c7c90abfca193' +
253
- '87d2131f9d9b9ecfc8672249c33144d1be3bfc41558a13f99466' +
254
- '3661a3af24fd0a97619d508db36f5fc131af86fc68cf' ) ;
255
217
}
256
218
257
- // Test invalid oaepHash options.
219
+ // Test invalid oaepHash and oaepLabel options.
258
220
for ( const fn of [ crypto . publicEncrypt , crypto . privateDecrypt ] ) {
259
221
assert . throws ( ( ) => {
260
222
fn ( {
@@ -275,6 +237,17 @@ for (const fn of [crypto.publicEncrypt, crypto.privateDecrypt]) {
275
237
code : 'ERR_INVALID_ARG_TYPE'
276
238
} ) ;
277
239
}
240
+
241
+ for ( const oaepLabel of [ 0 , false , null , Symbol ( ) , ( ) => { } , { } , 'foo' ] ) {
242
+ common . expectsError ( ( ) => {
243
+ fn ( {
244
+ key : rsaPubPem ,
245
+ oaepLabel
246
+ } , Buffer . alloc ( 10 ) ) ;
247
+ } , {
248
+ code : 'ERR_INVALID_ARG_TYPE'
249
+ } ) ;
250
+ }
278
251
}
279
252
280
253
// Test RSA key signing/verification
0 commit comments