@@ -5200,7 +5200,7 @@ template <PublicKeyCipher::Operation operation,
52005200bool PublicKeyCipher::Cipher (Environment* env,
52015201 const ManagedEVPPKey& pkey,
52025202 int padding,
5203- const char * oaep_hash ,
5203+ const EVP_MD* digest ,
52045204 const unsigned char * data,
52055205 int len,
52065206 AllocatedBuffer* out) {
@@ -5212,9 +5212,8 @@ bool PublicKeyCipher::Cipher(Environment* env,
52125212 if (EVP_PKEY_CTX_set_rsa_padding (ctx.get (), padding) <= 0 )
52135213 return false ;
52145214
5215- if (oaep_hash != nullptr ) {
5216- if (!EVP_PKEY_CTX_md (ctx.get (), EVP_PKEY_OP_TYPE_CRYPT,
5217- EVP_PKEY_CTRL_RSA_OAEP_MD, oaep_hash))
5215+ if (digest != nullptr ) {
5216+ if (!EVP_PKEY_CTX_set_rsa_oaep_md (ctx.get (), digest))
52185217 return false ;
52195218 }
52205219
@@ -5256,6 +5255,12 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
52565255
52575256 const node::Utf8Value oaep_str (env->isolate (), args[offset + 2 ]);
52585257 const char * oaep_hash = args[offset + 2 ]->IsString () ? *oaep_str : nullptr ;
5258+ const EVP_MD* digest = nullptr ;
5259+ if (oaep_hash != nullptr ) {
5260+ digest = EVP_get_digestbyname (oaep_hash);
5261+ if (digest == nullptr )
5262+ return THROW_ERR_OSSL_EVP_INVALID_DIGEST (env);
5263+ }
52595264
52605265 AllocatedBuffer out;
52615266
@@ -5265,7 +5270,7 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
52655270 env,
52665271 pkey,
52675272 padding,
5268- oaep_hash ,
5273+ digest ,
52695274 buf.data (),
52705275 buf.length (),
52715276 &out);
0 commit comments