@@ -477,41 +477,6 @@ WebCryptoKeyExportStatus DHKeyExportTraits::DoExport(
477
477
}
478
478
}
479
479
480
- namespace {
481
- ByteSource StatelessDiffieHellmanThreadsafe (const EVPKeyPointer& our_key,
482
- const EVPKeyPointer& their_key) {
483
- auto dp = DHPointer::stateless (our_key, their_key);
484
- if (!dp) return {};
485
-
486
- return ByteSource::Allocated (dp.release ());
487
- }
488
-
489
- void Stateless (const FunctionCallbackInfo<Value>& args) {
490
- Environment* env = Environment::GetCurrent (args);
491
-
492
- CHECK (args[0 ]->IsObject () && args[1 ]->IsObject ());
493
- KeyObjectHandle* our_key_object;
494
- ASSIGN_OR_RETURN_UNWRAP (&our_key_object, args[0 ].As <Object>());
495
- CHECK_EQ (our_key_object->Data ().GetKeyType (), kKeyTypePrivate );
496
- KeyObjectHandle* their_key_object;
497
- ASSIGN_OR_RETURN_UNWRAP (&their_key_object, args[1 ].As <Object>());
498
- CHECK_NE (their_key_object->Data ().GetKeyType (), kKeyTypeSecret );
499
-
500
- const auto & our_key = our_key_object->Data ().GetAsymmetricKey ();
501
- const auto & their_key = their_key_object->Data ().GetAsymmetricKey ();
502
-
503
- Local<Value> out;
504
- if (!StatelessDiffieHellmanThreadsafe (our_key, their_key)
505
- .ToBuffer (env)
506
- .ToLocal (&out)) return ;
507
-
508
- if (Buffer::Length (out) == 0 )
509
- return ThrowCryptoError (env, ERR_get_error (), " diffieHellman failed" );
510
-
511
- args.GetReturnValue ().Set (out);
512
- }
513
- } // namespace
514
-
515
480
Maybe<void > DHBitsTraits::AdditionalConfig (
516
481
CryptoJobMode mode,
517
482
const FunctionCallbackInfo<Value>& args,
@@ -529,7 +494,7 @@ Maybe<void> DHBitsTraits::AdditionalConfig(
529
494
ASSIGN_OR_RETURN_UNWRAP (&private_key, args[offset + 1 ], Nothing<void >());
530
495
531
496
if (private_key->Data ().GetKeyType () != kKeyTypePrivate ||
532
- public_key->Data ().GetKeyType () != kKeyTypePublic ) {
497
+ public_key->Data ().GetKeyType () == kKeyTypeSecret ) {
533
498
THROW_ERR_CRYPTO_INVALID_KEYTYPE (env);
534
499
return Nothing<void >();
535
500
}
@@ -550,8 +515,20 @@ bool DHBitsTraits::DeriveBits(
550
515
Environment* env,
551
516
const DHBitsConfig& params,
552
517
ByteSource* out) {
553
- *out = StatelessDiffieHellmanThreadsafe (params.private_key .GetAsymmetricKey (),
554
- params.public_key .GetAsymmetricKey ());
518
+ auto dp = DHPointer::stateless (params.private_key .GetAsymmetricKey (),
519
+ params.public_key .GetAsymmetricKey ());
520
+ if (!dp) {
521
+ bool can_throw =
522
+ per_process::v8_initialized && Isolate::TryGetCurrent () != nullptr ;
523
+ if (can_throw) {
524
+ unsigned long err = ERR_get_error (); // NOLINT(runtime/int)
525
+ if (err) ThrowCryptoError (env, err, " diffieHellman failed" );
526
+ }
527
+ return false ;
528
+ }
529
+
530
+ *out = ByteSource::Allocated (dp.release ());
531
+ CHECK (!out->empty ());
555
532
return true ;
556
533
}
557
534
@@ -604,7 +581,6 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
604
581
make (FIXED_ONE_BYTE_STRING (env->isolate (), " DiffieHellmanGroup" ),
605
582
DiffieHellmanGroup);
606
583
607
- SetMethodNoSideEffect (context, target, " statelessDH" , Stateless);
608
584
DHKeyPairGenJob::Initialize (env, target);
609
585
DHKeyExportJob::Initialize (env, target);
610
586
DHBitsJob::Initialize (env, target);
@@ -625,7 +601,6 @@ void DiffieHellman::RegisterExternalReferences(
625
601
registry->Register (SetPrivateKey);
626
602
627
603
registry->Register (Check);
628
- registry->Register (Stateless);
629
604
630
605
DHKeyPairGenJob::RegisterExternalReferences (registry);
631
606
DHKeyExportJob::RegisterExternalReferences (registry);
0 commit comments