@@ -907,6 +907,7 @@ v8::Local<v8::Function> KeyObjectHandle::Initialize(Environment* env) {
907907 isolate, templ, " getSymmetricKeySize" , GetSymmetricKeySize);
908908 SetProtoMethodNoSideEffect (
909909 isolate, templ, " getAsymmetricKeyType" , GetAsymmetricKeyType);
910+ SetProtoMethodNoSideEffect (isolate, templ, " checkKeyData" , CheckKeyData);
910911 SetProtoMethod (isolate, templ, " export" , Export);
911912 SetProtoMethod (isolate, templ, " exportJwk" , ExportJWK);
912913 SetProtoMethod (isolate, templ, " initECRaw" , InitECRaw);
@@ -926,6 +927,7 @@ void KeyObjectHandle::RegisterExternalReferences(
926927 registry->Register (Init);
927928 registry->Register (GetSymmetricKeySize);
928929 registry->Register (GetAsymmetricKeyType);
930+ registry->Register (CheckKeyData);
929931 registry->Register (Export);
930932 registry->Register (ExportJWK);
931933 registry->Register (InitECRaw);
@@ -1237,6 +1239,45 @@ void KeyObjectHandle::GetAsymmetricKeyType(
12371239 args.GetReturnValue ().Set (key->GetAsymmetricKeyType ());
12381240}
12391241
1242+ bool KeyObjectHandle::CheckKeyData () const {
1243+ MarkPopErrorOnReturn mark_pop_error_on_return;
1244+
1245+ bool isValid;
1246+ const ManagedEVPPKey& key = data_->GetAsymmetricKey ();
1247+ EVPKeyCtxPointer ctx (EVP_PKEY_CTX_new (key.get (), nullptr ));
1248+ switch (EVP_PKEY_id (key.get ())) {
1249+ case EVP_PKEY_EC: {
1250+ switch (data_->GetKeyType ()) {
1251+ case kKeyTypePublic :
1252+ #if OPENSSL_VERSION_MAJOR >= 3
1253+ isValid = EVP_PKEY_public_check_quick (ctx.get ()) == 1 ;
1254+ #else
1255+ isValid = EVP_PKEY_public_check (ctx.get ()) == 1 ;
1256+ #endif
1257+ break ;
1258+ case kKeyTypePrivate :
1259+ isValid = EVP_PKEY_check (ctx.get ()) == 1 ;
1260+ break ;
1261+ default :
1262+ UNREACHABLE ();
1263+ }
1264+ break ;
1265+ }
1266+ default :
1267+ UNREACHABLE ();
1268+ }
1269+
1270+ ctx.reset ();
1271+ return isValid;
1272+ }
1273+
1274+ void KeyObjectHandle::CheckKeyData (const FunctionCallbackInfo<Value>& args) {
1275+ KeyObjectHandle* key;
1276+ ASSIGN_OR_RETURN_UNWRAP (&key, args.Holder ());
1277+
1278+ args.GetReturnValue ().Set (key->CheckKeyData ());
1279+ }
1280+
12401281void KeyObjectHandle::GetSymmetricKeySize (
12411282 const FunctionCallbackInfo<Value>& args) {
12421283 KeyObjectHandle* key;
0 commit comments